CAN ACK (and etc) problem

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

CAN ACK (and etc) problem

464 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by m2babaey on Tue Aug 20 01:36:23 MST 2013
Hi
I'm trying to make CAN1 of LPC1768 work using CMSIS drivers
When I transmitted a message to another CAN device, the message was not transferred successfully (the receiver was getting wrong data) so I decided to check loopback mode first

Now when self test mode(STM) in CAN1MOD is 1 and self reception request (SSR) is 1 message is transmitted and receive interrupt occurs, everything ok

But if SSR=1 and STM=0 no receive interrupt happens, although if I read receive registers, they have the correct data but it seems transmit error counter limit is reached not no acknowledge is received. Also no interrupt occurs

In another test, when the other can device sends messages to me, receive error counter limit appears and no interrupt is generated

My questions:
1. Why receive interrupt doesn't occur when STM=0?
2. How can I understand what is the data that is transmitted so find out what the problem is?
3. How can one figure out what kind of error has occurred in receiving so the receive error count limit has reached?
4. Any other hints that can help me the fix my CAN receive and transmit?

Here is the related part of my code:

#define Fcpu 23040000             //11.0592 xtal, M=100, N=6, CPU_D=4  => 2*xtal*M/N/CPU_D/4 = MIPS

void CAN_IRQHandler(void)
{
unsigned char myvar[60];
CAN_ReceiveMsg(LPC_CAN1,&RXMsg);

SendString0("CAN Int\r\n");
sprintf(myvar,"RID is %x  and ICR is %x and RDA is %x and RFS is %x\r\n",LPC_CAN1->RID,LPC_CAN1->ICR,LPC_CAN1->RDA,LPC_CAN1->RFS);
SendString0(myvar);
LPC_CAN1->CMR = CAN_CMR_AT | CAN_CMR_RRB | CAN_CMR_CDO;
}

void SendCANMsg()
{
TXMsg.id = 46;
TXMsg.dataA[0] = 5;
TXMsg.dataA[1] = 6;
TXMsg.dataA[2] = 7;
TXMsg.dataA[3] = 8;

TXMsg.len = 4;
TXMsg.format = STD_ID_FORMAT;
TXMsg.type   = DATA_FRAME;

CAN_SendMsg(LPC_CAN1,&TXMsg);
}


int main (void) 
{
unsigned int i;
unsigned char myvar[30];
baudrate=986040;
CAN_Init(LPC_CAN1, baudrate);  //((int) 983040)
//Enable Interrupt
CAN_IRQCmd(LPC_CAN1, CANINT_RIE, ENABLE);
CAN_IRQCmd(LPC_CAN1, CANINT_DOIE, ENABLE);
CAN_ModeConfig(LPC_CAN1,CAN_OPERATING_MODE , ENABLE); //CAN_OPERATING_MODE CAN_MOD_STM
CAN_SetAFMode(LPC_CANAF,CAN_AccBP);
NVIC_EnableIRQ(CAN_IRQn);

while(1)
{
if(doProcess) //every 1 second is activated by timer 0
{
  doProcess=0;
sprintf(myvar,"GSR is %x  and SR is %x\r\n",LPC_CAN1->GSR,LPC_CAN1->SR);
SendString0(myvar);
sprintf(myvar,"RID is %d  and DATA is %x\r\n",LPC_CAN1->RID,LPC_CAN1->RDA);
LPC_CAN1->CMR = CAN_CMR_AT | CAN_CMR_RRB | CAN_CMR_CDO;
SendString0(myvar);/**/
SendCANMsg();

}

}
}


Thanks in advance

Labels (1)
0 Kudos
1 Reply

423 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by arw on Fri Aug 23 10:01:17 MST 2013
In my experience with this type of behavior, there is normally a mismatch in baud rate between the two nodes.  Check carefully that the baud rate and bit timings match on both nodes.  With the clock frequency you have defined above, I'm not sure if you can hit a typical bus baud rate like 250kHz.
If you have a bus analyzer, it might also give you more information by auto-baud adaptating to the transmitter's baud rate.

Cheers!
0 Kudos