#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 =0;// 0xE0038000;
*pAddr = 0x211f20cf;
pAddr++;
*pAddr = 0x206B2064;
SFF_GRP_sa = 0x00000008;
EFF_sa = 0x00000008;
EFF_GRP_sa = 0x00000008;
ENDofTable = 0x00000008;
AFMR = 0x00000000;
}
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;
lcd_initialization();
CAN_init();
while(1)
{
// receiving the data frame
//while ((C1GSR & 0x00000008) !=0x00000008); checking the RBS bit
if((C1RFS & 0x40000000)!=0x40000000)
{
if (C1RID == 0x000000CF)
{
n=0x00800000;
lcdcommand();
val = C1RDA;
n=val;//<<16;
lcddatawrt();
}
else;
C1CMR = 0x00000004;
}
}
//transmitting data frame
/*
while((C1SR & 0x00000004) != 0x00000004);
C1TFI1 = 0x00040000;
C1TID1 = 0x000000CF;
C1TDA1 = i;
C1CMR = 0x21;
while((C1GSR & 0x00000008) != 0x00000008);
*/
}
the code is working fine its physical hardware implementation, since we cant simulate the receiving part of the data frame in CAN in KEIL uVersion3
while ((C1GSR & 0x00000008) !=0x00000008);
ya, but i told i have doubt in receiving part
Code:while ((C1GSR & 0x00000008) !=0x00000008);
in data sheet they said that RBS =1 when data frame is received,
when i do that i am not able to get the output......
if i dont monitor its working fine....
now should i monitor RBS bit or not .........
while(!(C1GSR & 0x00000001));
/****************************************************************************
* Name: IRQ_CAN2Rx()
* Function: IRQ_CAN2Rx interrupt
* Input(s): none
* Returns : none
****************************************************************************/
void __irq IRQ_CAN2Rx(void)
{
UInt32 Temp_CAN2Rx_IRQ=0;
UInt8 i=0;
plpc2000CANdriver_RXObj_t pCAN2_Rcv_Data_IRQ;
i = 0;
CAN2Rx_Return_Message_Flag[i] = 1; //indicate one Rx interrupt happened
i++;
Temp_CAN2Rx_IRQ = CAN2ICR;
if( (Temp_CAN2Rx_IRQ & 0x00000001) == 0x00000001 )
{
// put Rcv data to Rcv-Buffer, must assign value to pointer before used
pCAN2_Rcv_Data_IRQ = CAN_Rcv_Data + CAN_Rcv_Data_Counter;
Return_Value = lpc2000CANdriver_ReceiveMessageCh2 (pCAN2_Rcv_Data_IRQ);
CAN_Rcv_Data_Counter++;
CAN_Rcv_Status = 1; // communication successful
}
if( ((Temp_CAN2Rx_IRQ>>2) & 0x00000001) == 0x00000001 )
{
CAN2Rx_Return_Message_Flag[i] = 1;
//Add code for "Error Warning Interrupt-EI"
}
i++;
if( ((Temp_CAN2Rx_IRQ>>3) & 0x00000001) == 0x00000001 )
{
CAN2Rx_Return_Message_Flag[i] = 1;
//Add code for "Data Overrun Interrupt-DOI"
}
i++;
if( ((Temp_CAN2Rx_IRQ>>4) & 0x00000001) == 0x00000001 )
{
CAN2Rx_Return_Message_Flag[i] = 1;
//Add code for "Wake-Up Interrupt-WUI"
}
i++;
if( ((Temp_CAN2Rx_IRQ>>5) & 0x00000001) == 0x00000001 )
{
CAN2Rx_Return_Message_Flag[i] = 1;
//Add code for "Error Passive Interrupt-EPI"
}
i++;
if( ((Temp_CAN2Rx_IRQ>>6) & 0x00000001) == 0x00000001 )
{
CAN2Rx_Return_Message_Flag[i] = 1;
//Add code for "Arbitration Lost Interrupt-ALI"
}
i++;
if( ((Temp_CAN2Rx_IRQ>>7) & 0x00000001) == 0x00000001 )
{
CAN2Rx_Return_Message_Flag[i] = 1;
//Add code for "Bus Error Interrupt-BEI"
}
i++;
if( ((Temp_CAN2Rx_IRQ>>8) & 0x00000001) == 0x00000001 )
{
//Add code for "ID Ready Interrupt-IDI"
}
VICVectAddr = 0x00;
}
while(!(C1GSR & 0x00000001));
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?