Flex_CAN Receive issue

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

Flex_CAN Receive issue

2,992 次查看
vardhan
Contributor I

In S32k144 Evolution board I import Flex CAN project. Transmit functions working properly but Receive functions i didn't get Receive data by using MICROCHIP CAN BUS Analyzer.

As of my observation this Flag (CAN0->FLAG1) is not setting in Receiver function. Please help me to  resolve the issue

Below is my working flow 

In main(){

for (;;)
{
/* Loop: if a msg is received, transmit a msg */
if ((CAN0->IFLAG1 >> 4) & 1) { /* If CAN 0 MB 4 flag is set (received msg), read MB4 */
FLEXCAN0_receive_msg (); /* Read message */
rx_msg_count++; /* Increment receive msg counter */

if (rx_msg_count == 1000) { /* If 1000 messages have been received, */
PTD->PTOR |= 1<<16; /* toggle output port D16 (Green LED) */
rx_msg_count = 0; /* and reset message counter */
}

}

FLEXCAN0_transmit_msg (); /* Transmit message using MB0 */
}
}

void FLEXCAN0_receive_msg(void)
{
/*! Receive msg from ID 0x556 using msg buffer 4
* =============================================
*/
uint8_t j;
uint32_t dummy;

RxCODE = (CAN0->RAMn[ 4*MSG_BUF_SIZE + 0] & 0x07000000) >> 24; /* Read CODE field */
RxID = (CAN0->RAMn[ 4*MSG_BUF_SIZE + 1] & CAN_WMBn_ID_ID_MASK) >> CAN_WMBn_ID_ID_SHIFT; /* Read ID */
RxLENGTH = (CAN0->RAMn[ 4*MSG_BUF_SIZE + 0] & CAN_WMBn_CS_DLC_MASK) >> CAN_WMBn_CS_DLC_SHIFT; /* Read Message Length */

for (j=0; j<2; j++)
{ /* Read two words of data (8 bytes) */
RxDATA[j] = CAN0->RAMn[ 4*MSG_BUF_SIZE + 2 + j];
}
RxTIMESTAMP = (CAN0->RAMn[ 0*MSG_BUF_SIZE + 0] & 0x000FFFF);
dummy = CAN0->TIMER; /* Read TIMER to unlock message buffers */
CAN0->IFLAG1 = 0x00000010; /* Clear CAN 0 MB 4 flag without clearing others*/
}

 

0 项奖励
回复
3 回复数

2,979 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

so you are using S32K144_Project_FlexCan example. You are able to send message (std ID 0x555), this is visible on CAN bus analyzer. This example is preparing MB4 to receive message with std ID 0x511. Is this message send from CAN bus analyzer? if yes, is the message ACKed, or do you see any error detected on both sides?

BR, Petr

0 项奖励
回复

2,956 次查看
vardhan
Contributor I

Hi PeteS,

Thank you for support.

I follow the below  procedure & I got Rx data but, in that I am getting garbage values .I am attaching Transmit &receive data screenshots for your reference. Please help me to sort out this problem. 

0 项奖励
回复

2,936 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

looks RxDATA[0] and RxDATA[1] have correct values, you read 32bit word and

RxDATA[0] = 16909060 = 0x1020304
RxDATA[1] = 84281096 = 0x5060708

thus byte values correspond to one transmitted by CAN tool.

BR, Petr

0 项奖励
回复