cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F105 Can bus sending problem and code stops after executing for 16 times

Jbaha.1
Associate

I'm facing an issue with an STM32F105 microcontroller which with a simple code executing in a while loop it stops after 16 times.Here is code which I don't think there is a problem with the code since it runs fine on STM32F103

while (1)

 {

     uint8_t frame[8] = {'H','E','L','L','O','W','O','R'};

     CAN1_TX(0x110110,8,frame);

     HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1);

     HAL_Delay(500);

     CAN1_TX(0x110110,8,frame);

     HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1);

     HAL_Delay(500);

 }

void CAN1_TX(uint32_t id,uint32_t dlc,uint8_t frame[8]){

   char msg[50];

   CAN_TxHeaderTypeDef TxHeader;

   uint32_t TxMailbox;

   TxHeader.DLC = dlc;

   TxHeader.ExtId = id;

   TxHeader.IDE = CAN_ID_EXT;

   TxHeader.RTR = CAN_RTR_DATA;

   if(HAL_CAN_AddTxMessage(&hcan1, &TxHeader, frame,&TxMailbox) != HAL_OK){

       Error_Handler();

   }

   while(HAL_CAN_IsTxMessagePending(&hcan1, TxMailbox));

}

The led toggles for 16 seconds and then stop.

When I changed the delay to 500 it blinks now for 8 seconds only.

The problem is from the CAN_TX functions the problem only happens when CAN1_TX or CAN2_TX added when I remove it the code run normally infinitly

Debugging didn't help after that 8 seconds the debugger don't show any problem or where it is hanging

And after more digging.I changed the CAN mode to LOOPBACK and the problem disapeared it seems that the problem only happens on normal mode but why ? when I switch back to normal mode the problem came back.but I should point out that even with loopback mode the MCU don’t send any can frames (I’m hooking a logic analyser to see if there is some traffic) on STM32F103 the same code runs fine and the MCU sends can frames

3 REPLIES 3
MKado.1
Associate II

i have the same problem ??

i am a littile confused .. how the code work on st32f103 and not work on 105 ???

The STM32F103 and 105/107 implement CAN differently, the latter don't share a RAM buffer with USB, for example. The clocking is ALSO different, the former typically using 8 MHz, the later 25 MHz, as I recall.

Make sure you've got the CAN rate is correct, and that you have a responding node on the wire, so that messages pass, and CRC errors don't occur. Check bus traffic with an analyzer. Debug your situation.

Me Tooing Ghost/Zombie posts from ~2 Years ago isn't going to help. Create a NEW posts explaining your situation and context completely.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

thank you soo much