Other Parts Discussed in Thread: HALCOGEN
Hi.
I am having trouble updating a CAN message object. The application I am prototyping on will require a lot more then 64 CAN messages, so I will have to dynamically change the content of message objects.
I have used HALCoGen to generate code, then written a modified version of CanTransmit, see code snippet below. The ID and DLC are correct, but on the CAN-bus no data is present.
What am I missing?
uint32 ExtCanTransmit(canBASE_t *node, uint32 messageBox, uint16 msgBoxArbitVal, uint8 dlc, const uint8 * data)
{
uint32 i;
uint32 success = 0U;
uint32 regIndex = (messageBox - 1U) >> 5U;
uint32 bitIndex = 1U << ((messageBox - 1U) & 0x1FU);
// Check input arguments
if (messageBox > 64U || msgBoxArbitVal > 0x7FFU || dlc > 8U) {
// Error! \todo add ASSERT
return 0;
}
/** - Check for pending message:
* - pending message, return 0
* - no pending message, start new transmission
*/
if ((node->TXRQx[regIndex] & bitIndex) != 0U) {
success = 0U;
}
else {
// Is interface register free?
if ((node->IF1STAT & 0x80U) == 0U) {
// IF1 is free
node->IF1CMD = 0xB7U; // Dir = write, access arbitration bits, control bits, data A and data B.
node->IF1ARB &= 0xE0000000U; // Keep the MsgVal,Xtd and Dir setting.
node->IF1ARB |= ((uint32)(msgBoxArbitVal & 0x7FFU) << 18U); // Copy passed value into the arbitration register.
node->IF1MCTL &= 0xFFFFFFF0U; // Keep everything except DLC.
node->IF1MCTL |= ((uint32)dlc & 0x0000000FU); // Copy DLC.
// Copy TX data
for (i = 0U; i < dlc; i++) {
node->IF1DATx[i] = *data;
data++;
}
// Copy TX data into message box
node->IF1NO = (uint8) messageBox;
success = 1U;
}
else {
// No interface register free, try again later.
success = 0U;
}
}
return success;
}