MSCAN can't transmit

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MSCAN can't transmit

Jump to solution
1,187 Views
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 Kudos
1 Solution
1,158 Views
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

View solution in original post

0 Kudos
4 Replies
1,185 Views
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 Kudos
1,172 Views
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 Kudos
1,164 Views
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 Kudos
1,159 Views
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 Kudos