Hello,
I am having some issues with receiving messages via CAN. I have configured 3 mailboxes where mailbox 0 and 1 are used for transmitting data and mailbox 2 is used for receiving data. I have had no issue with transmitting messages.
To help debug the problem, I have reduced the code to solely receive messages and I have disabled interrupts.
Can anyone see an issue with the code? Thanks in advance.
Configuration: (bit timing not included to reduce number of lines in post)
struct ECAN_REGS ECanaShadow; // Create a shadow register structure for the CAN control registers. This is needed, since only 32-bit access is allowed to these registers.
EALLOW; // EALLOW enables access to protected bits
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 3;
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 3;
SysCtrlRegs.PCLKCR0.bit.ECANAENCLK = 1; //Enable CAN A clock
ECanaShadow.CANRIOC.all = ECanaRegs.CANRIOC.all;
ECanaShadow.CANRIOC.bit.RXFUNC = 1; //CAN receive functions
ECanaRegs.CANRIOC.all = ECanaShadow.CANRIOC.all;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.SCB = 0; //Standard CAN controller
ECanaShadow.CANMC.bit.DBO = 1; //Data byte order
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
//initialize registers to zero
ECanaMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanaRegs.CANTA.all = 0xFFFFFFFF; /* Clear all TAn bits TA = transmission acknowledge*/
ECanaRegs.CANRMP.all = 0xFFFFFFFF; /* Clear all RMPn bits RMP = receive message pending*/
ECanaRegs.CANGIF0.all = 0xFFFFFFFF; /* Clear all interrupt flag bits */
ECanaRegs.CANGIF1.all = 0xFFFFFFFF;
ECanaShadow.CANGAM.all = ECanaRegs.CANGAM.all;
ECanaShadow.CANGAM.bit.AMI = 0;
ECanaRegs.CANGAM.all = ECanaShadow.CANGAM.all;
ECanaRegs.CANME.all = 0; // Disable all Mailboxes, Required before writing the MSGIDs
EDIS;
//Mailbox 2:
ECanaMboxes.MBOX2.MSGID.bit.AAM = 0; //No automatic replies to remote requests (AAM = auto answer mode)
ECanaMboxes.MBOX2.MSGID.bit.AME = 0; //No acceptance mask is used, all identifier bits must match to receive the message
ECanaMboxes.MBOX2.MSGID.bit.IDE = 0; //No extended identifier (IDE = identifier extension bit)
ECanaMboxes.MBOX2.MSGID.bit.STDMSGID = 0x100; //Message identifier
//Configure Mailbox(s) as either transmit or receive
ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;
ECanaShadow.CANMD.bit.MD2 = 1; //receive
ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;
//Enable Mailbox(s)
ECanaShadow.CANME.all = ECanaRegs.CANME.all;
ECanaShadow.CANME.bit.ME2 = 1;
ECanaRegs.CANME.all = ECanaShadow.CANME.all;
//Write to DLC field
ECanaMboxes.MBOX2.MSGCTRL.bit.DLC = 1;
ECanaRegs.CANMIM.all = 0x00000000;
Code in main.c:
for(;;){
if (ECanaRegs.CANRMP.bit.RMP2 = 1){
ECanaRegs.CANRMP.bit.RMP2 = 1; //Clear RMP
volatile struct MBOX *Mailbox;
Mailbox = &ECanaMboxes.MBOX2;
receive_l = Mailbox->MDL.all;
receive_h = Mailbox->MDH.all;
}
}