Thanks Robin
Yes that is correct, CAN frame can be sent when CAN0_ENABLE or CAN1_ENABLE is defined, but cannot be sent if both are defined at the same time.
I added a toggle to the switch ISR, so that each time the button is pressed it will toggle between sending either the CAN0 message or the CAN1 message (but not both).
I did this to avoid any possible conflicts of trying to send a message on CAN0 and CAN1 at the same time.
However, the result is the same i.e.CAN1 works but CAN0 doesn't.
The end goal is to send messages at the same time on both CAN0 and CAN1, because I am trying to emulate a redundant CAN bus.
The code is shown below (where canToggle is used to toggle between message sending)..
void buttonISR(void)
{
/* Check if one of the buttons was pressed */
uint32_t buttonsPressed = PINS_DRV_GetPortIntFlag(BTN_PORT) &
((1 << BTN1_PIN) | (1 << BTN2_PIN));
bool sendFrame = false;
static bool canToggle;
if(buttonsPressed != 0)
{
/* Set FlexCAN TX value according to the button pressed */
switch (buttonsPressed)
{
case (1 << BTN1_PIN):
ledRequested = LED0_CHANGE_REQUESTED;
sendFrame = true;
/* Clear interrupt flag */
PINS_DRV_ClearPinIntFlagCmd(BTN_PORT, BTN1_PIN);
break;
case (1 << BTN2_PIN):
ledRequested = LED1_CHANGE_REQUESTED;
sendFrame = true;
/* Clear interrupt flag */
PINS_DRV_ClearPinIntFlagCmd(BTN_PORT, BTN2_PIN);
break;
default:
PINS_DRV_ClearPortIntFlagCmd(BTN_PORT);
break;
}
if (sendFrame)
{
/* Set information about the data to be sent
* - Standard message ID
* - Bit rate switch enabled to use a different bitrate for the data segment
* - Flexible data rate enabled
* - Use zeros for FD padding
*/
if (canToggle)
{
#ifdef CAN1_ENABLE
can_buff_config_t buffCfg1 = {
.enableFD = false,
.enableBRS = true,
.fdPadding = 0U,
.idType = CAN_MSG_ID_STD,
.isRemote = false
};
/* Configure TX buffer with index TX_MAILBOX*/
CAN_ConfigTxBuff(&can_1_instance, 2, &buffCfg1);
/* Prepare message to be sent */
can_message_t message1 = {
.cs = 0U,
.id = 0x0C1,
.data[0] = 0x01,
.data[1] = 0x23,
.data[2] = 0x45,
.data[3] = 0x67,
.data[4] = 0x89,
.data[5] = 0xAB,
.data[6] = 0xCD,
.data[7] = 0xEF,
.length = 8U
};
/* Send the information via CAN */
CAN_Send(&can_1_instance, 2, &message1);
#endif
}
else
{
#ifdef CAN0_ENABLE
can_buff_config_t buffCfg = {
.enableFD = false,
.enableBRS = true,
.fdPadding = 0U,
.idType = CAN_MSG_ID_STD,
.isRemote = false
};
/* Configure TX buffer with index TX_MAILBOX*/
CAN_ConfigTxBuff(&can_0_instance, 1, &buffCfg);
/* Prepare message to be sent */
can_message_t message = {
.cs = 0U,
.id = TX_MSG_ID,
.data[0] = 0x01,
.data[1] = 0x23,
.data[2] = 0x45,
.data[3] = 0x67,
.data[4] = 0x89,
.data[5] = 0xAB,
.data[6] = 0xCD,
.data[7] = 0xEF,
.length = 8U
};
/* Send the information via CAN */
CAN_Send(&can_0_instance, 1, &message);
#endif
}
canToggle ^= 1;
}
}
}