CAN RECEPTION ISSUE LPC2129

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

CAN RECEPTION ISSUE LPC2129

1,932 次查看
akhileshverneka
Contributor II

LPC2129 not receiving CAN messages. I have attached the code below of reception.Please help

void can_rx()
{
unsigned int l,id;
int i;
unsigned int low,high;
while ((C1GSR & 0x01)!=0x01);    // Checking if data is present in Rx buffer

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;

C1CMR=0x04; // Releases the Rx buffer

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

}

标记 (3)
0 项奖励
回复
2 回复数

1,894 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Akhilesh,

I think you have to set up the CAN baud rate of LPC2129, set up the ID you want to accept.

Anyway, there is code bundle for the LPC2xxx, pls download the code and have a try.

BR

XiangJun Rong

Single-chip 16/32-bit microcontrollers; 32/64/128/256/512 kB ISP/IAP flash with 10-bit ADC and DAC |... 

0 项奖励
回复

1,894 次查看
akhileshverneka
Contributor II

#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);

can_rx();

 


}

Sir this is the complete code.

Please help

0 项奖励
回复