My project referred to the routine of the website.(Example_MPC5748G_FlexCAN_FD_TX_RX_test_S32DS_21 )
When I use this exmple provided by the website to send data, flexcan has access to the data I send???why I can get the data that I send.
/* enable the FlexCAN module, reset and freeze */
CAN_0.MCR.R = (0
| FLEXCAN_MCR_FRZ /* enabled to enter Freeze mode */
| FLEXCAN_MCR_HALT /* enter freeze mode if FRZ bit is set */
//| FLEXCAN_MCR_SOFTRST /* soft reset */
//| FLEXCAN_MCR_SRXDIS /* self reception enabled */
| FLEXCAN_MCR_BCC /* individual Rx masking and queue */
| 0x00000003);
/*******************************************************************************
Function Name : TransmitMsgFD
Engineer : Petr Stancik
Date : Jun-22-2021
Parameters : mb ... mb number used
ext ... 0-standard ID, 1-extended ID
ID ... ID to be sent
length ... number of bytes to be sent
Modifies : NONE
Returns : NONE
Notes : Transmit message once using selected MB
Issues : NONE
*******************************************************************************/
void TransmitMsgFD(uint32_t mb, uint8_t ext, uint32_t ID, uint8_t length)
{
/* Assumption: Message buffer CODE is INACTIVE */
uint8_t i,dlc,z=0;
uint32_t *pTxMB = GetMBAddr(mb);
uint32_t txID = (ext==0) ? ID<<18 : ID;
/*calculate dlc value from no. bytes*/
if(length < 0x09)
{
dlc = length;
}else if(length < 0x0D){
dlc = 0x9;
}else if(length < 0x11){
dlc = 0xA;
}else if(length < 0x15){
dlc = 0xB;
}else if(length < 0x19){
dlc = 0xC;
}else if(length < 0x21){
dlc = 0xD;
}else if(length < 0x31){
dlc = 0xE;
}else{
dlc = 0xF;
}
*(pTxMB + 1) = txID; // write ID
for (i=0; i<length/4; i++,z+=4) {
*(pTxMB + 2 + i) = z<<24 | (z+1)<<16 | (z+2)<< 8 | z+3; /* Data to be transmitted */
}
*pTxMB = (0 // Tx Buffer 0 T0 word
| 1<<31 // extended Data Length
| 1<<30 // bit rate switch
| 0xC<<24 // code = 0xC, TX once
| 1<<22 // SRR = 1
| ext<<21 // IDE
| 0<<20 // RTR = 0
| dlc<<16); // DLC
while (!(CAN_0.IFLAG1.R & 1<<mb)) {}; /* Wait for CAN 0 MB 0 flag */
CAN_0.IFLAG1.R = 1<<mb; // clear MB flag
}
/*******************************************************************************
Function Name : ReceiveMsgFD
Engineer : Petr Stancik
Date : Jun-22-2021
Parameters : mb ... MB number used
Modifies : NONE
Returns : NONE
Notes : check if given MB have new message, if yes, read it
Issues : NONE
*******************************************************************************/
void ReceiveMsgFD(uint32_t mb)
{
uint8_t j;
uint32_t dummy,dlc;
uint32_t *pRxMB = GetMBAddr(mb);
uint8_t *pRxMBdata = (uint8_t *)(&pRxMB[2]);
if(CAN_0.IFLAG1.R & 1<<mb) // if CAN 0 MB flag set
{
/* Read CODE, ID, LENGTH, DATA, TIMESTAMP*/
dummy = *pRxMB;
RxCODE = (dummy>>24) & 0xF;
RxID = *(pRxMB+1);
dlc = (dummy>>16) & 0xF;
/*calculate no. bytes from dlc value*/
if(dlc < 0x09)
{
RxLENGTH = dlc;
}else if(dlc == 0x9){
RxLENGTH = 12;
}else if(dlc == 0xA){
RxLENGTH = 16;
}else if(dlc == 0xB){
RxLENGTH = 20;
}else if(dlc == 0xC){
RxLENGTH = 24;
}else if(dlc == 0xD){
RxLENGTH = 32;
}else if(dlc == 0xE){
RxLENGTH = 48;
}else{
RxLENGTH = 64;
}
for (j=0; j<RxLENGTH; j++) {
RxDATA[j] = *pRxMBdata++ ;
}
RxTIMESTAMP = dummy & 0xFF;;
dummy = CAN_0.TIMER.R; // Read TIMER to unlock message buffers
CAN_0.IFLAG1.R = 1<<mb; // clear MB flag
}
}