MSCAN can't transmit

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

MSCAN can't transmit

跳至解决方案
1,368 次查看
terrybogard
Contributor II

I test MSCAN in loopback mode, it wors well. but when loop mode disabled, it can't transmit the frame. Pls give me some advice about code below. Is there any code demo about MSCAN not use loop mode in MC56F82748?Thx.

Sending data frame without interrupt service (polling)

The following example demonstrates sending a data frame with standard ID and extended ID.

OnFreeTxBuffer event is called when a frame is successfully transmitted and returns buffer index (in this case 0), which was send.

Required component setup :

 

Content of ProcessorExpert.c:

volatile bool DataFrameTxFlg;LDD_TDeviceData *MyCANPtr;LDD_TError Error;LDD_CAN_TFrame Frame;uint8_t OutData[4] = {0x00U, 0x01U, 0x02U, 0x03U};                /* Initialization of output data buffer */ void main(void){  . . .  MyCANPtr = CAN2_Init(NULL);                                     /* Initialization of CAN2 component */      Frame.MessageID = 0x123U;                                       /* Set Tx ID value - standard */    Frame.FrameType = LDD_CAN_DATA_FRAME;                           /* Specyfying type of Tx frame - Data frame */  Frame.Length = sizeof(OutData);                                 /* Set number of bytes in data frame - 4B */  Frame.Data = OutData;                                           /* Set pointer to OutData buffer */  DataFrameTxFlg = FALSE;                                         /* Initialization of DataFrameTxFlg */  Error = CAN2_SendFrame(MyCANPtr, 0U, &Frame);                   /* Sends the data frame over buffer 0 */   while (!DataFrameTxFlg) {                                       /* Wait until data frame is transmitted */    CAN2_Main(MyCANPtr);    }  . . .  Frame.MessageID = (0x123456U | LDD_CAN_MESSAGE_ID_EXT);         /* Set Tx ID value - extended */    Frame.FrameType = LDD_CAN_DATA_FRAME;                           /* Specyfying type of Tx frame - Data frame */  Frame.Length = sizeof(OutData);                                 /* Set number of bytes in data frame - 4B */  Frame.Data = OutData;                                           /* Set pointer to OutData buffer */  DataFrameTxFlg = FALSE;                                         /* Clear DataFrameTxFlg */  Error = CAN2_SendFrame(MyCANPtr, 0U, &Frame);                   /* Sends the data frame over buffer 0 */   while (!DataFrameTxFlg) {                                       /* Wait until data frame is transmitted */    CAN2_Main(MyCANPtr);    }  . . .        for(;;) {}}

Content of Event.c:

extern volatile bool DataFrameTxFlg;void CAN2_OnFreeTxBuffer(LDD_TUserData *UserDataPtr, LDD_CAN_TMBIndex BufferIdx){  DataFrameTxFlg = TRUE; /* Set DataFrameTxFlg flag */}

0 项奖励
回复
1 解答
1,339 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Because the CAN transmit node requires acknowledge signal from the CAN receiver, so you have to connect two CAN module via transceiver when you have a test to transfer can message.

BR

XiangJun Rong

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,366 次查看
terrybogard
Contributor II

volatile bool DataFrameTxFlg;
LDD_TDeviceData *MyCANPtr;
LDD_TError Error;
LDD_CAN_TFrame Frame;
uint8_t OutData[4] = {0x04U, 0x08U, 0x0cU, 0x0fU}; /* Initialization of output data buffer */

void main(void)
{

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/

MyCANPtr = CAN1_Init(NULL); /* Initialization of CAN1 component */

Frame.MessageID = 0x123U; /* Set Tx ID value - standard */
Frame.FrameType = LDD_CAN_DATA_FRAME; /* Specyfying type of Tx frame - Data frame */
Frame.Length = sizeof(OutData); /* Set number of bytes in data frame - 4B */
Frame.Data = OutData; /* Set pointer to OutData buffer */
DataFrameTxFlg = FALSE; /* Initialization of DataFrameTxFlg */
Error = CAN1_SendFrame(MyCANPtr, 0U, &Frame); /* Sends the data frame over buffer 0 */
while (!DataFrameTxFlg) { /* Wait until data frame is transmitted */
CAN1_Main(MyCANPtr);
}

Frame.MessageID = (0x123456U | LDD_CAN_MESSAGE_ID_EXT); /* Set Tx ID value - extended */
Frame.FrameType = LDD_CAN_DATA_FRAME; /* Specyfying type of Tx frame - Data frame */
Frame.Length = sizeof(OutData); /* Set number of bytes in data frame - 4B */
Frame.Data = OutData; /* Set pointer to OutData buffer */
DataFrameTxFlg = FALSE; /* Clear DataFrameTxFlg */
Error = CAN1_SendFrame(MyCANPtr, 0U, &Frame); /* Sends the data frame over buffer 0 */
while (!DataFrameTxFlg) { /* Wait until data frame is transmitted */
CAN1_Main(MyCANPtr);
}

for(;;) {}
}

Content of Event.c:

extern volatile bool DataFrameTxFlg;

void CAN2_OnFreeTxBuffer(LDD_TUserData *UserDataPtr, LDD_CAN_TMBIndex BufferIdx)

{  DataFrameTxFlg = TRUE; /* Set DataFrameTxFlg flag */}

 

0 项奖励
回复
1,353 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I have not see the code which configured the mcan pin assignment.

Pls try to use the code:

SIM_PCE1|=0x01; //enable mcan module gated clock

SIM_PCE0|=1<<4; //enable GPIOC gated clock

GPIOC_PER|=3<<11;

 //GPIOC11 CANTX SCL0 TXD1
 // GPIOC12 CANRX SDA0 RXD1

SIM_GPSCH&=0xFC3F;

xiangjun_rong_0-1622440233947.png

 

Pls have a try

BR

XiangJun Rong

0 项奖励
回复
1,345 次查看
terrybogard
Contributor II

thx for Xiangjun's answer, i am sure i have done the pin assignment by processor expert as below.

terrybogard_0-1622518341672.png

terrybogard_1-1622519406388.png

terrybogard_2-1622519464439.png

 

when i debug, in CANTFLG register, TXE0 = 0 all the time: mean Transmit buffer full (not sent, scheduled).

 

 

0 项奖励
回复
1,340 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Because the CAN transmit node requires acknowledge signal from the CAN receiver, so you have to connect two CAN module via transceiver when you have a test to transfer can message.

BR

XiangJun Rong

0 项奖励
回复