How to Transmit CAN messages in MB1 and MB2

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

How to Transmit CAN messages in MB1 and MB2

1,067 Views
b_mansoor
Contributor I

Hi,

For transmitting messages in MB0 we have,

CAN0->RAMn[ 0*MSG_BUF_SIZE + 0] = 0x0C400000 | 8 <<CAN_WMBn_CS_DLC_SHIFT;

What all are the changes i supposed to make it to send messages in MB1 and MB2 instead of MB0?

Tags (1)
0 Kudos
3 Replies

991 Views
kef2
Senior Contributor IV

CAN0->RAMn[ MB_NO * MSG_BUF_SIZE + 0] = 0x0C400000 | 8 <<CAN_WMBn_CS_DLC_SHIFT;

MB_NO=0,1,2,..

0 Kudos

991 Views
b_mansoor
Contributor I

Hi,

void CAN_transmit_Msg(CAN_Type * CANchannel, uint32_t *transmitDATA, uint32_t transmitID) {  
       CANchannel->IFLAG1 = 0x00000001;       /* Clear CAN 0 MB 1 flag without clearing others*/ 
       // Assign the MsgID to the Transmit data
       CANchannel->RAMn[ 0*MSG_BUF_SIZE + 1] = (transmitID) << 18; // Assign the Transmit Message ID 
       // Prepare Data Word 0 and Data Word 1, by saving in required MBuff, which needs to be transmitted to Bus
       CANchannel->RAMn[ 0*MSG_BUF_SIZE + 2] = transmitDATA[0]; // MB0 word 2: data word 0
       CANchannel->RAMn[ 0*MSG_BUF_SIZE + 3] = transmitDATA[1]; // MB0 word 3: data word 1 
         //Set the parameters of the CAN Protocol, and activate channel to transmit message on Bus
       CANchannel->RAMn[ 0*MSG_BUF_SIZE + 0] = 0x0C400000 | 8 <<CAN_WMBn_CS_DLC_SHIFT;// MB0 word 0:                                                                                                                      // EDL,BRS,ESI=0: CANFD not used
                                                                                      // CODE=0xC: Activate msg buf to transmit
                                                                                      // IDE=0: Standard ID
                                                                                      // SRR=1 Tx frame (not req'd for std ID)
                                                                                     // RTR = 0: data, not remote tx request frame
                                                                                     // DLC = 8 bytes
}
This is the function written for transmitting in MB0. When i changed it to MB1 and MB2 by replacing 0 by 1 and 2. its not working. Which all places i should change ? 
0 Kudos

991 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

- be sure written MBs are enabled, check MCR[MAXMB]

- if Abort is enabled (MCR[AEN] asserted) then you should clear MB flag in IFLAG1 to be able to update MB

- if the CAN FD is enabled and different payload is used, MSG_BUF_SIZE should be set accordingly. For default payload of 8bytes  MSG_BUF_SIZE = 4

Anyway you can check the MB memory if it is written.

BR, Petr

0 Kudos