AnsweredAssumed Answered

STM32F103RBT6 CAN bus heavy issue

Question asked by Bastien Clergue on Apr 23, 2018
Latest reply on Apr 26, 2018 by AvaTar

Hello everyone, I am trying to configure my CAN on my OLIMEXINO STM32 board : OLIMEXINO-STM32 - Open Source Hardware Board  (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 !

Outcomes