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.

LAUNCHXL-F28379D: CAN CODING

Part Number: LAUNCHXL-F28379D

Hi,

I have a doubt in the code below. I am unable to understand the entry condition of the " if " block. I know that RXOK is the bit that has to be checked to confirm that the receiver has received the data with no errors. Isn't if (CAN_ES_RXOK) condition sufficient?

if(((HWREGH(CANA_BASE + CAN_O_ES) & CAN_ES_RXOK)) == CAN_ES_RXOK)
{
//
// Get the received message
//
CAN_readMessage(CANA_BASE, RX_MSG_OBJ_ID, rxMsgData);
GPIO_togglePin(65U);
rxMsgCount++;
}

Also, it would be helpful if you could define HWREGH and CAN_O_ES in short. I couldn't find it anywhere in the technical reference manual.

Thank you,

Karthikeya

  • Isn't if (CAN_ES_RXOK) condition sufficient?

    if (CAN_ES_RXOK) condition is not sufficient. You need to read the CANES register first. Only then the code can determine the status of the RXOK bit.

    it would be helpful if you could define HWREGH and CAN_O_ES in short.

    HWREGH is used to directly write/read registers.

    How to directly write/read registers:

    For accessing lower or upper 16-bits of a register, use HWREGH. (Have to add 2 to access upper 16-bits when dealing with byte peripherals such as CAN).

    HWREGH(ui32Base + CAN_O_IF1ARB) = 0x4321;     // Write 0x4321 to LOWER 16-bit
    
    HWREGH(ui32Base + CAN_O_IF1ARB + 2) = 0x8765; // Write 0x8765 to UPPER 16-bit

    After executing the above 2 lines, CAN_0_IF1ARB should contain 0x87654321.

    For all 32-bit access, use HWREG_BP.

    HWREG_BP(ui32Base + CAN_O_IF1ARB) = 0x87654321;     // Write 0x87654321 to the 32 bits

    After executing the above line, CAN_0_IF1ARB should contain 0x87654321.

    CAN_O_ES refers to the CANES register.

  • Thank you for responding sir.

    In this code snippet ((HWREGH (CANA_BASE + CAN_O_ES) & CAN_ES_RXOK)) == CAN_ES_RXOK, the lower 16 bits of the CANES register are read and a bitwise AND operation is performed on it. I did not understand what was going on here. Could you please explain it?

    Also, are CAN_O_ES and CAN_ES the same?

    Thank you

    Karthikeya

  • In this code snippet ((HWREGH (CANA_BASE + CAN_O_ES) & CAN_ES_RXOK)) == CAN_ES_RXOK, the lower 16 bits of the CANES register are read and a bitwise AND operation is performed on it.

    Correct. It takes some effort to learn the coding style used in Driverlib, since multiple files are involved. 

    Also, are CAN_O_ES and CAN_ES the same?

    Already answered in the previous post. They are the same.