AnsweredAssumed Answered

Cannot enable CAN bus

Question asked by smith.benjamin on Jul 4, 2012
Latest reply on Dec 15, 2013 by Bellons
#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.

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?