This is an old revision of the document!
//***************************************************************************** // // CAN message receiving. // //***************************************************************************** #include <inc/hw_ints.h> #include <inc/hw_memmap.h> #include <inc/hw_types.h> #include <driverlib/sysctl.h> #include <driverlib/can.h> //***************************************************************************** // // Main function. // //***************************************************************************** int main(void) { tCANMsgObject psMsg; unsigned char pucData[8]; // // Set the clocking to run from the PLL at 50MHz // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Enable peripherals. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0); // // Configure CAN pins. // GPIOPinTypeCAN(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Enable the CAN controller. // CANInit(CAN0_BASE); CANBitRateSet(CAN0_BASE, SysCtlClockGet(), CAN_BITRATE); CANEnable(CAN0_BASE); // // Create receive message object. // psMsg.ulMsgID = 0x01; psMsg.ulMsgIDMask = 0xFF; psMsg.ulFlags = MSG_OBJ_NO_FLAGS; psMsg.pucMsgData = pucData; // // Set message object on box 1. // CANMessageSet(CAN0_BASE, 1, &psEchoMsg, MSG_OBJ_TYPE_RX); // // Loop forever. // while (1) { // // CAN message received ? // if (CANStatusGet(CAN0_BASE, CAN_STS_NEWDAT) & 1) { // // Get the message. // CANMessageGet(CAN0_BASE, CAN_MSG_OBJ_RX, &psMsg, true); // // Access pucData here. // To get the length of the data read psMsg.ulMsgLen // } } }