STM32G473 extended CAN ID never even
I'm attempting to interface an STM32G473 with a VESC motor controller using CAN.
I am successfully receiving status frames from the VESC controller, but when I transmit a frame to command it, the ID my scope reads in the frame is not always the same as what I set in my code. It appears to always set bit 0.
For example, if I set an extended ID of 0, my scope reads an ID of 1. Setting the ID to 1 in code results in the same waveform. I've attached waveforms for IDs 0 and 1. The problem persists for other IDs, so 88 becomes 89 etc.
I've used CubeMX to configure FDCAN1 for 500kbps, which gave me this at 150MHz clock:
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan1.Init.AutoRetransmission = DISABLE;
hfdcan1.Init.TransmitPause = DISABLE;
hfdcan1.Init.ProtocolException = DISABLE;
hfdcan1.Init.NominalPrescaler = 20;
hfdcan1.Init.NominalSyncJumpWidth = 1;
hfdcan1.Init.NominalTimeSeg1 = 12;
hfdcan1.Init.NominalTimeSeg2 = 2;
hfdcan1.Init.DataPrescaler = 1;
hfdcan1.Init.DataSyncJumpWidth = 1;
hfdcan1.Init.DataTimeSeg1 = 1;
hfdcan1.Init.DataTimeSeg2 = 1;
hfdcan1.Init.StdFiltersNbr = 0;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
I start it with:
HAL_FDCAN_Start(&hfdcan1);
HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
Once started, receiving works as expected.
I then have this for transmitting, with a temporary test assignment for the ID:
FDCAN_TxHeaderTypeDef header;
header.Identifier = id;
header.IdType = FDCAN_EXTENDED_ID;
header.TxFrameType = FDCAN_DATA_FRAME;
header.DataLength = FDCAN_DLC_BYTES_8;
header.FDFormat = FDCAN_CLASSIC_CAN;
header.MessageMarker = 0;
const uint32_t tmp_id = 0;
header.Identifier = tmp_id;
std::array<uint8_t, 8> buffer = {0};
if (HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &header, buffer.data()) != HAL_OK) {
const auto can_errno = HAL_FDCAN_GetError(&hfdcan1);
LOG_ERROR("Failed to add message to FDCAN1 TX FIFO, error={}", can_errno);
}
I'm not sure what I'm missing or have misunderstood.
