AnsweredAssumed Answered

STM32F429I Discovery UART4 Data Problem

Question asked by kasapoglu.orkun on Mar 31, 2016
Latest reply on Mar 31, 2016 by Clive One
Hi. I'm trying to get what I've sent from UART4 port GPIOC10 (TX) GPIOC11 (RX). But every time I can't get what I've sent. For example I'm sending 0x10, reading 0x90.

Port settings; Baud = 9600kbps, 8-bit, Even Parity, 1 Stop bit, No hardware flow control

Initializing port with;

void serial_init(void)
{
  GPIO_InitTypeDef g;
 USART_InitTypeDef u;

 // GPIOA clk aktif
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
 // UART4 clk aktif
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);

 g.GPIO_Mode = GPIO_Mode_AF;
 g.GPIO_OType = GPIO_OType_PP;
 g.GPIO_PuPd = GPIO_PuPd_UP;
 g.GPIO_Speed = GPIO_Speed_50MHz;
 
 g.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
 
 GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);
 GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);
 
 GPIO_Init(GPIOC, &g);
 
 u.USART_BaudRate = 9600;
 u.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
 u.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
 u.USART_WordLength = USART_WordLength_8b;
 u.USART_Parity = USART_Parity_Even;
 u.USART_StopBits = USART_StopBits_1;
 
 USART_Init(UART4, &u);
 
 USART_ClearFlag(UART4, USART_FLAG_LBD | USART_FLAG_TC | USART_FLAG_RXNE);
 USART_ClearITPendingBit(UART4, USART_IT_ERR | USART_IT_FE | USART_IT_IDLE | \
                                USART_IT_LBD | USART_IT_NE | USART_IT_ORE | \
                                USART_IT_ORE_ER | USART_IT_ORE_RX | \
                 USART_IT_PE | USART_IT_RXNE | USART_IT_TC | \
                 USART_IT_TXE);
 
 USART_Cmd(UART4, ENABLE);

}

and testing it with;

void test_serial(void)
{
  //int i;
  USART_SendData(UART4, (uint16_t)0x10);
  while (USART_GetFlagStatus(UART4, USART_FLAG_TC) != SET);
  USART_ClearFlag(UART4, USART_FLAG_TC);
  //for (i = 0; i < 1000; ++i);
  while (USART_GetFlagStatus(UART4, USART_FLAG_RXNE) != SET);
  if ((uint8_t)USART_ReceiveData(UART4) == (uint8_t)0x10)
  {
    continue;
  }
}

I've added for test the //int i; and the //for... lines. Program doesn't reach the continue line.

Outcomes