teachop / FlexCAN_Library

Arduino library for CAN on Teensy 3.1
The Unlicense
155 stars 122 forks source link

ESR1 SYNCH #9

Open xboxpro1 opened 8 years ago

xboxpro1 commented 8 years ago

Hello, is it possible to add a function to check that the Can Bus is synchronized. There is a Flag in the ESR1 register, CAN Synchronization Status.

I want a function to connect automatic to the Can Bus, like try baud 50000 connect, check synchronization. If not synchronized, try baud 125000, and so on... If synchronization is successful Return the baudrate or if not Return 0..

Thanks...

tonton81 commented 6 years ago

This flag is more or less if the controller participated on the bus, regardless of bitrate. Your baud could be bad but still the SYNCH flag may be set. You'll have to monitor more than just the SYNCH flag, there are other bits to check in that ESR1 register, never rely on just the SYNCH, you'll also need 2 or more nodes on the network talking in order to write such a "detect" function, and must be in listen only mode to prevent collissions when using wrong bitrates on bus detections.