I did setup a project for testing CAN with K22. I do use latest Processor Expert and WinIDA from iSystems.
Using the attached project I tested sending CAN messages. Everything worked fine until I added another node sending messages. My procedure was like this
- Timer Interrupt with 1 millisecond cycle time sends Message 1 using mailbox 1. Message1SentCounter++
- TX Buffer Free Event sends Message 2 using Mailbox 2. Message2SentCounter++
Both counters incremented synchronously. When I caused the second node sending cyclic messages then Message2SentCounter increments less than Message1SentCounter.
I checked with a CANalyzer that this was true - message 2 wasn't sent often enough. But even Message 1 was not sent es often as I expected. And this makes sense because if message 1 is not sent I won't get the TX Buffer Free Event. Please note that I tried to send 3 messages in 1 ms at a bitrate of 1 Mhz. This is more than enough time.
Ok, next thing I tried was checking for the error value the function. It returned ERR_BUSY and I made this to work around my problem.
RepeatCounter = 0;
Error = CAN1_SendFrame (CAN1_DeviceData, TransmitBuffer_Tlg_1, &Frame);
while((Error != ERR_OK) && (RepeatCounter < 1000));
This works - that basically is great.
And here comes my questions.
I give a message to mailbox 1. I expect that the CAN controller sends this message as soon as possible. If it can't access the bus than it should wait until the bus is empty and repeat automatically the message. If bus arbitration fails again it tries next free bus time. I do not expect that I do this by software as I did it int the above source snipped. I do not want to wast my processor time at this loop.
I assume that I make a configuration error. Could anybody help me with this?