cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103RBT6 CAN bus heavy issue

B C
Associate II
Posted on April 23, 2018 at 17:15

Hello everyone, I am trying to configure my CAN on my OLIMEXINO STM32 board : 

https://www.olimex.com/Products/Duino/STM32/OLIMEXINO-STM32/

  (with a STM32F103RBT6 �C), but it just won't work ...

I'm using a PCAN USB to communicate between my PC and my board, but there is no data exchange between my board and my computer. The Pcan software is sending me a 'bus heavy' flag and I don't know why.

Here is my code : 

int nb_trames = 4;

int ID[8] = {0x06, 0x11, 0x12, 0x13, 0x14,0x15,0x16,0x17};

Tab_TxMessages = malloc(nb_trames * sizeof(CanTxMsgTypeDef));

...

while (1)

{

   int cpt = 0 ;

   for (cpt = 0 ; cpt < nb_trames ; cpt++)

      {

      Tab_TxMessages[cpt].StdId = ID[cpt];

      Tab_TxMessages[cpt].IDE = 0;

      Tab_TxMessages[cpt].RTR = 0;

      Tab_TxMessages[cpt].DLC = 8;

      Tab_TxMessages[cpt].Data[0] = cpt;

      Tab_TxMessages[cpt].Data[1] = cpt+1;

      Tab_TxMessages[cpt].Data[2] = cpt+2;

      Tab_TxMessages[cpt].Data[3] = cpt+3;

      Tab_TxMessages[cpt].Data[4] = cpt+4;

      Tab_TxMessages[cpt].Data[5] = cpt+5;

      Tab_TxMessages[cpt].Data[6] = cpt+6;

      Tab_TxMessages[cpt].Data[7] = cpt+7;

      HAL_CAN_Transmit(&hcan, HAL_MAX_DELAY);

      HAL_Delay(1);

      }

}

(don't know how to properly format it though, if anyone can help...)

The issue is not coming from the 120 Ohm (I set the jumper correctly on the board). However it might come from the way I configure my CAN bus : 

void MX_CAN_Init(void)

{

hcan.Instance = CAN1;

hcan.Init.Prescaler = 4;

hcan.Init.Mode = CAN_MODE_NORMAL;

hcan.Init.SJW = CAN_SJW_1TQ;

hcan.Init.BS1 = CAN_BS1_8TQ;

hcan.Init.BS2 = CAN_BS2_8TQ;

hcan.Init.TTCM = DISABLE;

hcan.Init.ABOM = DISABLE;

hcan.Init.AWUM = DISABLE;

hcan.Init.NART = DISABLE;

hcan.Init.RFLM = DISABLE;

hcan.Init.TXFP = DISABLE;

if (HAL_CAN_Init(&hcan) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

}

I have no idea how to correctly configure it, so if anyone dare to explain, that might help solve the issue..

Thank you for the help !

#pcan #can-interface #olimex #stm32f103rbt6
33 REPLIES 33
Posted on April 23, 2018 at 17:23

Perhaps pay attention to errors/status returned by functions, pay attention to bus loading if important, rather than blasting data with arbitrary delays.

Check if other messages are being sent to you.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
stm322399
Senior
Posted on April 23, 2018 at 17:51

Where is your assignment of hcan.pTxMsg ?

By the way, which speed are you expect to achieve, is your probe synced with ?

stm322399
Senior
Posted on April 23, 2018 at 18:27

Good. So what does HAL_CAN_Transmit returns ?

For speed, I can share my settings:

* 1Mbps

* prescaler 2 (set it to 4 for 500 kbps)

* SJW_2TQ

* BS1_11TQ

* BS2_6TQ

* ABOM enabled

Posted on April 23, 2018 at 17:26

When I build my project, there is no error/warning

Clive One wrote:

pay attention to bus loading if important, rather than blasting data with arbitrary delays.

What do you mean ?

Clive One wrote:

Check if other messages are being sent to you.

Through CAN ? Nothing is being sent to me ..

Posted on April 23, 2018 at 18:01

Shame on me, I forgot it ...

Changed the loop to : 

for (cpt = 0 ; cpt < nb_trames ; cpt++)

{

   Tab_TxMessages[cpt].StdId = ID[cpt];

   Tab_TxMessages[cpt].IDE = 0;

   Tab_TxMessages[cpt].RTR = 0;

   Tab_TxMessages[cpt].DLC = 8;

   Tab_TxMessages[cpt].Data[0] = cpt;

   Tab_TxMessages[cpt].Data[1] = cpt+1;

   Tab_TxMessages[cpt].Data[2] = cpt+2;

   Tab_TxMessages[cpt].Data[3] = cpt+3;

   Tab_TxMessages[cpt].Data[4] = cpt+4;

   Tab_TxMessages[cpt].Data[5] = cpt+5;

   Tab_TxMessages[cpt].Data[6] = cpt+6;

   Tab_TxMessages[cpt].Data[7] = cpt+7;

   hcan.pTxMsg = &Tab_TxMessages[cpt];

   HAL_CAN_Transmit(&hcan, HAL_MAX_DELAY);

   HAL_Delay(1);

}

However it didn't change anything to the issue ..

500 kbits/sec would be good, but I can go lower if needed

stm322399
Senior
Posted on April 24, 2018 at 09:32

Looks like the issue is coming from something else, check clock, gpio etc ...

By the way, try to directly observe signal at MCU pins with o-scope, relying on computer communication is too high level.

Good luck.

Posted on April 24, 2018 at 09:08

It doesn't return anything as it gets stuck in this loop : 

while(!(__HAL_CAN_TRANSMIT_STATUS(hcan, transmitmailbox)))

{

   /* Check for the Timeout */

   if(Timeout != HAL_MAX_DELAY)                           // Doesn't go past this as the timeout I set is HAL_MAX_DELAY

   {

      if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout))

      {

         hcan->State = HAL_CAN_STATE_TIMEOUT;

         /* Cancel transmission */

         __HAL_CAN_CANCEL_TRANSMIT(hcan, transmitmailbox);

         /* Process unlocked */

        __HAL_UNLOCK(hcan);

         return HAL_TIMEOUT;

         }

     }

}

I double/triple checked and the board is well connected to the computer, I really don't know where it is coming from...

Also, I read that the CAN settings depend  on the clock configuration, how can I check my clock configuration (as I used CubeMX) ?

Posted on April 24, 2018 at 09:52

GPIO are good, I don't exactly know what to check about the clock.

Unfortunately I don't have an oscilloscope...

stm322399
Senior
Posted on April 24, 2018 at 12:05

CAN_CTRL is the external signal to the CAN transceiver.