2012-07-04 09:16 AM
#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
2012-07-06 05:50 AM
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.2012-07-10 09:54 AM
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!2012-10-12 02:15 AM
2012-10-13 07:24 PM
As I indicated in the other thread, I'm not using CAN on an F1 device
2013-12-15 07:42 AM
#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?