AnsweredAssumed Answered

something puzzled about CAN BUF[ ]

Question asked by Shi Yinbiao on Oct 19, 2016
Latest reply on Oct 20, 2016 by Martin Kovar

I'm learning CAN module of MPC5606B,but there're something  bothered me:

when we initialized CAN_0,we set BUF[0] as TX inactive ,we send data with BUF[0] and can use BUF[0] recivice data, but why we use BUF[4]  also can recivice the data the same to BUF[0] reciviced.

Sample code as followed:

 

void initCAN_0 (void) {
uint8_t i;
CAN_0.MCR.R = 0x5000003F; /* Put in Freeze Mode & enable all 64 msg bufs */
CAN_0.CR.R = 0x04DB0006; /* Configure for 8MHz OSC, 100kHz bit time */
for (i=0; i<64; i++) {
CAN_0.BUF[i].CS.B.CODE = 0; /* Inactivate all message buffers */
}
CAN_0.BUF[0].CS.B.CODE = 8; /* Message Buffer 0 set to TX INACTIVE */
SIU.PCR[16].R = 0x0624; /* MPC56xxB: Config port B0 as CAN0TX, open drain */
SIU.PCR[17].R = 0x0100; /* MPC56xxB: Configure port B1 as CAN0RX */
CAN_0.MCR.R = 0x0000003F; /* Negate FlexCAN 0 halt state for 64 MB */
}
void TransmitMsg (void) {
uint8_ti;
/* Assumption: Message buffer CODE is INACTIVE */
const uint8_t TxData[] = {"Hello"}; /* Transmit string*/
CAN_0.BUF[0].CS.B.IDE = 0; /* Use standard ID length */
CAN_0.BUF[0].ID.B.STD_ID = 555; /* Transmit ID is 555 */
CAN_0.BUF[0].CS.B.RTR = 0; /* Data frame, not remote Tx request frame */
CAN_0.BUF[0].CS.B.LENGTH = sizeof(TxData) -1 ; /* # bytes to transmit w/o null */
for (i=0; i<sizeof(TxData); i++) {
CAN_0.BUF[0].DATA.B[i] = TxData[i]; /* Data to be transmitted */
}
CAN_0.BUF[0].CS.B.SRR = 1; /* Tx frame (not req'd for standard frame)*/
CAN_0.BUF[0].CS.B.CODE =0xC; /* Activate msg. buf. to transmit data frame */
}
void RecieveMsg (void) {
uint8_t j;
uint32_t dummy;
while (CAN_0.IFRL.B.BUF04I == 0) {}; /* Wait for CAN 0 MB 4 flag */
RxCODE = CAN_0.BUF[4].CS.B.CODE; /* Read CODE, ID, LENGTH, DATA, TIMESTAMP */
RxID = CAN_0.BUF[4].ID.B.STD_ID;
RxLENGTH = CAN_0.BUF[4].CS.B.LENGTH;
for (j=0; j<RxLENGTH; j++) {
RxDATA[j] = CAN_0.BUF[4].DATA.B[j];
}
RxTIMESTAMP = CAN_0.BUF[4].CS.B.TIMESTAMP;
dummy = CAN_0.TIMER.R; /* Read TIMER to unlock message buffers */
CAN_0.IFRL.R = 0x00000010; /* Clear CAN 0 MB 4 flag */
}

Outcomes