This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:examples:can:arm [2010/03/15 08:23] – mikk.leini | en:examples:can:arm [2010/03/15 08:40] (current) – removed mikk.leini | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Simple CAN ====== | ||
| - | ===== Practice ===== | ||
| - | |||
| - | ARM-CAN controller board MCU is programmed with the help of Texas Instruments (former Luminary Micro) StellarisWare software library. The library includes all the functions to alter microcontroller' | ||
| - | |||
| - | <code c> | ||
| - | // | ||
| - | // | ||
| - | // CAN message receiving. | ||
| - | // | ||
| - | // | ||
| - | |||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | // | ||
| - | // | ||
| - | // 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 | | ||
| - | | ||
| - | |||
| - | // | ||
| - | // Enable peripherals. | ||
| - | // | ||
| - | SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); | ||
| - | SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0); | ||
| - | |||
| - | // | ||
| - | // Configure CAN pins. | ||
| - | // | ||
| - | GPIOPinTypeCAN(GPIO_PORTD_BASE, | ||
| - | |||
| - | // | ||
| - | // Enable the CAN controller. | ||
| - | // | ||
| - | CANInit(CAN0_BASE); | ||
| - | CANBitRateSet(CAN0_BASE, | ||
| - | CANEnable(CAN0_BASE); | ||
| - | |||
| - | // | ||
| - | // Create receive message object. | ||
| - | // | ||
| - | psMsg.ulMsgID | ||
| - | psMsg.ulMsgIDMask = 0xFF; | ||
| - | psMsg.ulFlags | ||
| - | psMsg.pucMsgData | ||
| - | |||
| - | // | ||
| - | // Set message object on box 1. | ||
| - | // | ||
| - | CANMessageSet(CAN0_BASE, | ||
| - | |||
| - | // | ||
| - | // Loop forever. | ||
| - | // | ||
| - | while (1) | ||
| - | { | ||
| - | // | ||
| - | // CAN message received ? | ||
| - | // | ||
| - | if (CANStatusGet(CAN0_BASE, | ||
| - | { | ||
| - | // | ||
| - | // Get the message. | ||
| - | // | ||
| - | CANMessageGet(CAN0_BASE, | ||
| - | |||
| - | // | ||
| - | // Access pucData here. | ||
| - | // To get the length of the data read psMsg.ulMsgLen | ||
| - | // | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | </ | ||