TI中文支持网
TI专业的中文技术问题搜集分享网站

TMS570LC4357: How to change DLC when sending,

Part Number:TMS570LC4357

How to change DLC when sending,如何发送可变字节长度的报文

I modified the DLC value in the cantransmit function, but it still failed.  我在canTransmit函数中修改DLC的值但还是不行

有没有参考的流程,手册我已经看了很多次了还是不太明白。

Green Deng:

你好,问题已经收到,我需要向其他工程师咨询一下之后再回复你,还请耐心等待。

,

NA GAO:

谢谢

,

NA GAO:

我也想知道如何读取接收到报文的DLC值

,

Green Deng:

可以在将数据从 IFx 寄存器传输到 DCAN 消息 RAM 或邮箱之前更新 DLC。 HAL 代码没有更新 DLC 的 API,但可以编写自己的 API。 例如:

void canUpdateDLC(canBASE_t *node, uint32 messageBox, uint8 msgBoxDLC)
{/** - Wait until IF2 is ready for use */while ((node->IF2STAT & 0x80U) ==0x80U){} /* Wait */node->IF2CMD = 0x90U;node->IF2MCTL &= ~(uint32)(0xFU);node->IF2MCTL |= (uint32)(msgBoxDLC & 0xFU);node->IF2NO = (uint8) messageBox;/** - Wait until data are copied into IF2 */while ((node->IF2STAT & 0x80U) ==0x80U){} /* Wait */}

消息对象的DLC必须定义为与其他节点具有相同标识符的相应对象中的值相同。

,

NA GAO:

//可以把这个程序添加在Transmit函数里面吗?

uint32 canTransmit(canBASE_t *node, uint32 messageBox, const uint8 * data,uint8 msgBoxDLC){ uint32 i; uint32 success = 0U; uint32 regIndex = (messageBox – 1U) >> 5U; uint32 bitIndex = 1U << ((messageBox – 1U) & 0x1FU);

/* USER CODE BEGIN (7) */     //添加在这里

/** – Wait until IF2 is ready for use */ while ((node->IF2STAT & 0x80U) ==0x80U) { } /* Wait */

node->IF2CMD = 0x90U;

node->IF2MCTL &= ~(uint32)(0xFU);

node->IF2MCTL |= (uint32)(msgBoxDLC & 0xFU);

node->IF2NO = (uint8) messageBox;

/** – Wait until data are copied into IF2 */ while ((node->IF2STAT & 0x80U) ==0x80U) { } /* Wait */

/* USER CODE END */

/** – Check for pending message: * – pending message, return 0 * – no pending message, start new transmission */

if ((node->TXRQx[regIndex] & bitIndex) != 0U) { success = 0U; }

else { /** – Wait until IF1 is ready for use */ /*SAFETYMCUSW 28 D MR:NA <APPROVED> "Potentially infinite loop found – Hardware Status check for execution sequence" */ while ((node->IF1STAT & 0x80U) ==0x80U) { } /* Wait */

/** – Configure IF1 for * – Message direction – Write * – Data Update * – Start Transmission */ /*SAFETYMCUSW 28 D MR:NA <APPROVED> "Potentially infinite loop found – Hardware Status check for execution sequence" */

/** – Copy TX data into IF1 */ for (i = 0U; i < msgBoxDLC; i++)                 //这里循环条件改成DLC {#if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1)) /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */ node->IF1DATx[i] = *data; /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */ data++;#else /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */ node->IF1DATx[s_canByteOrder[i]] = *data; /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */ data++;#endif }

/** – Copy TX data into message box */ /*SAFETYMCUSW 93 S MR: 6.1,6.2,10.1,10.2,10.3,10.4 <APPROVED> "LDRA Tool issue" */ node->IF1NO = (uint8) messageBox;

success = 1U; } /** @note The function canInit has to be called before this function can be used.\n * The user is responsible to initialize the message box. */

/* USER CODE BEGIN (8) *//* USER CODE END */

return success;}

,

NA GAO:

接收到的报文怎么读取DLC

,

Green Deng:

收到,我会尽快帮你反馈。

,

NA GAO:

使用canUpdateID函数更新ID后,发送的数据帧变成远程帧了,我不知道原因

,

Green Deng:

这是新问题?新问题的话还请麻烦新开一个帖子,都放一起会乱

,

NA GAO:

谢谢

,

Green Deng:

客气了,之前的问题应该会在明天回复你。

,

Green Deng:

1、是的,可以将新 ID、DLC 添加到传输 API。

NA GAO 说:/** – Copy TX data into IF1 */ for (i = 0U; i < msgBoxDLC; i++)                 //这里循环条件改成DLC

这里不必将 8 更改为 msgBoxDLC。 无论 DLC 有多小,八字节数据都会从 IFx 数据寄存器(A 和 B)传输到消息 RAM。

2、DLC 是消息控制寄存器的一部分。 您需要设置 CMD 寄存器的 CONTROL 位和 CMD 寄存器的 CLEAR W/R 位,以便将 DLC 从 Message RAM 传输到 Fx 寄存器:

canGetData(0 API include this portion:

/** – Configure IF2 for* – Message direction – Read* – Data Read* – Clears NewDat bit in the message object.*/node->IF2CMD = 0x17U;/** – Copy data into IF2 *//*SAFETYMCUSW 93 S MR: 6.1,6.2,10.1,10.2,10.3,10.4 <APPROVED> "LDRA Tool issue" */node->IF2NO = (uint8) messageBox;

/** – Wait until data are copied into IF2 *//*SAFETYMCUSW 28 D MR:NA <APPROVED> "Potentially infinite loop found – Hardware Status check for execution sequence" */while ((node->IF2STAT & 0x80U) ==0x80U){} /* Wait */

/** – Get number of received bytes */size = node->IF2MCTL & 0xFU;if(size > 0x8U){size = 0x8U;}/** – Copy RX data into destination buffer */

赞(0)
未经允许不得转载:TI中文支持网 » TMS570LC4357: How to change DLC when sending,
分享到: 更多 (0)