0
\$\begingroup\$

I'm trying to make use of the bxCAN of STM32F103C8 on a bluepill but it doesn't work and I don't know what is the problem.I'm using the hal API
here is the main code in the while loop

while (1)
{
    char msg[50];
    CAN_TxHeaderTypeDef TxHeader;
    uint8_t data[5] = {'H','E','L','L','O'};
    uint32_t TxMailbox;
    TxHeader.DLC = 5;
    TxHeader.ExtId = 0x18181820;
    TxHeader.IDE = CAN_ID_EXT;
    TxHeader.RTR = CAN_RTR_DATA;
    if(HAL_CAN_AddTxMessage(&hcan, &TxHeader, data,TxMailbox) != HAL_OK){
        Error_Handler();
    }

    while(HAL_CAN_IsTxMessagePending(&hcan, TxMailbox));
    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
    HAL_Delay(1000);
    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
    HAL_Delay(1000);
}

The code breaks at the HAL_CAN_AddTxMessage.
this is my first time working with an STM32 so I've never had a working example and couldn't find any working examples online.
Please help I've posted many times :/

\$\endgroup\$
1
  • \$\begingroup\$ How are you initialising bxCAN and how many CAN nodes does your network have? \$\endgroup\$
    – Jeroen3
    Apr 14, 2020 at 6:12

1 Answer 1

2
\$\begingroup\$

TxMailbox -> &TxMailbox.

The manual:

pTxMailbox pointer to a variable where the function will return the TxMailbox used to store the Tx message.

Since the function will apparently try to return data through this pointer, it will crash and burn if you provide a uint32_t by value.

Notably, a conforming C compiler must give you a message (warning or error) for this code. If you didn't get any such message, your tool chain is broken. References.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.