Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:examples:can:arm [2010/03/14 18:14] mikk.leinien:examples:can:arm [2010/03/15 08:40] (current) – removed mikk.leini
Line 1: Line 1:
-====== Simple CAN ====== 
  
-===== Practice ===== 
- 
-<code c> 
-//***************************************************************************** 
-// 
-// 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 
- // 
- } 
- } 
-} 
-</code> 
en/examples/can/arm.1268590460.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0