cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F207IF use of CAN2

felipe
Associate II
Posted on July 02, 2013 at 18:51

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?

2 REPLIES 2
Posted on July 02, 2013 at 19:08

So I guess it is a problem with the pin configuration

Or how the transceiver is configured, or if loop back is connected.

Try making it work with the standard library examples, I have little interest in looking up register bit patterns. These settings don't look unreasonable, start looking at your other code, and the hardware attached.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
felipe
Associate II
Posted on July 15, 2013 at 16:35 Hi Again, I put it working with the library. But I have no sucess with the keil exemple code and I really want to use this because the code work with the RTX tasks. I am almost sure that the error is something with the configuration:

// 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

));
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);