Hi,
I am trying to get the CAN bus working in loopback mode on an Olimexino STM32. I have tried the libraries from STM, and x893's code from this forum, and the Keil example code, and I am still having the same problem: The bus initialises OK, returns to normal mode OK, I set up the TX mailbox OK (I checked the register values), but when I set the TXRQ bit nothing happens and the bus remains idle. I also checked aborting the transmission by setting the ABRQ bit but the mailbox isn't cleared. It appears that the hardware is not responding to the software setting bits, which I figured must be due to a problem with the low level interface setup, but I've checked the register addresses in the STM32 manual and the pins in the Olimexino manual and I can't see anything wrong. Below is my initialisation code:
nvic_globalirq_disable();// disable all interrupts
rcc_clk_enable(RCC_GPIOB);
rcc_clk_enable(RCC_AFIO);// enable clocks for AFIO
(RCC_BASE->APB1ENR) = 0x2000007; //enable CAN clock, disable USB clock
(RCC_BASE->CFGR) |= 1<<CFGR_USBPRE; //turn off USB prescaler
(RCC_BASE->APB2RSTR) = 0x9; //assert GPIO reset
(RCC_BASE->APB2RSTR) = 0x0; //release GPIO reset
(RCC_BASE->APB1RSTR) = 0x2000000; //assert CAN reset
(RCC_BASE->APB1RSTR) = 0x0; //release CAN reset
afio_remap(AFIO_REMAP_CAN_1);
gpio_set_mode(GPIOB, 8, GPIO_INPUT_FLOATING);
gpio_set_mode(GPIOB, 9, GPIO_AF_OUTPUT_PP);
//enable interrupts
nvic_irq_enable(NVIC_USB_LP_CAN_RX0); // enable NVIC interrupts
nvic_irq_enable(NVIC_USB_HP_CAN_TX);
nvic_globalirq_enable();//enable all interrupts
(CAN_CTRL->IER) |= 1<<IER_FMPIE0; //set FIFO0 empty interrupt bit
(CAN_CTRL->IER) |= 1<<IER_FMPIE1; //set FIFO1 empty interrupt bit
(CAN_CTRL->IER) |= 1<<IER_TMEIE; //set TX MB empty interrupt bit
The only things I can think of is that there is some interrupt which should occur which hasn't been enabled, or else there is still some interference between the USB and CAN bus. Any ideas?
Cheers,
Ben