Do the following if you want to transmit message. TCS checking in GSR register is important:
while ( !(LPC_CAN1->GSR & (0x1<<3)) );
CANStatus = LPC_CAN1->SR;
if ( CANStatus & 0x00000004 )
{
LPC_CAN1->TFI 1 = pTxBuf->Frame & 0xC00F0000;
LPC_CAN1->TID1 = pTxBuf->MsgID;
LPC_CAN1->TDA1 = pTxBuf->DataA;
LPC_CAN1->TDB1 = pTxBuf->DataB;
LPC_CAN1->CMR = 0x21;
return ( TRUE );
}
else if ( CANStatus & 0x00000400 )
{
LPC_CAN1->TFI2 = pTxBuf->Frame & 0xC00F0000;
LPC_CAN1->TID2 = pTxBuf->MsgID;
LPC_CAN1->TDA2 = pTxBuf->DataA;
LPC_CAN1->TDB2 = pTxBuf->DataB;
LPC_CAN1->CMR = 0x41;
return ( TRUE );
}
else if ( CANStatus & 0x00040000 )
{
LPC_CAN1->TFI3 = pTxBuf->Frame & 0xC00F0000;
LPC_CAN1->TID3 = pTxBuf->MsgID;
LPC_CAN1->TDA3 = pTxBuf->DataA;
LPC_CAN1->TDB3 = pTxBuf->DataB;
LPC_CAN1->CMR = 0x81;
return ( TRUE );
}
return ( FALSE ); // Check why???
Can you see my picture of sending function? I do not check GSR . But i check the TCS1 TCS2 TCS3 in SR register .I think it has same function with the bit TCS in GSR register.I start the sending of pocket using CMR=0x21,and then i judge whther finish the sending using statement "while (TCS1==0);".when i check TCS1 in SR register, the program will run to death.do you think my judgement has errors?
Please try the S/W example from NXP website under:
To see if you can get a packet loss error or not first. I don't recall there are any known issues on CAN controller and the same CAN IP has been used on many LPC family MCUs.