Hello,
I have the following system:
This works fine as long as all devices work with the same bit rate.
Sometimes it happens, that one device with the "wrong" bitrate is inserted in such a system which breaks the whole system.
I'm now looking for a way to detect such errors.
In my opinion, the CANTXERR register should count up in the one wrong configured module whenever it transmits a CAN message.
I'm not sure if the CANRXERR is counted up if messages with a wrong bitrate are received.
Is there a reason why these registers are not readable in normal mode?
What will be the best way to detect these error conditions?
Thanks in advance.
Best regards,
Andre
Hello puppetmaster,
Thanks for the document. I will have a deeper look at it.
I think you can't have a mix of devices operating at different baudrates. None of them will be able to deliver their messages and will try to resend again and again. If your devices are or can be silent until some master with right baudrate asks slaves for something, then you can use this algo at slave powerup to autodetect baudrate:
start CAN with LISTEN bit set
while(bitrate_not_detected == 1)
{
select_next_bitrate(); // all possible bitrates 10kbps, 50, .. 1000, 10, 50, .. 1000, ...
delay();
if(RXRFM_bit_is_set)
bitrate_not_detected = 0;
}
restart CAN with LISTEN=0 and known baudrate
Hello Edward,
Thanks for your reply.
My advantage is, that I only have to support two different bitrates: 125 and 250 kbps. The bad side is, the devices are not silent at startup at the moment.
Your tip with LISTEN ONLY at startup sounds useful, but that also means that there is no ACK for the CAN frames from master until at least one slave is synchronized. But this should be no big problem.
I'm not sure, but I guess you'll have problems with such setup. What if two nodes at the same time try to send, then fail, then both switch do different baudrate, then again try to send, then fail, etc? You could also listen for a while at startup, but what if two or more nodes listen for the same amount of time and then at the same time decide that they are alone and start sending at their own baudrates. Though, maybe you will find a way to make them talking at the same baudrate after few iterations of listen-send-failure, I'm not sure.
Few years ago Daniel Lundin suggested on the forums using timer pin to determine CAN baudrate. This should help determining shortest bit time (presence of 250kbps nodes?), but I guess you don't have timer pin connected to CAN RX.
Regarding CAN*XERR counters. It is not clear how are you going to use them, but instead of reading error counters, you may set up RSTATEx and TSTATEx bits to set CSCIF flag when error status changes. You need to service (clear) CSCIF each time, else you won't notice any changes in status bits TSTATx and RSTATx.
How and when errors counters get incremented or decremented is specified in Bosch CAN specs:
hhttp://www.freescale.com/files/microcontrollers/doc/data_sheet/BCANPSV2.pdf
Thanks for you answer and the document.
Unfortunately, I don't have a timer pin (more unfortunate, the CAN interface is on different pins in different devices.
I will have a look at the RSTATEx / TSTATEx bits and the Bosch specs.