I am having an issue where the first CAN message received has the correct data field length, however the data bytes are all zeros. When I send the same CAN message a second time it works fine.
Here is my CAN initialization code:
/*--------------------------------------------------------------------
Function Name: can_init()
Purpose: This function will initialize the CAN Controller peripheral
Input(s): None
Output(s): None
----------------------------------------------------------------------*/
void can_init()
{
// ************************************************************************************************************
// Init CAN
SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0); // The GPIO port and pins have been set up for CAN.
GPIOPinTypeGPIOOutput( CANS_PORT, CANS_PIN );
GPIOPinWrite(CANS_PORT, CANS_PIN, 0 ); // S = LOW
IntMasterEnable(); // Enable processor interrupts.
GPIOPinConfigure(GPIO_PB4_CAN0RX); // Configure the GPIO pin muxing to select CAN0 functions for these pins.
GPIOPinConfigure(GPIO_PB5_CAN0TX);
GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5); // Enable the alternate function on the GPIO pins.
CANInit(CAN0_BASE); // Initialize the CAN controller
CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000); // Set up the bit rate for the CAN bus.
CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS); // Enable interrupts on the CAN peripheral. Name of the handler is in the vector table of startup code.
IntEnable(INT_CAN0); // Enable the CAN interrupt on the processor (NVIC).
CANEnable(CAN0_BASE); // Enable the CAN for operation.
}
Has anyone encountered this issue?
Thanks,
Robert