cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot enable CAN bus

ee52bs
Associate II
Posted on July 04, 2012 at 18:16

#include ''ll_can.h'' 
#include ''rcc.h'' 
#include ''gpio.h'' 
#include ''nvic.h'' 
#include ''usb.h'' 
int can_init(int mode) 
{ 
rcc_clk_enable(RCC_GPIOB); //enable GPIO port B 
rcc_clk_enable(RCC_AFIO); //enable AFIO clock 
afio_remap(AFIO_REMAP_CAN_1); //remap to PB8 and PB9 
gpio_set_mode(GPIOB, 8, GPIO_INPUT_FLOATING); //set pin modes 
gpio_set_mode(GPIOB, 9, GPIO_AF_OUTPUT_PP); 
(RCC_BASE->APB1ENR) |= 1 << 
RCC_APB1ENR_CANEN
; //enable CAN clock 
(RCC_BASE->APB1RSTR) |= 1 << 
RCC_APB1ENR_CANRST
; //reset CAN peripheral 
return RCC_BASE->APB1ENR; 
//set up of baud rates, mode, filters etc. 
}

Hi, I am trying to setup the CAN bus in loopback mode on an Olimexino STM32 board (using an STM32F103RBT6), but when I print out the binary value of the APB1 enable register I get 100000000000000000000111 - i.e. the USB clock is enabled, and TIM2, 3 and 4 are enabled.I'd be grateful if anyone has any ideas to solve this? #can-bus #olimexino
14 REPLIES 14
Posted on July 06, 2012 at 14:50

it might be because there are interrupt conflicts between the USB and CAN bus. Does this sound likely?

Don't CAN and USB share hardware resources, like a memory buffer,or pins? Seem to recall some complaints about this on earlier STM32 parts, but the connectivity series supposedly addressed that.

There are interrupts that share the same vector, in which case you need to check/handle the specific sources of the interrupt.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ee52bs
Associate II
Posted on July 10, 2012 at 18:54

I have managed to get the controller to switch back to normal mode, by playing with the baud rates. I am now working on transmitting data in loopback mode and I have a few more questions :)

>In loopback mode do I need to do anything to the hardware set up on my board such as put a resistor between the CANH and CANL terminals of the CAN transceiver?

>Since the switch from INIT to NORMAL mode works OK does this suggest I have my clocks and baud rate set up correctly or could this still be a problem?

>USB and CAN share the same transmit/ recieve SRAM in the controller I am using (STM32F103RBT6), so it is not possible to use both at the same time. If the USB clock is disabled are there any other sources of interference between the USB and CAN?

Thanks!

emmanuelmigabo2007
Associate II
Posted on October 12, 2012 at 11:15

Hey Clivel!

I am using STM32f103CB microcontroller with my codes attached in this post!I can see something when I change the mode to loop_back mode but doesn't get anything out of the CAN_TX pin when operating in normal mode!I have checked my settings and even compared them with the CAN_settings of examples in the STM firmware!

cAN ANYONE ASSIST PLIZ!

________________

Attachments :

CANbus.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtE0&d=%2Fa%2F0X0000000aKT%2FyHAp42kRZ8wPogX2u0YqYs8v5z9s8PRd5Mm96OuYbhM&asPdf=false
Posted on October 14, 2012 at 04:24

As I indicated in the other thread, I'm not using CAN on an F1 device

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
abelloni
Associate II
Posted on December 15, 2013 at 16:42

#include ''ll_can.h'' 
#include ''rcc.h'' 
#include ''gpio.h'' 
#include ''nvic.h'' 
#include ''usb.h'' 
int can_init(int mode) 
{ 
rcc_clk_enable(RCC_GPIOB); //enable GPIO port B 
rcc_clk_enable(RCC_AFIO); //enable AFIO clock 
afio_remap(AFIO_REMAP_CAN_1); //remap to PB8 and PB9 
gpio_set_mode(GPIOB, 8, GPIO_INPUT_FLOATING); //set pin modes 
gpio_set_mode(GPIOB, 9, GPIO_AF_OUTPUT_PP); 
(RCC_BASE->APB1ENR) |= 1 << 
RCC_APB1ENR_CANEN
; //enable CAN clock 
(RCC_BASE->APB1RSTR) |= 1 << 
RCC_APB1ENR_CANRST
; //reset CAN peripheral 
return RCC_BASE->APB1ENR; 
//set up of baud rates, mode, filters etc. 
}

Hi, I am trying to setup the CAN bus in loopback mode on an Olimexino STM32 board (using an STM32F103RBT6), but when I print out the binary value of the APB1 enable register I get 100000000000000000000111 - i.e. the USB clock is enabled, and TIM2, 3 and 4 are enabled.I'd be grateful if anyone has any ideas to solve this?