cancel
Showing results for 
Search instead for 
Did you mean: 

CAN BaudRate

julien
Associate II
Posted on June 03, 2008 at 15:32

CAN BaudRate

8 REPLIES 8
julien
Associate II
Posted on May 17, 2011 at 12:35

Hello,

I'm using um0427 firmware library.

I try to configure the baudrate at 500Kb/s for can interface,

in ST example :

/* CAN transmit at 500Kb/s and receive by interrupt in loopback mode*/

TestRx = CAN_Interrupt();

CAN_Interrupt() :

CAN_InitStructure.CAN_Mode=CAN_Mode_LoopBack;

CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1=CAN_BS1_8tq;

CAN_InitStructure.CAN_BS2=CAN_BS2_7tq;

CAN_InitStructure.CAN_Prescaler=1;

I don't understand how APB1Clock(36MHz)/(1+8+7)=500Kbit/s

thanks,

[ This message was edited by: julien.massot on 26-05-2008 11:27 ]

[ This message was edited by: julien.massot on 28-05-2008 10:32 ]

smart
Associate II
Posted on May 17, 2011 at 12:35

I also faced the same problem looks like that example code baud rate setting is completely wrong.

Try this It should work

CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1=CAN_BS1_9tq;

CAN_InitStructure.CAN_BS2=CAN_BS2_2tq;

CAN_InitStructure.CAN_Prescaler=6;

when APB1 clock is running at 36Mhz.

and also see datasheet page 297

julien
Associate II
Posted on May 17, 2011 at 12:35

Hello,

I still did not succeed in configuring the CAN, I try to send a frame but, only a bits is transmitted.

In spec CAN only one ACK is needed at the end of the frame.

/* CAN register init */

CAN_DeInit();

CAN_StructInit(&CAN_InitStructure);

/* CAN cell init */

CAN_InitStructure.CAN_TTCM=DISABLE;

CAN_InitStructure.CAN_ABOM=DISABLE;

CAN_InitStructure.CAN_AWUM=DISABLE;

CAN_InitStructure.CAN_NART=ENABLE;

CAN_InitStructure.CAN_RFLM=DISABLE;

CAN_InitStructure.CAN_TXFP=DISABLE;

//CAN_InitStructure.CAN_Mode=CAN_Mode_LoopBack;

CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;

CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1=CAN_BS1_9tq;

CAN_InitStructure.CAN_BS2=CAN_BS2_2tq;

CAN_InitStructure.CAN_Prescaler=6;

CAN_Init(&CAN_InitStructure);

/* CAN filter init */

CAN_FilterInitStructure.CAN_FilterNumber=1;

CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;

CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;

CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000;

CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;

CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0xFFFF;

CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;

CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;

CAN_FilterInitStructure.CAN_FilterActivation=DISABLE;

CAN_FilterInit(&CAN_FilterInitStructure);

/* transmit */

TxMessage.StdId=0x11;

TxMessage.RTR=CAN_RTR_DATA;

TxMessage.IDE=CAN_ID_STD;

TxMessage.DLC=2;

TxMessage.Data[0]=0xCA;

TxMessage.Data[1]=0xFE;

TransmitMailbox=CAN_Transmit(&TxMessage);

e = 0;

while(( etat!= CANTXOK) && (e != 0xFF))

{

e++;

etat=CAN_TransmitStatus(TransmitMailbox);

}

[ This message was edited by: julien.massot on 02-06-2008 17:31 ]

smart
Associate II
Posted on May 17, 2011 at 12:35

Do you have any other node in your network to acknowledge the transmit message on the CAN bus.

If you want to use the can in normal mode atleast one node should be there.

If you are just testing then use loopback mode.

Did you enable the Can clock, and also setup the can tx and Rx lines I hope you have already did that.

julien
Associate II
Posted on May 17, 2011 at 12:35

Hello Smart.avr,

I have the impression that we are the only ones to use the CAN on STM32 :-].

I use the can with an another can node CANUSB working at 500kb/s (www.canusb.com),

I do not think that it is a problem of ACK because only the first Bit is transmitted.

My RCC config,

/* Enable GPIOD clocks */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

My GPIO config.

//CAN Remappper sur D0 et D1

GPIO_PinRemapConfig(GPIO_Remap2_CAN, ENABLE);

/* Configure CAN pin: RX */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;

GPIO_Init(GPIOD, &GPIO_InitStructure);

/* Configure CAN pin: TX */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;

GPIO_Init(GPIOD, &GPIO_InitStructure);

thanks,

smart
Associate II
Posted on May 17, 2011 at 12:35

Then not sure about your problem.But in your RCC configuration I still can not see the code to enable the CAN clock.

I have this configuration if it helps you...

One more point, did you see the STM32 errata related with PD0 and PD1 Pins and also if you have debugger did you see in the peripherals window if your can Controller is initialized properly.

/* CAN Periph clock enable */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);

/* GPIOD clock enable */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);

/* AFIO clocks */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

/* Configure CAN pin: TX */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOD, &GPIO_InitStructure);

/* Configure CAN pin: RX */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

GPIO_Init(GPIOD, &GPIO_InitStructure);

/* Enable the full remapping of CAN at PD0,PD1 */

GPIO_PinRemapConfig(GPIO_Remap2_CAN , ENABLE);

julien
Associate II
Posted on May 17, 2011 at 12:35

Scuse it's a mistake i've forget to paste this lines

/* activation de l'horloge sur le CAN ----*/

RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);

My Code test the whole of the interfaces of the STM32.. so i can't paste all my source code..

thanks you

muhammaduzairafzal45
Associate III
Posted on December 19, 2012 at 15:00

May be my post is helpful for Baudrate calculation for CAN.

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32%20CAN%20Filter&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx&currentviews=4]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32%20CAN%20Filter&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx&currentviews=4