2022-08-25 08:15 AM
I'm new to the STM32Cube series, and I'm using the STM32Cube MX L4 chipset. I believe I've done everything that online tutorials, examples, and the actual specs demand, but when my code issues HAL_CAN_AddTxMessage, my ISR never gets called. What am I missing?
Here's my code:
/* USER CODE BEGIN 0 */
// TODO: programmatically retrieve the actual CAN ID
#define NOJI_DEFAULT_ID 102
uint8_t currentID = NOJI_DEFAULT_ID;
CAN_TxHeaderTypeDef txHeader;
CAN_RxHeaderTypeDef rxHeader;
uint8_t txData[8];
uint8_t rxData[8];
uint32_t txMailbox;
int dataCheck = 0;
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *Nhcan)
{
static uint32_t count = 0;
count++;
memset((void *) &rxHeader, 0, sizeof(CAN_RxHeaderTypeDef));
memset((void *) rxData, 0, 8);
HAL_CAN_GetRxMessage(Nhcan, CAN_RX_FIFO0, &rxHeader, rxData);
if (rxHeader.DLC == 1)
{
dataCheck = 1;
}
}
HAL_StatusTypeDef Noji_CAN_Start(CAN_HandleTypeDef *Nhcan)
{
HAL_StatusTypeDef status = HAL_OK;
CAN_FilterTypeDef canFilter;
memset((void *) &canFilter, 0, sizeof(CAN_FilterTypeDef));
canFilter.FilterActivation = CAN_FILTER_ENABLE;
canFilter.FilterBank = 4;
canFilter.FilterFIFOAssignment = CAN_RX_FIFO0;
canFilter.FilterIdHigh = currentID << 5;
canFilter.FilterMaskIdHigh = currentID << 5;
canFilter.FilterMode = CAN_FILTERMODE_IDMASK;
canFilter.FilterScale = CAN_FILTERSCALE_32BIT;
canFilter.SlaveStartFilterBank = 10;
status = HAL_CAN_ConfigFilter(Nhcan, &canFilter);
status = HAL_CAN_Start(Nhcan);
status = HAL_CAN_ActivateNotification(Nhcan, CAN_IT_RX_FIFO0_MSG_PENDING);
memset((void *) &txHeader, 0, sizeof(CAN_TxHeaderTypeDef));
txHeader.IDE = CAN_ID_STD;
txHeader.RTR = CAN_RTR_DATA;
txHeader.StdId = currentID; // 0x66
txHeader.DLC = 1;
txHeader.TransmitGlobalTime = DISABLE;
memset((void *) txData, 0, 8);
txData[0] = 0xD7;
status = HAL_CAN_AddTxMessage(Nhcan, &txHeader, txData, &txMailbox);
return status;
}
/* USER CODE END 0 */
and then Noji_CAN_Start is called from MX_CAN1_Init immediately after the call to HAL_CAN_Init
Thanks!
2022-08-31 12:58 PM
Ok, no answer. Well, let's try a different approach. What can I do in the STM32 firmware to advertise my ID / presence on the CAN bus? Using DroneCAN, I can't see my device, possibly because it doesn't register / advertise its ID on the bus. Thoughts?