AnsweredAssumed Answered

STM32F4-Discovery - USART problem

Question asked by dzikowski.bartlomiej on Oct 9, 2012
Latest reply on Oct 12, 2012 by Clive One
Hi,
I'm trying to connect together two USARTs. First is set as a transmitter and second as a receiver. I connect together two pins on the board PA9 - USART1_TX and PC7 USART6_RX. I have problem with receving data by USART6 from USART1. My program won't exit the loop - while(!(USART6->SR & USART_SR_RXNE)). My code looks like this:

int main(void)
{

 RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIOCEN;
 RCC->APB2ENR |= RCC_APB2ENR_USART1EN | RCC_APB2ENR_USART6EN; //USART clock enable

 GPIO_Port_Init (GPIOA, USART1_TX, GPIO_Mode_AF, GPIO_OType_PP, GPIO_Speed_25MHz, GPIO_PuPd_NOPULL);
 GPIO_Port_Init (GPIOC, USART6_RX, GPIO_Mode_AF, GPIO_OType_PP, GPIO_Speed_25MHz, GPIO_PuPd_NOPULL);
 GPIO_Port_Init (GPIOD, LED1_Green | LED2_Orange, GPIO_Mode_OUT, GPIO_OType_PP, GPIO_Speed_25MHz, GPIO_PuPd_NOPULL);
 
GPIO_Port_AF_Init(GPIOA, USART1_TX, GPIO_AF_USART1);
 GPIO_Port_AF_Init(GPIOC, USART6_RX, GPIO_AF_USART6);

 USART1->CR1 = 0x0000;
 USART1->CR2 = 0x0000;
 USART6->CR1 = 0x0000;
 USART6->CR2 = 0x0000;

 USART1->CR1 |= USART_CR1_UE; //USART enable
 USART6->CR1 |= USART_CR1_UE; //USART enable

 USART1->BRR = 84000000/9600;
 USART6->BRR = 84000000/9600;

 USART1->CR1 |= USART_CR1_TE; //transmitter enable
 USART6->CR1 |= USART_CR1_RE; //receiver enable

 while( !( USART1->SR & USART_SR_TXE )); //wait until DR register will be empty

USART1->DR = 'o'; //send data
 
while(!(USART1->SR & USART_SR_TC)); //wait for end of transmission

 while(!(USART6->SR & USART_SR_RXNE)); //wait for data in DR register 

uint16_t a = USART6->DR;
 
if (a=='o')
 {
    LED1_Green_on;
 }

 while (1)
 {

 }
}

Thanks in advance!

Outcomes