This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
您好!
为什么为 CANBUS 生成的卤素码硬编码要发送8个字节? 是否可以通过某种方法发送多达8个字节、即每个 CAN 消息2个数据字节? 我在这里包含了我一直在看的函数:
uint32 canTransmit(canBASE_t *node, uint32 messageBox, const uint8 * data) { 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 = 0x87U; /** - 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; 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; }
此致、
阿利斯特
尊敬的 Alister:
[quote userid="568126" url="~/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1243382/tms570ls0432-canbus-tx-fixed-to-8-byte-packets 为什么 CANBUS 生成的卤素代码硬编码要发送8个字节? 是否可以通过某种方法发送多达8个字节、即每个 CAN 消息2个数据字节? 我在这里包含了我一直在看的函数:是的、它使用8个字节进行了硬编码、但您可以在 DLC (数据长度代码)中提及您的有效数据字节。
如果数据长度码小于8、报文对象剩余的字节可能会被未定义的值覆盖。
--
谢谢。此致、
Jagadish。
Jagadish、您好!
感谢您的回答、如何在仍然使用 HAL 实施的情况下、按每个数据包设置 DLC 寄存器?
此致、
阿利斯特
尊敬的 Alister:
感谢您回复我,如何在仍使用 HAL 实施的情况下以每个数据包为基础设置 DLC 寄存器?
HAL 不提供 API 来更新 DLC。 但您可以编写一个。
--
谢谢。此致、
Jagadish。