CAN PROTOCOL IN LPC2129

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CAN PROTOCOL IN LPC2129

1,231 Views
akhileshverneka
Contributor II

Sir I am working on Implementation of CAN protocol for LPC2129 board.Sir,When I  select CAN RX and CANTX  pin then the CAN TX line is Idle.But when I select only CAN TX then I get correct output.Please help me solve this issue.

I have attached the code below.

#include<lpc21xx.h>


char a[100]={1,3,5,7,9,11,13,15};
char b[100]={2,4,6,8,10,12,14,16};
char rxdata[8]={0,0,0,0,0,0,0,0};
char txdata[8]={0,0,0,0,0,0,0,0};
int flag=1;
unsigned int l,id;
unsigned int low,high;


void can_init()
{
PINSEL1 |= 0x00040000; can1 rx

AFMR=0x02; // All messages are received
C1MOD=0x01; // CAN is set to reset mode
C1IER=0x00; // Disabling all interrupts
C1RFS=0x00003000;
C1BTR=0x00270004; // Setting Baud rate to 500kbps , Baudrate Prescalar
C1MOD=0×00; // CAN is set to normal mode


}

void can_tx(char a[])
{

C1TFI1=0X00080000; // Data length code = 3 is set, RTR =0;
C1TID1=0X92; // Identifier is set to 34(dec)

C1TDA1=(a[0]) | (a[1]<<8) | (a[2]<<16) | (a[3]<<24); // 4 bytes of data is added
C1TDB1=(a[4]) | (a[5]<<8) | (a[6]<<16) | (a[7]<<24); //
C1CMR=0X21; // Transmission request and Transmitter buffer 1 is selected;

while((C1SR & 0x04 )!= 0x04); // wait till transmission is completed

}
void can_rx()
{
int i;
//while ((C1GSR & 0x00000010)!= 0x000000010)

flag=0;
// Checking if data is present in Rx buffer
if((C1RFS & 0x00000008)!=0x00000008)
{
l=C1RFS; // Length of the Received data
id=C1RID; // Stores the Identifier of the Rx msg into id
low=C1RDA; // Received data is stored in d
high=C1RDB;

for(i=0;i<4;i++)
{
txdata[i]=low<<(i*8);
}
for(i=4;i<8;i++)
{
txdata[i]=high<<(i*8);
}
}
else
C1CMR=0x04; // Releases the Rx buffer
}

int main()
{
can_init();

can_tx(a);


}

Tags (3)
2 Replies

1,186 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Akhilesh,

First of all, you have to connect a CAN transceiver and have at least two CAN nodes so that they can communicate each other.

BTW, the LPC2129 is a bit old, I suggest you use the latest LPC family.

BR

XiangJun Rong

1,186 Views
akhileshverneka
Contributor II

Thank you

0 Kudos