Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[help] receiving code of can controller lpc2129

Status
Not open for further replies.

jjeevan007

Full Member level 5
Joined
Apr 13, 2012
Messages
310
Helped
44
Reputation
88
Reaction score
43
Trophy points
1,308
Location
bangalore
Activity points
2,782
hi to all,

i am implementing can protocol using two LPC2129 controller

one is sending data and one is receiving data....

here is code for sending

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;

//DWORD *pAddr;


PINSEL1 |=0x00040000;

C1MOD = 0x01;
C1GSR = 0x00;
C1IER = 0x02;
C1BTR = 0x001C001D;
C1EWL = 0xff;
C1MOD = 0x00;

//pAddr = (DWORD *) AFRAM;

AFMR = 0x00000001;
SFF_sa = 0;

*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++);
	}





int main()
{
unsigned int i='a';
//unsigned int status;


CAN_init();


PINSEL0=0;
IO0DIR= 0x000000ff;
while(1)
{

while((C1SR & 0x00000004) != 0x00000004);
C1TFI1 = 0x00040000;
C1TID1 = 0x000000CF;
C1TDA1 = i;
C1CMR = 0x21;
//val=C1ICR;
//while((C1GSR & 0x00000008) != 0x00000008);

//status = C1GSR; 
while((C1GSR & 0x00000008) != 0x00000008);
//{
//status = C1GSR;
//}


		IO0SET = 0x000000ff;  
		 MSdelay (1000);  
  		 IO0CLR = 0x000000ff;
		 MSdelay(1000);
}



}


here is code for receiving

Code:
#include<lpc21xx.h>


unsigned int val,n;



void CAN_init()
{
unsigned int * pAddr;
pAddr  = (unsigned int * )0xE0038000;




PINSEL1 |=0x00040000;

C1MOD = 0x01;
C1GSR = 0x00;
C1IER = 0x00;
C1BTR = 0x001C001D;
C1EWL = 0xff;
C1MOD = 0x00;



AFMR = 0x00000001;

*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();

n=0x00310000;
lcddatawrt();


while(1)
{
n=0x00310000;
lcddatawrt();
while ((C1GSR & 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);



}


in simulating i can able see sending of data correctly,

but i am not able simulate the receiving part so help me with receiving part of my code

regards
jeevan
 
Last edited:

zip and post your simulation file. is it proteus simulation? What is your problem?

What I see in your receiving code is that you have two while loops, but there is no braek statement for inner while loop i.e., no break for the code

Code:
while ((C1GSR & 0x00000001) !=0x00000001)
{
		 IO0SET = 0x0000000f;  
		 //MSdelay (2000);  
  		 //IO0CLR = 0x0000000f;
		 //MSdelay(2000);


}
 
Last edited:

Can you zip and post the simulation file and your code file?
 
  • Like
Reactions: ASHIF

    ASHIF

    Points: 2
    Helpful Answer Positive Rating
ok i will try with it


hi i am new to ARM ... doing project in CAN only ... plz help i dont know how to start code for CAN .... somewhat can able to understand code !!!
but in simulation only transmission message displaying ... how to conform both r communicating? pls share ur Knowledge

Thank you
 
  • Like
Reactions: ASHIF

    ASHIF

    Points: 2
    Helpful Answer Positive Rating
receiving of the CAN can not simulated in LPC2129................

do u have a written code then post it so that we can help u..........
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top