CAN implementation Using LPC2129
Discussion in "ARM Development" started by jjeevan007 Nov 17, 2012.
Sat Nov 17 2012, 07:49 pm
hi to all,
i want to implement the Can protocol using two LPC2129 controller so help,
here is the receiving code of the can which is not working so please guide me
code:
regards,
jeevan
i want to implement the Can protocol using two LPC2129 controller so help,
here is the receiving code of the can which is not working so please guide me
code:
#include<lpc21xx.h> unsigned int val,n,fs,id,data; unsigned char i=0; void CAN_init() { unsigned int * pAddr; pAddr = (unsigned int * )0xE0038000; PINSEL1 =0x00054000; C1MOD = 0x01; C1GSR = 0x00; C1ICR = 0x00; C1IER = 0x01; C1BTR = 0x001C001D; C1EWL = 0xff; C1MOD = 0x00; AFMR = 0x00000001; SFF_sa = 0xE0038000; *pAddr = 0x211f20cf; pAddr++; *pAddr = 0x206B2064; SFF_GRP_sa = 0x00000008; EFF_sa = 0x00000008; EFF_GRP_sa = 0x00000008; ENDofTable = 0x00000008; AFMR = 0x00000001; } void can_receive() { i=10; fs=C1RFS; id=C1RID; data=C1RDA; C1CMR = 0x00000004; VICSoftIntClr = 0x04000000; VICVectAddr = 0x00000000; } void initFiq(void) { VICIntEnable = 0x04000000; VICDefVectAddr = (unsigned) can_receive; } void MSdelay(unsigned int rtime) { unsigned int r,s; for(r=0;r<rtime;r++) for(s=0;s<7500;s++); } void lcdcommand(void) { MSdelay(6); IODIR1=0X00FF0000; /* P1.16..23 defined as Outputs */ IOPIN1 = n; IOCLR0=0x00000010; /* RS(P0.4)=0 */ IOCLR0=0x00000020; /* R/W(P0.5)=0 */ IOSET0=0x00000040; /* EN(P0.6)=1 */ IOCLR0=0x00000040; /* EN(P0.6)=0 */ } void lcddatawrt(void) { MSdelay(4); IODIR1=0X00FF0000; /* P1.16..23 defined as Outputs */ IOPIN1 = n; IOSET0=0x00000010; /* RS(P0.4)=1 */ IOCLR0=0x00000020; /* R/W(P0.5)=0 */ IOSET0=0x00000040; /* EN(P0.6)=1 */ IOCLR0=0x00000040; /* EN(P0.6)=0 */ } void lcd_initialization(void) { //PINSEL1=0x00000000; /*MAKE 0.28,0.29,0.30 AS I/O*/ //PINSEL2=0x00000000; /*MAKE 1.16...1.23 AS I/O*/ n=0x00380000; lcdcommand(); n=0x000c0000; lcdcommand(); n=0x00060000; lcdcommand(); n=0x00010000; lcdcommand(); } int main() { //unsigned int temp; PINSEL0=0; IO0DIR= 0x000000ff; initFiq(); lcd_initialization(); CAN_init(); //VICSoftInt = 0x04000000; n=0x00310000; lcddatawrt(); while(1) { ///* if(i==10) { n=0x00310000; lcddatawrt(); i=0; IOSET0=0x00000001; //if((fs & 0x40000000)!=0x40000000) // { //n=0x00310000; //lcddatawrt(); // if (id == 0x000000CF) // { n=0x000c0000; lcdcommand(); val = data; n=val<<16; lcddatawrt(); // } // else; // } } //else; //*/ /* while ((C1SR & 0x00000001) !=0x00000001) { IO0SET = 0x0000000f; //MSdelay (2000); //IO0CLR = 0x0000000f; //MSdelay(2000); } IO0CLR = 0X0000000F; //n=0x00310000; //lcddatawrt(); //temp=C1RFS; if((C1RFS & 0x40000000)!=0x40000000) { n=0x00310000; lcddatawrt(); //if((temp & 0x80000000) == 0x80000000) if (C1RID == 0x000000CF) { val = C1RDA; n=val<<16; lcddatawrt(); } else; C1CMR = 0x00000004; } */ } /* while((C1SR & 0x00000004) != 0x00000004); C1TFI1 = 0x00040000; C1TID1 = 0x000000CF; C1TDA1 = i; C1CMR = 0x21; while((C1GSR & 0x00000008) != 0x00000008); */ //while(1); }
regards,
jeevan
Powered by e107 Forum System