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 */
}
Hi,
I am not sure if I understand your question. Do you want to use the same Message Buffer for sending and receiving message or you want to use MB0 for sending and MB4 for receiving message?
In the code you posted I see that you wait for CAN_0.IFRL.B.BUF04I, but I do not see the code which set MB4 for receiving message.
So could you please clarify your issue?
Regards,
Martin
Actually, I want to know the difference between MB0 and MBx.Because there is no introduction about in the Datasheet.
And I want to know under what circumstances can use and how use MB0 or MBx (MB4, for example), I made a test:MB0 and MB4 can receive the same data of a same CAN channel .thank you.
Hi,
there is no difference between MB0 and MB4. Each CAN module on MPC5606B has 64 MBs (message buffers). You can use every message buffer you want for sending and also receiving messages. There is not any prescription about using message buffers. If you want to test one module, I only recommend you to use different MB for sending a receiving data as you did.
If you have any other question, please feel free to write me back.
Regards,
Martin