ticket

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
2,548 Views
dreamtea81125
Contributor II

I have some problem about CAN_TX in MPC5746R.

there are my code and i can't get the right date in Oscilloscope.

I didn't know what's wrong. Can someone give me a hand?   thank you very much.

 

int main(void)

{
/* Write your local variable definition here */

#define TX_MAILBOX (1UL)
#define TX_MSG_ID1 (1UL)
#define TX_MSG_ID2 (2UL)
#define RX_MAILBOX (0UL)
#define RX_MSG_ID1 (2UL)
#define RX_MSG_ID2 (1UL)

uint8_t TX_date[1];
uint8_t TX_date1[1];


/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/

/* Write your code here */


CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
                            g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);

PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);

FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
FLEXCAN_DRV_Init(INST_CANCOM2, &canCom2_State, &canCom2_InitConfig0);


flexcan_data_info_t dataInfo =
{
.data_length = 1UL,
.msg_id_type = FLEXCAN_MSG_ID_STD
};


/* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &dataInfo, RX_MSG_ID1);
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM2, RX_MAILBOX, &dataInfo, RX_MSG_ID2);


while(1)
{

/* Configure TX message buffer with index TX_MSG_ID1 and TX_MAILBOX*/
FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1, TX_MAILBOX, &dataInfo, TX_MSG_ID1);
FLEXCAN_DRV_ConfigTxMb(INST_CANCOM2, TX_MAILBOX, &dataInfo, TX_MSG_ID2);

TX_date[0] = 0x11U;

/* Execute send non-blocking */
FLEXCAN_DRV_Send(INST_CANCOM1, TX_MAILBOX, &dataInfo, TX_MSG_ID1, (uint8_t*)TX_date);

// FLEXCAN_DRV_Send(INST_CANCOM2, TX_MAILBOX, &dataInfo, TX_MSG_ID2, &TX_date1);

// FLEXCAN_DRV_SendBlocking(INST_CANCOM1, TX_MAILBOX, &dataInfo, TX_MSG_ID2, &TX_date, 200);

}

pastedImage_1.png

1 Solution
1,047 Views
PetrS
NXP TechSupport
NXP TechSupport

you can use below code to receive a message

flexcan_data_info_t dataInfo =
{
.data_length = 1U,
.msg_id_type = FLEXCAN_MSG_ID_STD
};

/* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &dataInfo, RX_MSG_ID1);

while(1)
{
   /* Define receive buffer */
   flexcan_msgbuff_t recvBuff;
   
   /* Start receiving data in RX_MAILBOX. */
   FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff);

   /* Wait until the previous FlexCAN receive is completed */
   while((FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) == STATUS_BUSY);

   /* Check the received message ID and payload */   

   ....

}

Also you set bitrate to 10kbps in flexcan components. This is quite low one. How this can work as EVB is using TJA1041 which has minimum possible bitrate of 40kbps (due to TXD dominant clamping detection)?  

Moreover the CAN bit setting of the PC tool is weird, 10K is selected and it shows 83.333 kbps.

So do you have really same bitrate set on MCU and PC side? The same sample point is also recommended.

BR, Petr

View solution in original post

4 Replies
1,047 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

do you use EVB on your side? Seems you are using 2 FlexCAN modules, do you want to do communication between those 2? If yes, how those modules are connected together?

Regarding a code; it is not needed to call FLEXCAN_DRV_ConfigTxMb() each time you want to send message. You have placed this in main's while loop. Also calling non-blocking FLEXCAN_DRV_Send() periodically is not correct. You have to be sure previous transmission is finished. FLEXCAN_DRV_GetTransferStatus() can be used for this.

BR, Petr

1,047 Views
dreamtea81125
Contributor II

This is my setting in can converter. Thank you.

pastedImage_1.pngpastedImage_2.png

0 Kudos
1,048 Views
PetrS
NXP TechSupport
NXP TechSupport

you can use below code to receive a message

flexcan_data_info_t dataInfo =
{
.data_length = 1U,
.msg_id_type = FLEXCAN_MSG_ID_STD
};

/* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &dataInfo, RX_MSG_ID1);

while(1)
{
   /* Define receive buffer */
   flexcan_msgbuff_t recvBuff;
   
   /* Start receiving data in RX_MAILBOX. */
   FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff);

   /* Wait until the previous FlexCAN receive is completed */
   while((FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) == STATUS_BUSY);

   /* Check the received message ID and payload */   

   ....

}

Also you set bitrate to 10kbps in flexcan components. This is quite low one. How this can work as EVB is using TJA1041 which has minimum possible bitrate of 40kbps (due to TXD dominant clamping detection)?  

Moreover the CAN bit setting of the PC tool is weird, 10K is selected and it shows 83.333 kbps.

So do you have really same bitrate set on MCU and PC side? The same sample point is also recommended.

BR, Petr

1,047 Views
dreamtea81125
Contributor II

Hi, Petr Stancik

Thank you for your respond.

Yes. I use EVB on my side.

I can send the data by EVB and get the data by CAN converter in computer new.

but it seem have some problems. I can't receive the data by EVB.

I don't know what's wrong. Can you give some advice.

There are my code . Any suggestion is helpful.

int main(void)
{
/* Write your local variable definition here */

#define TX_MAILBOX (1UL)
#define TX_MSG_ID1 (1UL)
#define TX_MSG_ID2 (2UL)
#define RX_MAILBOX (0UL)
#define RX_MSG_ID1 (2UL)
#define RX_MSG_ID2 (1UL)

uint8_t TX_date = 0x52U;

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/

/* Write your code here */


CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);

PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);

FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
FLEXCAN_DRV_Init(INST_CANCOM2, &canCom2_State, &canCom2_InitConfig0);


flexcan_data_info_t dataInfo =
{
.data_length = 1U,
.msg_id_type = FLEXCAN_MSG_ID_STD
};


/* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &dataInfo, RX_MSG_ID1);
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM2, RX_MAILBOX, &dataInfo, RX_MSG_ID2);


/* Configure TX message buffer with index TX_MSG_ID1 and TX_MAILBOX*/
FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1, TX_MAILBOX, &dataInfo, TX_MSG_ID1);
FLEXCAN_DRV_ConfigTxMb(INST_CANCOM2, TX_MAILBOX, &dataInfo, TX_MSG_ID2);

PINS_DRV_SetPins(PTA,3U);
PINS_DRV_GetPinsOutput(PTA);


while(1)
{


/* Execute send non-blocking */
FLEXCAN_DRV_Send(INST_CANCOM1, TX_MAILBOX, &dataInfo, 2UL, &TX_date);

// FLEXCAN_DRV_Send(INST_CANCOM2, TX_MAILBOX, &dataInfo, 1UL, &TX_date1);


/* Define receive buffer */
flexcan_msgbuff_t recvBuff;
flexcan_msgbuff_t recvBuff1;
recvBuff1.msgId=1U;
recvBuff1.dataLen=8U;

/* Start receiving data in RX_MAILBOX. */

FLEXCAN_DRV_ReceiveBlocking(INST_CANCOM2,RX_MAILBOX, &recvBuff1,200);
// FLEXCAN_DRV_Receive(INST_CANCOM2,RX_MAILBOX, &recvBuff1);
if(recvBuff1.data[0]==1)
{

PINS_DRV_WritePin(PTA,3U,1U);
}
// FLEXCAN_DRV_Receive(INST_CANCOM1,RX_MAILBOX, &recvBuff);
}

pastedImage_1.png

0 Kudos