Question
STM32F103RB CAN PINS PROBLEM
Posted on April 11, 2013 at 16:03
Hi,
I have a problem with the CAN keil example for mcbstm32 board. I use this example a lot with the remap for CAN so the pins are PB8 and PB9. That is theDefault configuration for the board. I tried to change the pins to original position with no remap (PA11 and PA12) to test the program with another board. So I go to CAN_STM32Fc and change the function to:/* 1. Enable CAN controller Clock */
RCC->APB1ENR |= (1 << 25);
/* Note: MCBSTM32 uses PB8 and PB9 for CAN */ /* 2. Setup CAN Tx and Rx pins */ // RCC->APB2ENR |= (1 << 0); // enable clock for Alternate Function
// AFIO->MAPR &= 0xFFFF9FFF; // reset CAN remap // AFIO->MAPR |= 0x00004000; // set CAN remap, use PB8, PB9 /* GPIOB clock enable */ // RCC->APB2ENR |= (1 << 3);
/* Configure CAN pin: RX PB.8 input push pull */ // GPIOB->CRH &= ~(0x0F<< 0);
// GPIOB->CRH |= (0x08<< 0);
/* Configure CAN pin: TX PB.9 alternate output push pull */ // GPIOB->CRH &= ~(0x0F<< 4);
// GPIOB->CRH |= (0x0B<< 4);
/* 2. Setup CAN Tx and Rx pins */ /* GPIOA clock enable */ RCC->APB2ENR |= (1 << 2);
/* Configure CAN pin: RX PA.11 input push pull */ GPIOA->CRH &= ~(0x0F<< 12);
GPIOA->CRH |= (0x08<< 12);
/* Configure CAN pin: TX PA.12 alternate output push pull */ GPIOA->CRH &= ~(0x0F<< 16);
GPIOA->CRH |= (0x0B<< 16);
/* 3. Setup IRQ vector for CAN interrupt */ /* not necessary */ /* 4. Enable CAN interrupt */ NVIC->IPR [4] |= 0x10000000; /* set priority lower than SVC */ NVIC->ISER[0] |= (1 << (USB_HP_CAN_TX_IRQChannel & 0x1F)); /* only FIFO 0 is used */ NVIC->IPR [5] |= 0x00000010; /* set priority lower than SVC */ NVIC->ISER[0] |= (1 << (USB_LP_CAN_RX0_IRQChannel & 0x1F)); return CAN_OK; It compile ok but after callingCAN_Start it stucks. The example is: C:\Keil\ARM\Boards\Keil\MCBSTM32\RL\CAN Any ideas? Thanks