In my program i want to send multiple messages though 1 Mailbox, But i can't seem to change the message DLC, i can change it in the CAN init, where HalCoGen generated the messageboxes and writes the DLC in the IF1MCTL register. But i need to change it runtime when i send multiple messages.
I want to change the DLC inside the canTransmit function generated by Halcogen.
I saw another post about this, here they suggested the TRM chapters: "Reconfiguration of Message Objects for the Transmission of Frames"and "Changing a Transmit Object" but that doesn't seem to help me. i don't quite get the sentence: "The Data Length Code of a message object must be defined to the same value as in the corresponding objects with the same identifier at other nodes" either in Table 27-2. Message Object Field Descriptions the part about "DLC[3:0]"
am i missing something when i try this modified "canTransmit()" function:
uint32 canTransmit(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);
/** - Check for pending message:
* - pending message, return 0
* - no pending message, start new transmission
*/
if ((node->TXRQx[regIndex] & bitIndex) != 0U)
{
success = 0U;
}
else
{
/******* MY ADDED CODE *****/////////
node->IF1CMD = 0x90U;
/* set message length */
node->IF1MCTL = (uint32)((uint32)(node->IF1MCTL & 0xFFFFFFF0) | ((uint32)0x0000000FU & (uint32)dlc));
/******* MY ADDED CODE END*****/////////
/** - Wait until IF1 is ready for use */
while ((node->IF1STAT & 0x80U) ==0x80U)
{
node->IF1CMD = 0x87U;
/** - Copy TX data into IF1 */
for (i = 0U; i < dlc; i++)
{
#if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1))
node->IF1DATx[i] = *data;
data++;
#else
node->IF1DATx[s_canByteOrder[i]] = *data;
data++;
#endif
}
/** - Copy TX data into message box */
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.
*/
return success;
}
What am i doing wrong? this just produces messages with a length of 8 (DLC has been set to 8 in canInit)