Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

[Help] Can Controller of LPC2129

Status
Not open for further replies.

jjeevan007

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

i want to implement CAN protocol in LPC2129

i am clear with can protocol, but i am not able understand

Acceptance Filter RAM

Acceptance Filter Registers

of the CAN controller in LPC2129

why we use these registers and their functions in CAN controller in LPC2129

regards
jeevan
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
zip and post your project files and proteus file. I will try.
 
  • Like
Reactions: mkumar

    mkumar

    points: 2
    Helpful Answer Positive Rating

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,505
The CAN bus utilizes a Message ID centric system, in contrast to Ethernet which is a Node ID centric system, this approach allows a node to receive virtually all traffic on the bus.

The messages received by a CAN node can be limited by the use of an Acceptance Filter, which determines the messages accepted by its ID.

KEIL CAN Peripheral Simulation


BigDog
 

jjeevan007

Full Member level 5
Joined
Apr 13, 2012
Messages
311
Helped
44
Reputation
88
Reaction score
43
Trophy points
1,308
Location
bangalore
Activity points
2,781
i have implemented the CAN its working fine but still i have doubts regarding receiving of data frame in LPC2129 CAN Controller.

my doubt : in GSR register of CAN, the RBS will be set after receiving the data frame, but if i monitor the RBS bit for setting then my program will not work, if i dont monitor the RBS bit then my code is working fine

regards
jeevan
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,505
It's been a while since I last used a LPC21XX series ARM as a CAN node.

Can you post or upload your code so that I may examine it?

Mean while I'll dig up my last LPC21XX CAN project and maybe I can advise you.

Also, is your project a simulation or physical hardware?

If simulation, please include the simulation project file as well.


BigDog
 

jjeevan007

Full Member level 5
Joined
Apr 13, 2012
Messages
311
Helped
44
Reputation
88
Reaction score
43
Trophy points
1,308
Location
bangalore
Activity points
2,781
here is code

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 =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
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,505
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

The LPC2129 does provide two separate CAN controllers, you can utilize both CAN controllers to test your code.

Although, I've never attempted it, you might be able to directly cross connect the TX and RX CAN lines between the two CAN controllers.

If not, you'll need to used two CAN transceivers, one for each CAN controller and implement a proper CAN bus.

I've used the latter technique when developing CAN code using only a single development board.


BigDog
 

jjeevan007

Full Member level 5
Joined
Apr 13, 2012
Messages
311
Helped
44
Reputation
88
Reaction score
43
Trophy points
1,308
Location
bangalore
Activity points
2,781
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 .........

please guide me to understand the CAN of LPC2129....

regards
jeevan
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,505
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 .........
According to the LPC2129 User Manual, the RBS flag is Bit0 in the C1GSR register, not Bit3.

The following polls/tests RBS until set:
Code:
while(!(C1GSR & 0x00000001));
The main problem with polling a flag is the microcontroller becomes totally dedicated to task of polling, in effect just burning cycles waiting for the state of the flag to transition rather than service another task.

Also, if no CAN message is ever sent, the microcontroller is essentially "stuck" at that point in the code. Which is why most tasks are handled by interrupt rather than polling.

The following CAN examples use CAN Receive Interrupt (RI Bit0 of CANICR), which is triggered when both RBS bit in CANSR and the RIE bit in CANIER are both set.

The CAN Receive Interrupt Service Routine:

Code:
/****************************************************************************
* 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;
  
}

The attached demos use the above ISR and are compatible with LPC2129.

BigDog
 

Attachments


jjeevan007

Full Member level 5
Joined
Apr 13, 2012
Messages
311
Helped
44
Reputation
88
Reaction score
43
Trophy points
1,308
Location
bangalore
Activity points
2,781
i want to do in polling method method the main thing is
Code:
while(!(C1GSR & 0x00000001));
is not getting set when it receives the any frame ..........

if i dont check that flag the i am able to access the received frame....
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,505
The CAN physical layer is half duplex, therefore you can't receive the same message you've transmitted unless the device offers two CAN controllers and both are utilized.

Also be aware, polling can easily lead to a state of contention, waiting endlessly for a message to arrive.

You might want to monitor the RI flag instead with a builtin time out to avoid the state of contention.


BigDog
 

jjeevan007

Full Member level 5
Joined
Apr 13, 2012
Messages
311
Helped
44
Reputation
88
Reaction score
43
Trophy points
1,308
Location
bangalore
Activity points
2,781
yes sir, i agree the disadvantage of polling method and can physical layer is half duplex, my main point why the RBS bit is not getting set.....

i didnt tried with interrupt method

its basic can implementation so i gone of polling method.......

i will try with interrupt method also......
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top