Other Parts Discussed in Thread: HALCOGEN
Hello !
I'm trying to manage CAN bus with several modules, which have a proper ModID (100, 110, 120...).
There are 9 packet types for each module (ID 100 to 108 for module 1, 110 to 118 for module 2).
Five of the packet IDs are for messages from master to module, and the remaining four are module to master.
I used HalCoGen (TMS570+FreeRTOS) to configure messageBoxes with masks for RX. With the help of the RTM and this forum, I manage to get CAN ID for RX (function below).
But I have some difficulties with the TX ID. I understand I need to edit IFxCMD to set Arb in order to change IFxARB, but I think I doing it wrong, since the ID is not changed.
Here's my TX function, is there someone who could help me ?
uint32_t canTransmitID(canBASE_t *node, uint32_t messageBox, const uint8_t *data, uint32_t msgBoxID)
{
uint32_t i;
uint32_t success = 0U;
uint32_t regIndex = (messageBox - 1U) >> 5U;
uint32_t bitIndex = 1U << ((messageBox - 1U) & 0x1FU);
/** - Check for pending message:
* - pending message, return 0
* - no pending message, start new transmission
*/
if (node->TXRQx[regIndex] & bitIndex)
{
return success;
}
/** - Wait until IF1 is ready for use */
while (node->IF1STAT & 0x80);
/** - Copy TX data into IF1 */
for (i = 0U; i < 8U; i++)
{
#ifdef __little_endian__
node->IF1DATx[i] = *data++;
#else
node->IF1DATx[s_canByteOrder[i]] = *data++;
#endif
}
node->IF1CMD |= 0x200000U;
node->IF1ARB &= 0xE0000000U;
node->IF1ARB |= (msgBoxID & 0x1FFFFFFFU);
/** - Copy TX data into message box */
node->IF1NO = messageBox;
success = 1U;
return success;
}
uint32_t canGetID(canBASE_t *node, uint32_t messageBox)
{
uint32_t msgBoxID = 0U;
/** - Wait until IF2 is ready for use */
while (node->IF2STAT & 0x80);
/** - Configure IF2 for
* - Message direction - Read
* - Data Read
* - Clears NewDat bit in the message object.
*/
node->IF2CMD = 0x20U;
/** - Copy data into IF2 */
node->IF2NO = messageBox;
/** - Wait until data are copied into IF2 */
while (node->IF2STAT & 0x80);
/* Read Message Box ID from Arbitration register. */
msgBoxID = (node->IF2ARB & 0x1FFFFFFFU);
return msgBoxID;
}
Thanks,
Regards,
Jean-Marie