AnsweredAssumed Answered

STM32F207IF use of CAN2

Question asked by carbonera.felipe on Jul 2, 2013
Latest reply on Jul 15, 2013 by carbonera.felipe
Hi.
I am using the KEIL exemple RL-CAN software for MCBSTM32F200 with and board that use stm32f207IF.
The problem is that I can't change the pins of CAN2 sucessfully. 
The CAN works to send a messange but receive nothing. So I guess it is a problem with the pin configuration:
The original code from the exemple to PB5 and PB13 is:
/* Enable clock for CAN2 and GPIOB */
    RCC->APB1ENR   |= (1 << 25) | (1 << 26);
    RCC->AHB1ENR   |= (1 <<  1);
    /* CAN2, use PB5, PB13 */
    GPIOB->MODER   &= ~(( 3 << ( 5 << 1)) | ( 3 << (13 << 1)));
    GPIOB->MODER   |=  (( 2 << ( 5 << 1)) | ( 2 << (13 << 1)));
    GPIOB->OTYPER  &= ~(( 1 <<   5)       | ( 1 <<  13      ));
    GPIOB->OSPEEDR &= ~(( 3 << ( 5 << 1)) | ( 3 << (13 << 1)));
    GPIOB->PUPDR   &= ~(( 3 << ( 5 << 1)) | ( 3 << (13 << 1)));
    GPIOB->AFR[0]  &= ~ (15 << ( 5 << 2));
    GPIOB->AFR[0]  |=   ( 9 << ( 5 << 2));
    GPIOB->AFR[1]  &= ~ (15 << ( 5 << 2));
    GPIOB->AFR[1]  |=   ( 9 << ( 5 << 2));
    /* Enable CAN2 interrupts */
    NVIC_SetPriority (CAN2_TX_IRQn,  1);
    NVIC_SetPriority (CAN2_RX0_IRQn, 1);
    NVIC_EnableIRQ   (CAN2_TX_IRQn);
    NVIC_EnableIRQ   (CAN2_RX0_IRQn);

Here's the code I did to pins PB5 and PB6:

/* Enable clock for CAN2 and GPIOB */
RCC->APB1ENR   |= (1 << 25) | (1 << 26);
RCC->AHB1ENR   |= (1 <<  1);
/* CAN2, use PB5, PB13 */
GPIOB->MODER   &= ~(( 3 << ( 5 << 1)) | ( 3 << (6 << 1)));
GPIOB->MODER   |=  (( 2 << ( 5 << 1)) | ( 2 << (6 << 1)));
GPIOB->OTYPER  &= ~(( 1 <<   5)       | ( 1 <<  6      ));
GPIOB->OSPEEDR &= ~(( 3 << ( 5 << 1)) | ( 3 << (6 << 1)));
GPIOB->PUPDR   &= ~(( 3 << ( 5 << 1)) | ( 3 << (6 << 1)));
 
 
GPIOB->AFR[0]  &= ~((15 << ( 5 << 2)) | (15 << ( 6 << 2)));
GPIOB->AFR[0]  |=  (( 9 << ( 5 << 2)) | ( 9 << ( 6 << 2)));
 
GPIOB->AFR[1]  &= ~(15 << ( 1 << 2));
GPIOB->AFR[1]  |=  ( 9 << ( 1 << 2));
 
/* Enable CAN2 interrupts */
NVIC_SetPriority (CAN2_TX_IRQn,  1);
NVIC_SetPriority (CAN2_RX0_IRQn, 1);
NVIC_EnableIRQ   (CAN2_TX_IRQn);
NVIC_EnableIRQ   (CAN2_RX0_IRQn);


Any ideia?

Outcomes