cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429I Discovery UART4 Data Problem

Posted on March 31, 2016 at 11:00

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.
3 REPLIES 3
Posted on March 31, 2016 at 11:42

You are in fact in 7E1 mode, for 8E1 you would need to set it in 9-bit mode, as the parity is included in the length.

You also need to mask the data register on reads, in this 7-bit mode, mask with 0x7F

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on March 31, 2016 at 11:48

Thanks clive1. So in 9-bit mode, I need 0xFF

Posted on March 31, 2016 at 11:53

Yes depending on the width of the variable you put it in. The DR is 16-bit wide at the bus interface.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..