canio module listener question

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Tim_H
 
Posts: 2
Joined: Mon Mar 20, 2023 11:30 am

canio module listener question

Post by Tim_H »

Hi All,
Question concerning the canio module, in particular the listener function.
I have done testing and the in_waiting function maxes out at 3 messages.
This causes the program to miss incoming messages, which obviously is a problem.

It appears that the queue or buffer only holds 3 messages, is this correct?
Now, I don't need it hold a thousand messages or even a hundred, but more than 3 for sure.

Any help would be appreciated.
Tim

User avatar
jepler
 
Posts: 10
Joined: Wed May 08, 2013 12:47 pm

Re: canio module listener question

Post by jepler »

That's right, in the current implementation of canio in CircuitPython, the only buffering is within the specific microcontroller peripheral or microcontroller low level library. You didn't mention which microcontroller you're using but it appears that on stm32f405 there can be a maximum of 3 messages waiting in the hardware queue. same51 and espressif have different (but not wildly larger) limits.

If possible, modify your program so that it is able to respond to messages more quickly, or use filters so that irrelevant messages don't need to be handled by your CircuitPython code. You may also be able to (it depends on the microcontroller's CAN peripheral) use multiple listeners with different filters so that your messages get divided across multiple listeners (for instance, one could listen only for even-numbered addresses and one only for odd-numbered addresses); on the stm32 implementation it appears that this would effectively give you up to 6 messages waiting (3 per listener) but I did not test this while preparing my answer.

A possible future direction for improvement of the circuitpython core could potentially add an additional software FIFO for messages. You're welcome to enter an issue about it on github, if you're a user there.

User avatar
Tim_H
 
Posts: 2
Joined: Mon Mar 20, 2023 11:30 am

Re: canio module listener question

Post by Tim_H »

I am using a Feather M4 Can.
I don't know if it's possible to process messages faster.
I did a test program where the loop just receives messages and prints the in_waiting and loops.
It is easily overloaded.
I will try some filtering, but I don't think it's going to work any better since messages are received from a single source.
Additionally, sequencing is important.

Would Arduino code be a better choice?

User avatar
jepler
 
Posts: 10
Joined: Wed May 08, 2013 12:47 pm

Re: canio module listener question

Post by jepler »

depending on how far you are into the project, arduino may worth investigating. the arduino CAN library appears to support an onInterrupt function so that your code can be called directly when a matching packet arrives. but I don't have much experience with CAN programming, despite implementing some of the low level code.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”