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 25, 2018 at 15:01

CANH / CANL swapped somewhere ?

Proper termination ?

Using PCAN stuff myself (PCAN Explorer), both mistakes used to produce such a result.

B C
Associate II
Posted on April 25, 2018 at 15:06

Termination is correctly set. CANH and CANL should also be ok according to the plans I've been given, I will swap them, just in case ...

I'm beggining to think it's a hardware issue, but can't find it ..

Posted on April 25, 2018 at 15:11

rebuild your project with the minimal functions (only sending a few CAN messages, nothing else) and post your binary here. I don't promise to find time to do it, but checking with o-scope can be helpful.

B C
Associate II
Posted on April 25, 2018 at 15:11

I changed the CANH and CANL, still not working

Posted on April 25, 2018 at 16:21

If you have more nodes, you can try to remove individual nodes, and check if anything changes.

Are the sampling points set correctly ?

Posted on April 25, 2018 at 16:37

I send it to you by PM, I also attach the project (the one the .bin is related to, so that you can make some little changes if you wich).

I actually found an old oscilloscope (analog ..) but i'm not exactly sure what am I supposed to look at and witness ...

Thank you for your help !

B C
Associate II
Posted on April 25, 2018 at 16:41

I just have CANH, CANL and GND

The sampling points ? I didn't have to set any sampling point (or I don't know I did ..)

Posted on April 25, 2018 at 18:10

ahem, did I say *only* CAN ??? Well I also need GPIO init ! Did you removed them because Iasked, or were they absent from your original project ?

Pay attention to the GPIO configuration to remap CAN1 to PB8/9, it is not the reset default, you need to write into AFIO->MAPR.

Posted on April 26, 2018 at 01:29

I used the CanDo unit for a week. everything worked brilliantly with the code I have already given you.

here are the sample points required by CanBus

0690X00000604btQAA.jpg
B C
Associate II
Posted on April 26, 2018 at 09:43

Okay so ...

For some reason, it seems that the different Time Quantas my Peak USB likes to receive are different than what

GONZALEZ.Laurent

mentionned. I managed to find this out while searching a bit in the submenu of PcanView.

So now it seems to be working ...

I feel a bit dumb though, but thank you everyone for the help anyway !