ARM LPC2129 Mini Development Board – CAN Interfacing
On board Controller Area Network (CAN) transceiver connection is a prominent feature of the rhydoLABZ make LPC2129 Development Board-Mini. For controlling the CAN, it has on board CAN transceiver MCP 2551, and the connection pinout is provided via RMC connector K15 (+5V,CANH,CANL,GND). This wiki section is all about LPC2129 Development Board-Mini’s CAN transceiver interfacing. Interfacing the CAN module requires connecting the jumpers J14 and J13.
The above figure depicts the CAN transceiver interfacing between two LPC2129 Mini Development Boards. Sample code for the same is given below. Once the code is loaded, the LCD display shows “CAN checking” at both transmitter and receiver end. Then the data communication will take place between both the transmitter end the receiver ends. Once the data is received the LEDs will blink up as per the code given below.
Schematic:
Sample code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
/****************************************************************************************************** * CAN PROGRAM * ******************************************************************************************************* * HEADER FILES * ******************************************************************************************************/ #include<lpc21xx.h> #define RS 0x00020000 /* 17th pin RS */ #define RW 0X00040000 /* 18th pin R/W */ #define EN 0X00080000 /* 19th pin EN */ #define CLR 0X00FE0000 /****************************************************************************************************** * VARIABLE DECLERATION * ******************************************************************************************************/ volatile unsigned char recdata; unsigned char data; int flag=0; /****************************************************************************************************** * Function : Delay * * Description : command for Delay * * Parameter : x ******************************************************************************************************/ int Delay(unsigned int x) { x=x*12000; while(x!=0){ x--; } return 0; } /****************************************************************************************************** * Function : Lcd_Command * * Description : command for lcd * * Parameter : command ******************************************************************************************************/ void Lcd_Command(char command) { int Temp; IO1CLR = CLR; /* Clear ALL 16-23 Pins */ IO1SET = EN; /* SET 19th Pin [EN] */ IO1CLR = RS; /* Clear 17th Pin [RS] */ IO1CLR = RW; /* Clear 18th Pin [R/W] */ Temp = (command & 0xF0) << 16; /* Higher Nibble Extracting 0X30 [3-High] & [4-7] Shifted To [20-23] */ IO1SET = IO1SET | Temp; /* 0X00080000 | 0X00300000[Shifted] = 0X00380000 [Only '3' Is in [20-23]pins */ Delay(2); /* Minimum Delay Time */ IO1CLR = EN; /* ENABLE High-Low Transition */ } /****************************************************************************************************** * Function : Lcd_Command1 * * Description : command for lcd * * Parameter : command1 ******************************************************************************************************/ void Lcd_Command1(char command1) { int Temp; IO1CLR = CLR; /* Clear ALL 16-23 Pins */ IO1SET = EN; /* SET 19th Pin [EN] */ IO1CLR = RS; /* Clear 17th Pin [RS] */ IO1CLR = RW; /* Clear 18th Pin [R/W] */ Temp = (command1 & 0xF0) << 16; /* Higher Nibble Extracting 0X30 [3-High] & [4-7] Shifted To [20-23] */ IO1SET = IO1SET | Temp; /* 0X00080000 | 0X00300000[Shifted] = 0X00380000 [Only '3' Is in [20-23]pins */ Delay(2); /* Minimum DelayTime */ IO1CLR = EN; /* ENABLE High-Low Transition */ IO1CLR = CLR; /* Clear ALL 16-23 Pins */ IO1SET = EN; /* SET 19th Pin [EN] */ IO1CLR = RW; /* Clear 17th Pin [RS] */ IO1CLR = RS; /* Clear 18th Pin [R/W] */ Temp = (command1 & 0x0F) << 20; /* Lower Nibble [0-3] Shifted To [20-23] & [0-3] Shifted To [20-23] */ IO1SET = IO1SET | Temp; /* 0X00080000 | 0X00800000[Shifted] = 0X00880000 [Only '8' Is in [20-23]pins */ Delay(2); /* Minimum Delay Time */ IO1CLR = EN; /* ENABLE High-Low Transition */ } /****************************************************************************************************** * Function : Lcd_Data * * Description : display command for lcd * * Parameter : data ******************************************************************************************************/ void Lcd_Data(char data) { int Temp; IO1CLR = CLR; /* Clear ALL 16-23 Pins */ IO1SET = EN; /* SET 19th Pin [EN] */ IO1CLR = RW; /* Clear 18th Pin [R/W] */ IO1SET = RS; /* Clear 17th Pin [RS] */ Temp = (data & 0xF0) << 16; /* Higher Nibble Extracting 0X30 [3-High] & [4-7] Shifted To [20-23] */ IO1SET = IO1SET | Temp; /* 0X00080000 | 0X00300000[Shifted] = 0X00380000 [Only '3' Is in [20-23]pins */ Delay(2); /* Minimum DelayTime */ IO1CLR = EN; /* ENABLE High-Low Transition */ IO1CLR = CLR; /* Clear ALL 16-23 Pins */ IO1SET = EN; /* SET 19th Pin [EN] */ IO1CLR = RW; /* Clear 18th Pin [R/W] */ IO1SET = RS; /* Clear 17th Pin [RS] */ Temp = (data & 0x0F)<<20; /* Lower Nibble [0-3] Shifted To [20-23] & [0-3] Shifted To [20-23] */ IO1SET = IO1SET | Temp; /* 0X00080000 | 0X00800000[Shifted] = 0X00880000 [Only '8' Is in [20-23]pins */ Delay(2); /* Minimum DelayTime */ IO1CLR = EN; /* ENABLE High-Low Transition */ } /******************************************************************************************************* * Function : Lcd_String * * Description : display group of data * * Parameter : dat *******************************************************************************************************/ void Lcd_String(unsigned char *dat) { while(*dat!='\0') { Lcd_Data(*dat); dat++; } } /****************************************************************************************************** * Function : Lcd_Init * * Description : Funtion for initialize LCD to display data * * Parameter : None *******************************************************************************************************/ void Lcd_Init(void) { Delay(15); /* Delay (1.5ms) */ Lcd_Command(0x30); /* Single line enable(2X16) */ Delay(10); /* Delay (10us) */ Lcd_Command(0x30); /* Single line enable(2X16) */ Delay(5); /* Delay (0.5ms) */ Lcd_Command(0x30); /* Single line enable(2X16) */ Lcd_Command(0x20); /* 4-bit Mode Enable */ Lcd_Command1(0x28); /* Double line enable (2X16) */ Lcd_Command1(0x01); /* Clear LCD */ Lcd_Command1(0x06); /* Automatic increment */ Lcd_Command1(0x0C); /* Cursor OFF /Display ON */ } /****************************************************************************************************** * Function : Can_Rx_Isr * * Description : CAN_Reception interrupt function * * Parameter : None *******************************************************************************************************/ void Can_Rx_Isr( void )__irq { data=C2RDA; C2CMR = 0x04; /* release the receive buffer */ VICVectAddr =0; } /****************************************************************************************************** * Function : Cart_Init * * Description : Cart_Initialization function * * Parameter : None ******************************************************************************************************/ void Cart_Init(void) { PINSEL1 |= 0X00014000; /* select pin for can rx PINSEL1 |= 0x00014000L; [ Set bits 14 and 16 ] */ AFMR = 0x2; /* All rx messages were accepted(Acceptance filter mode register) */ C2MOD = 0x01; /* Set CAN controller into reset */ C2IER = 0; /* disable all interrupt */ C2GSR = 0; /* clear all interrupts */ C2BTR = 0x001C0011; /* 100 kbpsc */ VICVectCntl0 = 0x0000003b; /* Interrupt vector number of CAN 2 */ VICVectAddr0 = (unsigned)Can_Rx_Isr;/* Interrupt vector address */ VICIntEnable = 0x08000000; /* Enable vectored interrupt for CAN 2 module */ VICIntSelect = 0x00000000; /* Initialise as IRQ */ C2IER = 0x01; /* Enable the Receive interrupt */ C2MOD = 0x00; /* Release CAN controller */ } /****************************************************************************************************** * Function : Can_Tx * * Description : CAN_DATA Transmission function * * Parameter : data ******************************************************************************************************/ void Can_Tx(int data ) { if((C2SR & 0X00000004)==0X00000004) /*cheking for CAN bus idle */ { C2TFI1 = 0x00010000; /* DLS&RTR(Transmit frame information register, No.data bytes transmitted) */ C2TID1 = 0x22; /* 11 bit Identefier */ C2TDA1 = data; /* Data */ C2CMR = 0X21; /* transmission request (command register,select tramission-1 TX buffer) */ while((C2GSR & 0X00000004)!=0X00000004); /* wait until complete transmission */ } } /****************************************************************************************************** * FUNCTION INITIALIZATION * ******************************************************************************************************/ void Port_Initial(void); void Can_Rx_Isr( void )__irq; /****************************************************************************************************** * CODE AREA * ******************************************************************************************************/ int main() { Port_Initial(); /* Function to initialize the direction & pinsel of ports */ Lcd_Init(); /* Initialization LCD */ Cart_Init(); /* Initialization of CAN */ Lcd_String("Rhydo Technology"); /* Initial displays */ Lcd_Command1(0xC0); Lcd_String(" Cochin "); Lcd_Command1(0x01); Lcd_Command1(0x80); Lcd_String("CAN checking"); /* CAN checking */ while(1) { if(data=='T') { IO0SET=0x000E0000; /* SET HIGH for LED's */ Delay(500); } if(data=='G') { IO0CLR=0x000E0000; /* CLR LED's */ Delay(500); } if(flag==0) { flag=1;Can_Tx('T'); } else { flag=0; Can_Tx('G'); } } } /****************************************************************************************************** * PORT INITIALIZATION * ******************************************************************************************************/ void Port_Initial(void) { IO1DIR = 0x00FE0000; /* 17-23 Pins As Output */ IO0DIR = 0x000E0001; /* for UART0 & LED' s */ PINSEL0 = 0x00000005; PINSEL1 = 0x05000000; PINSEL2 = 0x00000000; } /*********************************************END*****************************************************/ |
Topics related to ARM LPC2129 Mini Development Board:
- ARM LPC2129 Mini Development Board – Overview
- ARM LPC2129 Mini Development Board – LED Interfacing
- ARM LPC2129 Mini Development Board – LCD Interfacing
- ARM LPC2129 Mini Development Board – UART0 Interfacing
- ARM LPC2129 Mini Development Board – UART1 Interfacing
- ARM LPC2129 Mini Development Board – Switches Interfacing
- ARM LPC2129 Mini Development Board – BUZZER Interfacing
- ARM LPC2129 Mini Development Board – POT Interfacing (ADC)
- ARM LPC2129 Mini Development Board – Temperature Sensor Interfacing(ADC)
- ARM LPC2129 Mini Development Board – Interfacing Servo motor
- ARM LPC2129 Mini Development Board – CAN Interfacing
Resources:
- Softwares
How to buy
- Click here to buy rhydoLABZ ARM LPC2138 Mini Development Board
- Click here to buy rhydoLABZ ARM LPC2148 Mini Development Board
- Click here to buy rhydoLABZ ARM LPC2129 Mini Development Board
Support:
Please share your ideas with us,visit our forum for discussion