/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / CAN_BS1 and CAN_BS2

Username:     
Password:     
             

Forum

# 1   2010-05-08 17:48:53 CAN_BS1 and CAN_BS2 (project: STM32 CAN baudrate calculation 1.0)

kounst
New member
Registered: 2009-06-08
Posts: 7

CAN_BS1 and CAN_BS2 (project: STM32 CAN baudrate calculation 1.0)

I might be wrong but I think you also have to add 1 to TS1 and TS2.

CAN_BS1 = TS1 +1;
CAN_BS1 = TS2 +1;

At least that way it worked for me.

Regards,
kounst

Last edited by kounst (2010-05-08 17:49:21)

Offline

 

# 2   2010-05-08 21:12:38 CAN_BS1 and CAN_BS2 (project: STM32 CAN baudrate calculation 1.0)

Matthias
Member
From: Germany
Registered: 2010-01-30
Posts: 20

Re: CAN_BS1 and CAN_BS2 (project: STM32 CAN baudrate calculation 1.0)

have you entered the right frequency?
What hardware do you use?

I use the following values

   #ifdef  _125KB
   CAN_InitStructure.CAN_Prescaler = 16;
   CAN_InitStructure.CAN_BS1       = 8;
   CAN_InitStructure.CAN_BS2       = 7;
   #endif
   #ifdef  _250KB
   CAN_InitStructure.CAN_Prescaler = 8;
   CAN_InitStructure.CAN_BS1       = 8;
   CAN_InitStructure.CAN_BS2       = 7;
   #endif
   #ifdef  _500KB
   CAN_InitStructure.CAN_Prescaler = 4;
   CAN_InitStructure.CAN_BS1       = 8;
   CAN_InitStructure.CAN_BS2       = 7;
   #endif
   #ifdef  _1000KB
   CAN_InitStructure.CAN_Prescaler = 2;
   CAN_InitStructure.CAN_BS1       = 8;
   CAN_InitStructure.CAN_BS2       = 7;
   #endif

Last edited by Matthias (2010-05-08 21:28:02)


Wer Rechtschreibfehler findet, darf sie behalten
english by translate.google.com
Whoever finds typos may keep them

Offline

 

# 3   2010-05-09 13:30:21 CAN_BS1 and CAN_BS2 (project: STM32 CAN baudrate calculation 1.0)

kounst
New member
Registered: 2009-06-08
Posts: 7

Re: CAN_BS1 and CAN_BS2 (project: STM32 CAN baudrate calculation 1.0)

my apb1 frequency is 18MHz
I'm using an STM32F103VCT6. It's not a primer but that shouldn't make a difference.

Your spreadsheet calculated the following:

BaudRate    BRP[9:0]    TS1[3:0]    TS2[2:0]    SAMPLE POINT
500.000    1    8    7    44,4%
500.000    1    9    6    38,9%
500.000    1    10    5    33,3%
500.000    1    11    4    27,8%
500.000    1    12    3    22,2%
500.000    1    13    2    16,7%
500.000    1    14    1    11,1%
500.000    1    15    0    5,6%
500.000    2    8    1    16,7%
500.000    2    9    0    8,3%
500.000    3    0    6    77,8%
500.000    3    1    5    66,7% <--
500.000    3    2    4    55,6%
500.000    3    3    3    44,4%
500.000    3    4    2    33,3%
500.000    3    5    1    22,2%
500.000    3    6    0    11,1%
500.000    8    0    1    50,0%
500.000    8    1    0    25,0%

this way it didn't work
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_1tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 4;

this way it does
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_2tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_6tq;
CAN_InitStructure.CAN_Prescaler = 4;

same thing with 250kbaud

See also reference manual page 562 figure 205:
BS1 = tq * (TS1 +1)
BS2 = tq * (TS2 +1)

Offline

 

# 4   2010-05-09 20:12:52 CAN_BS1 and CAN_BS2 (project: STM32 CAN baudrate calculation 1.0)

Matthias
Member
From: Germany
Registered: 2010-01-30
Posts: 20

Re: CAN_BS1 and CAN_BS2 (project: STM32 CAN baudrate calculation 1.0)

Here is the error:
see stm32f10x_can.h
definatsion the other is when the value 1TG = 0, 2TG  = 1, etc


#define CAN_BS1_1tq                 ((uint8_t)0x00)  /* 1 time quantum */
#define CAN_BS1_2tq                 ((uint8_t)0x01)  /* 2 time quantum */
.
.
#define CAN_BS1_15tq                ((uint8_t)0x0E)  /* 15 time quantum */
#define CAN_BS1_16tq                ((uint8_t)0x0F)  /* 16 time quantum */


Wer Rechtschreibfehler findet, darf sie behalten
english by translate.google.com
Whoever finds typos may keep them

Offline

 

# 5   2010-05-09 22:32:40 CAN_BS1 and CAN_BS2 (project: STM32 CAN baudrate calculation 1.0)

kounst
New member
Registered: 2009-06-08
Posts: 7

Re: CAN_BS1 and CAN_BS2 (project: STM32 CAN baudrate calculation 1.0)

So you are saying that there is a bug in the stm32f10x_can.h file:
#define CAN_BS1_1tq                 ((uint8_t)0x00)  /* 1 time quantum */
instead of   
#define CAN_BS1_1tq                 ((uint8_t)0x01)  /* 1 time quantum */


As a workaround you have to add 1 not only to BRP but also to TS1 and TS2.

You should edit your projects description accordingly

Regards

Offline

 

Board footer