EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

lpc2129 CAN problem

Started by Rahul Bhatt January 31, 2013
hi
following is my CAN transmitter code of lpc2129

void Can_Init_tx(void)
{

PINSEL1 |= (DWORD) 0x00014000;
C2MOD = 1;
C2GSR = 0;
C2BTR = 0x00CBC01E; //baud rate 0f 125k
C2TFI1 |= 0x80000000;
C2MOD = 0;
}

void SendMessage(unsigned int x)
{
unsigned int status;
while((C2SR & 0x00000004)==0);
C2TFI1 = 0x00080000; //set DLC to 8 bytes;
C2TID1 = 0x00000022; //sets 29 bit identifier
C2TDA1 = x; //data to be send;
C2TDB1 = 0x00000000;
C2CMR = 0x00000021; //transmit the msg;
status = C2GSR;
}
void main(void)
{
int value;
VPBDIV=0x00000001;
Can_Init_tx();

while(1)
{
value=read_adc(); //adc output
SendMessage(value);

}
}

--
when iam trying to send the data the transmit buffer are not clearing and
program get stucked while checking C2SR
this is my receive part
void Can_Init_rx(void)
{
DWORD *pAddr;
VPBDIV=0x00000001;
PINSEL1 |= (DWORD) 0x00054000;

C2MOD = 1;
C2GSR = 0; // Clear status register
C2BTR = 0x00CBC01E;

C2IER = 1; //enable to receive interrupt
C2MOD = 0; // Enter Normal Operating Mode
AFMR = 0x00000001; //disable acceptance filter
SFF_sa = 0; //the start address of d table of individual
standard identifiers in AF lookup RAM

pAddr = (DWORD *) ACCEPTANCE_FILTER_RAM_BASE; //aceptance filter
RAM base address

*pAddr = 0x20012002;
pAddr++;
*pAddr=0x20032004;
SFF_GRP_sa = 0x00000008;
EFF_sa = 0x00000008;
EFF_GRP_sa = 0x00000008;
ENDofTable = 0x00000008;
AFMR = 0x00000000; //enable acceptace filter;
C2MOD=0x00000000; //Release CAN controller
}

and iam using interrupt mode for receiving.

please help
Thanks and regards
RAHUL BHATT
8698500248


An Engineer's Guide to the LPC2100 Series

On 31.01.2013 17:04, Rahul Bhatt wrote:
> when iam trying to send the data the transmit buffer are not clearing and
> program get stucked while checking C2SR

Do you have a proper CAN-bus with termination resistors and another
device receiving the message. Sending a message doesn't succeed and
transmit buffer doesn't become empty, until an other device acknoledges
successful reception.

--

Timo

Il 31/01/2013 16:04, Rahul Bhatt ha scritto:
>
>
> hi
> following is my CAN transmitter code of lpc2129
>
I have no time to check your code but I can suggest you to program the
CAN module in test mode to act both as transmitter and receiver to check
if your sw is correct. The idea is that you can check the
synchronization problems on the same piece of software with only one
board and so you have just to write-compile-test 1 piece of code
speeding up your debugging. At the beginning mocking the reception may
be useful to test the middle layer functions without requiring real
message reception.
> void Can_Init_tx(void)
> {
>
> PINSEL1 |= (DWORD) 0x00014000;
> C2MOD = 1;
> C2GSR = 0;
> C2BTR = 0x00CBC01E; //baud rate 0f 125k
> C2TFI1 |= 0x80000000;
> C2MOD = 0;
> }
>
> void SendMessage(unsigned int x)
> {
> unsigned int status;
> while((C2SR & 0x00000004)==0);
> C2TFI1 = 0x00080000; //set DLC to 8 bytes;
> C2TID1 = 0x00000022; //sets 29 bit identifier
> C2TDA1 = x; //data to be send;
> C2TDB1 = 0x00000000;
> C2CMR = 0x00000021; //transmit the msg;
> status = C2GSR;
> }
> void main(void)
> {
> int value;
> VPBDIV=0x00000001;
> Can_Init_tx();
>
> while(1)
> {
> value=read_adc(); //adc output
> SendMessage(value);
>
> }
> }
>
> --
> when iam trying to send the data the transmit buffer are not clearing and
> program get stucked while checking C2SR
>
> this is my receive part
> void Can_Init_rx(void)
> {
> DWORD *pAddr;
> VPBDIV=0x00000001;
> PINSEL1 |= (DWORD) 0x00054000;
>
> C2MOD = 1;
> C2GSR = 0; // Clear status register
> C2BTR = 0x00CBC01E;
>
> C2IER = 1; //enable to receive interrupt
> C2MOD = 0; // Enter Normal Operating Mode
> AFMR = 0x00000001; //disable acceptance filter
> SFF_sa = 0; //the start address of d table of individual
> standard identifiers in AF lookup RAM
>
> pAddr = (DWORD *) ACCEPTANCE_FILTER_RAM_BASE; //aceptance filter
> RAM base address
>
> *pAddr = 0x20012002;
> pAddr++;
> *pAddr=0x20032004;
> SFF_GRP_sa = 0x00000008;
> EFF_sa = 0x00000008;
> EFF_GRP_sa = 0x00000008;
> ENDofTable = 0x00000008;
> AFMR = 0x00000000; //enable acceptace filter;
> C2MOD=0x00000000; //Release CAN controller
> }
>
> and iam using interrupt mode for receiving.
>
> please help
>
> Thanks and regards
> RAHUL BHATT
> 8698500248
>
>




The 2024 Embedded Online Conference