2013-07-02 09:51 AM
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?2013-07-02 10:08 AM
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.2013-07-15 07:35 AM
// 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);