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

TMS570LS3137: CAN发送数据时,如何更新DLC

Part Number:TMS570LS3137

在使用canTransmit函数时,每次发送的数据长度不固定,1~8,如何将长度信息更新的DLC并发送

Ben Qin:

参考下这个帖子:

e2echina.ti.com/…/tms570lc4357-how-to-change-dlc-when-sending

,

x x:

我已经设置  node->IF1CMD = 0x97U;,而且已经更新node->IF1MCTL &= 0xFFFFFF00;node->IF1MCTL |= dlc;从变量监视穿孔也看到DLC被改变,但是CAN接收到,长度依旧为8,

uint32 canTransmitWithDLC(canBASE_t *node, uint32 messageBox, const uint8 * data,const uint8 dlc)
{uint32 i;uint32 success= 0U;uint32 regIndex = (messageBox - 1U) >> 5U;uint32 bitIndex = 1U << ((messageBox - 1U) & 0x1FU);/* USER CODE BEGIN (7) */
/* 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*/node->IF1CMD = 0x97U;/** - Copy TX data into IF1 */for (i = 0U; i < 8U; i++){
#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" *//*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */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" *//*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */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;node->IF1MCTL &= 0xFFFFFF00;node->IF1MCTL |= dlc;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;
}

 ,图中为监视状态,看起来是没有生效

,

x x:

更正一下,调整代码位置,则发送正确

/*如果代码这样写,发送的首帧长度依然为8;*/
node->IF1NO = (uint8) messageBox;node->IF1MCTL &= 0xFFFFFF00;
node->IF1MCTL |= dlc;/*代码这样写,发送数据的DLC则更新为输入参数dlc;*/
node->IF1MCTL &= 0xFFFFFF00;
node->IF1MCTL |= dlc;node->IF1NO = (uint8) messageBox;

,

Ben Qin:

好的,感谢分享,问题解决就好

赞(0)
未经允许不得转载:TI中文支持网 » TMS570LS3137: CAN发送数据时,如何更新DLC
分享到: 更多 (0)