First, I'm new to CAN and am in the middle of trying to figure out the basics of how to use mailboxes, FIFOs and callbacks.
I wrote a long detailed post, but figured no one would read or respond, so here's the short(er) version.
I have the SKPang "Triple CAN" T4.1 board talking to a CAN2.0A/B robot actuator using FlexCAN. It is just those two things on a dedicated CAN bus. The message ID is always the same for all frames traded between the two nodes. My current setup works with the 1Mbps CAN baudrate.
Here's how I'm setting things up right now (though I still don't really understand the purpose of distribute() or mailboxStatus() )
For technical performance reasons, I need to be able to throw the frames at the actuator at at least 1000 packets/sec, ideally 4000-5000 packets/sec.
My current implementation simply uses can1.write(msgCMD); and can1.read(msgcan1); in a polling loop running flat out (un-timed) on the T4.1.
The most obvious problem is that I'm missing Reply frames from the actuator - I get many of one type, but miss about 99% of the others. I don't really understand why, though I believe that the way I am currently polling (e.g. code architecture) is likely my problem.
Here's what I think I know - please correct me if any of this is wrong:
1) I don't think that using Masking or Filtering would make any difference, since this is a dedicated bus and that all MessageIDs are always the same.
2) I think that I probably need to be using (at least) an RX Callback to grab the frame asynchronously, but I've not found an example yet that makes sense to me. TX callbacks conceptually make zero sense to me at the moment.
3) I think I conceptually understand Mailboxes, but I still don't really understand the purpose of the CAN FIFO, or if that is something I should be using, or even if the polling approach I am using actually using the FIFO, just without my knowledge?
4) My understanding is that a Mailbox can only contain one message? Does that message get overwritten when the next arrives? Is there a buffer/queue behind the scenes, stacking frames up? (Doesn't seem so as I'm losing frames.)
5) Can you use multiple mailboxes to create a sequential message queue of sorts? Is that a dumb way to think about/use Mailboxes, if that is even possible?
6) Can anyone point to any "CAN Mailboxes & Callbacks for Dummies" examples to look at?
I've read as much as I can find on this site, read lots of Readmes and examples, and watched a lot of YouTube videos. Most of what I've found are either very basic (e.g. CAN frame format) or very automotive-related (not relevant it seems).
I feel like I'm kind of stuck in a place where I'm struggling to learn more but not finding the right material, advice, or examples.
Happy to provide more details if anyone is interested. I'd be grateful for any thoughts/observations/pointers/suggestions/examples.
Thanks!
Bruce
I wrote a long detailed post, but figured no one would read or respond, so here's the short(er) version.
I have the SKPang "Triple CAN" T4.1 board talking to a CAN2.0A/B robot actuator using FlexCAN. It is just those two things on a dedicated CAN bus. The message ID is always the same for all frames traded between the two nodes. My current setup works with the 1Mbps CAN baudrate.
Here's how I'm setting things up right now (though I still don't really understand the purpose of distribute() or mailboxStatus() )
Code:
void startCAN1( void ){
can1.begin();
can1.setBaudRate(1000000); // 1Mbits/sec (1000000) works now with termination resistor
can1.setMBFilter(ACCEPT_ALL);
can1.distribute();
can1.mailboxStatus();
return;
}
For technical performance reasons, I need to be able to throw the frames at the actuator at at least 1000 packets/sec, ideally 4000-5000 packets/sec.
My current implementation simply uses can1.write(msgCMD); and can1.read(msgcan1); in a polling loop running flat out (un-timed) on the T4.1.
The most obvious problem is that I'm missing Reply frames from the actuator - I get many of one type, but miss about 99% of the others. I don't really understand why, though I believe that the way I am currently polling (e.g. code architecture) is likely my problem.
Here's what I think I know - please correct me if any of this is wrong:
1) I don't think that using Masking or Filtering would make any difference, since this is a dedicated bus and that all MessageIDs are always the same.
2) I think that I probably need to be using (at least) an RX Callback to grab the frame asynchronously, but I've not found an example yet that makes sense to me. TX callbacks conceptually make zero sense to me at the moment.
3) I think I conceptually understand Mailboxes, but I still don't really understand the purpose of the CAN FIFO, or if that is something I should be using, or even if the polling approach I am using actually using the FIFO, just without my knowledge?
4) My understanding is that a Mailbox can only contain one message? Does that message get overwritten when the next arrives? Is there a buffer/queue behind the scenes, stacking frames up? (Doesn't seem so as I'm losing frames.)
5) Can you use multiple mailboxes to create a sequential message queue of sorts? Is that a dumb way to think about/use Mailboxes, if that is even possible?
6) Can anyone point to any "CAN Mailboxes & Callbacks for Dummies" examples to look at?
I've read as much as I can find on this site, read lots of Readmes and examples, and watched a lot of YouTube videos. Most of what I've found are either very basic (e.g. CAN frame format) or very automotive-related (not relevant it seems).
I feel like I'm kind of stuck in a place where I'm struggling to learn more but not finding the right material, advice, or examples.
Happy to provide more details if anyone is interested. I'd be grateful for any thoughts/observations/pointers/suggestions/examples.
Thanks!
Bruce