C_CAN on 11C14, RX status OK, but message body is NULL

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

C_CAN on 11C14, RX status OK, but message body is NULL

334 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gossamer on Sun Oct 25 06:27:40 MST 2015
I am trying to read all messages from CAN bus. I have configured filter to accept all messages, and I receive RX interrupt when message is sent by other device on CAN bus

void canBus::configureMessage ()
{
LPC_CAN->IF2_CMDMSK = WR|MASK|ARB|CTRL|DATAA|DATAB;

LPC_CAN->IF2_MCTRL  = 0;
LPC_CAN->IF2_MSK1   = 0;
LPC_CAN->IF2_MSK2   = 0;

LPC_CAN->IF2_ARB1   = 0;
LPC_CAN->IF2_ARB2   = (1UL << 15);

LPC_CAN->IF2_DA1    = 0;
LPC_CAN->IF2_DA2    = 0;
LPC_CAN->IF2_DB1    = 0;
LPC_CAN->IF2_DB2    = 0;
LPC_CAN->IF2_MCTRL  = UMSK|RXIE|EOB|DLC;

LPC_CAN->IF2_CMDREQ = 1;
while (LPC_CAN->IF2_CMDREQ & CMDREQ_BUSY);
}


I get proper message number when interrupt arrived. So if I change CMDREQ to 5, I will receive 5 in
msg_no = LPC_CAN->INT & INT_MSG_NUM_MASK;
,

but apart from that, everything else is wrong.

void canBus::processMessage (uint8_t a_msgNo)
{
uint32_t msgId;
can_msg msg;
while (LPC_CAN->IF2_CMDREQ & CMDREQ_BUSY);

LPC_CAN->IF2_CMDMSK = WR_RD|MASK|ARB|CTRL|INTPND|TREQ|DATAA|DATAB;
LPC_CAN->IF2_CMDREQ = a_msgNo;

while (LPC_CAN->IF2_CMDREQ & CMDREQ_BUSY);

if (IS_BIT_ENABLED(LPC_CAN->IF2_ARB2, MSG_EXTENDED)) {
msgId = (LPC_CAN->IF2_ARB1 | ((LPC_CAN->IF2_ARB2&0x5fff)<<16));
}
else {
msgId = (LPC_CAN->IF2_ARB2 & ID_STD_MASK) >> 2;
}

msg.ident = msgId;
msg.len = MIN(LPC_CAN->IF2_MCTRL & 0x0f, 8);

switch (msg.len) {
case 8:
case 7:
msg.data[7] = LPC_CAN->IF2_DB2>>8;
msg.data[6] = LPC_CAN->IF2_DB2;
case 6:
case 5:
msg.data[5] = LPC_CAN->IF2_DB1>>8;
msg.data[4] = LPC_CAN->IF2_DB1;
case 4:
case 3:
msg.data[3] = LPC_CAN->IF2_DA2>>8;
msg.data[2] = LPC_CAN->IF2_DA2;
case 2:
case 1:
msg.data[1] = LPC_CAN->IF2_DA1>>8;
msg.data[0] = LPC_CAN->IF2_DA1;
break;
default:
break;
}
}

msg.ident is 0, len in 8 even though I sent message with only 2 bytes, and all data are 0 anyway. Message is correctly send on CAN bus, as I can capture it with logic analyzer.

I am not sure what am I doing wrong.
Labels (1)
0 Kudos
0 Replies