Automatic bitrate detection on a CAN network

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Automatic bitrate detection on a CAN network

1,423 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ALU on Tue Feb 25 03:01:08 MST 2014
Hello everybody,

I'm trying to set up an automatic bit rate detection (LPC1778 controller + LOM).
Testing all valid bit rates works fine as long as more than one other CAN device is active on my network.
I haven't managed to detect a bit rate when LPC1778 and the sending CAN device are the only active devices.
(OK, each transmitted Message needs to be acknowledged by at least one other CAN device. )
But there is a time when the sending CAN device reaches error-warning limit and may not destroy the message it transmits.
This message should be detected by LPC1778, but it is not?!? (It works for other CAN-Controllers.)
What's the way to detect a valid bit rate when only the detecting device and one sending CAN-Device are active?
My code...
(Cyclic call of BSP_CAN_Autobaud(), CAN-Controller initialized in listen only mode)

// Automatic bitrate detection...
// Return values: 0..8 = index of detected bitrate , 10 detection in progress, >= 90 Error.
BYTE BSP_CAN_Autobaud(void)
{
    //check status of Receive Buffer
    if ( (LPC_CAN1->SR & CAN1SR_RBS ) != 0  ||
         (LPC_CAN1->GSR & CAN1SR_RBS ) != 0    )
    { // Valid Message received...
        LPC_CAN1->CMR = CAN1CMR_RRB;
        return g_BS_CAN.eBaudrate;
    }
    else
    {
        if( (BS_GetMsTicks()-g_BS_CAN.ulAutoBaudStartTime) > BS_CAN_AUTOBAUD_TIMEOUT_MS)
        { // No messages received, try next baudrate...


Thanks for any hint.
Labels (1)
0 Kudos
2 Replies

1,096 Views
roberthulsebos
Contributor I

 

  • Will baudrate detection work if no other device is acknowledging messages ?

    Answer: No. When there is only one device active on the CAN bus, then the messages it transmits will not be acknowledged by another device. As a result of this all other devices on the CAN bus that are in listen-only-mode will not receive the messages. That is a characteristic of the NXP CAN controller. Only correctly received messages are indicated with a receive interrupt (= RI bit in CANxICR register), and not-acknowledged messages are not considered correct messages. So basically listen-only-mode works only for a CAN bus with at least 2 active devices on it. Is this a showstopper - does this mean that the concept of baudrate detection is not feasible?

    No. Fortunately there is a way of detecting such not-acknowledged messages. Using the combination of the BEI, ERRBIT, ERRDIR and ERRC bits of the CANxICR register and the CANxRID register it is possible to detect an incoming not-acknowledged message and determine that it was not ‘normally’ received because of missing acknowledgement. The CANxID register can be used to retrieve the ID part of the message and determine if it was a known message. Try another baudrate if not known. Note that this is not explicitly documented behavior of the NXP CAN controller, so we are lucky here it works the way it works. There is a risk that with future silicon this may change…

 

0 Kudos

1,103 Views
sanderverhage
Contributor I

This issue has been posted a long time ago, but i believe it's still a problem in the entire LPC17xx microcontroller range.

When a CAN-BUS has only 2 nodes, one transmitting messages in normal mode and the other configured in listen only mode (LOM), the node configured in listen only mode doesn't signal the application about the received messages. This is probably caused by the fact, that the messages are not acknowledged on the bus, but acknowledgement shouldn't be a requirement for delivering messages to the application, when a node operates in listen only mode. Otherwise it's not posible to do autobaud detection or create a decent CAN monitoring device. 

In order to verify my reasoning, i have tried the same setup with a LPC2129 microcontroller. The CAN controller of the LPC2129 forwards all messages in listen only mode, so acknowlegement is (as expected) not required.

Is there a way to receive all CAN messages, using a LPC17xx microcontroller operating in LOM?

Thanks

0 Kudos