This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to read identifier(ID) of each CAN message



Hi All,

I am trying to read the identifier(ID) of each CAN message, since I configured the CAN of TMS570LS3 to receive CAN messages of all CAN nodes on the CAN bus, I want to find out which node sent the CAN message. I know that the CAN ID of each message is stored in the message ram in Debug/Suspend mode(and normal mode as well, but I forced a pointer to read the RAM location but failed to read the value out), and if I want to read them out in normal mode, what should i do? I thought the DCANIF1ARB or IF2ARB should do the work, but I failed to achieve it. Every time I read IFARB register I got the value I initially setup at canInit. Could you tell me how I could read out the CAN ID of each message please?

Many thanks,

Shawn

  • Hi Shawn,

    using IF1ARB or IF2ARB is the right approach to read out the CAN message IDs. However to be able to read it out from those registers you need to setup a read transfer from the message RAM into the IF1ARB or IF2ARB register for the message object which you are using. Please see the the section "24.6.2 Using Message Interface Register Sets 1 and 2" in the TRM for details.

    Best regards

    Andreas

    If a post answers your question, please mark it with the "verify answer" button.

  • Hi Andreas,

    Thank you for your reply, I managed to solve the problem. I set IF3UpdEn register to allow automatically update of all messages, and by reading IF3ARB and IF3Datax, it works.

    Thanks,

    Shawn

  • Hi,

    I'm having the same problem as Shawn. I've tried to implement the access you described for IF1ARB/IF2ARB but I'm not having a great deal of success.

    Can you post a fragment of code in here that does an ARB register read, so I can see where I'm going wrong?

    Thanks

    Andy

  • Hello Andy,

    in order to read the IFxARB register you need to setup a read transfer from the message RAM to the IFx registers.
    Therefore in IFxCMD:

    - Bit 23 WR/RD: 0 -> Read
    - Bit 21 Arb: 1-> transfer arbitration bits
    - Write message object number into bits 7:0 to trigger the transfer.
    - Check bit 15 (busy) to see when the transfer is finished.

    Best regards

    Andreas

    If a post answers your question, please mark it with the "verify answer" button.

  • Hi Andreas,

    I believe the code fragment below does what you described:

    void CAN2_RX_Unload_Rx_Msg(U8 fifo_buff_num_u8)
    {
        U16 can_id_u16;
        U32 can_id_u32;
        U8  rx_buffer_u8;
        U32 ExtendedID_u32;
        U32 Status;
        
        
        while (canREG2->IF2STAT & 0x80U){}  // wait until IF registers are free
        canREG2->IF2CMD = 0x23;             // bits 23 = 0, 21 = 1, 17&16 = 1 (RD, ARB, DATA A & DATA B)
        canREG2->IF2NO   = fifo_buff_num_u8;
        
        while (canREG2->IF2STAT & 0x80U){}  // wait until IF registers are free
        ExtendedID_u32 = canREG2->IF2ARB;
        
    There is only one message being transmitted from CAN1 and received by CAN2. That message has an ID of 0x400. 

    DCAN2->NEWDATX = 0x00000001 and DCAN2->NEWDAT12 = 0x00000001, indicating message box 1 contains the new message.

    fifo_buff_num_u8 = 1, but the value read into ExtendedID_u32 is 0x90000000 rather than the expected 0x400.

    What have I missed?

    Regards

    Andy

  • Hi Andy,

    looks like you are working with standard 11-bit IDs, then the ID 0x400 is correctly represented in the IFxARB register with the value you have give above. Please note that in standard ID mode the ID bits are IFxARB[28:18].

    Best regards

    Andreas

    If a post answers your question, please mark it with the "verify answer" button.

  • Ah, yes, of course!

    Thanks

    Andy

    ps. your last post said to press the "verify answer" button, but there isn't one.