AnsweredAssumed Answered

STM32L152 UART5 error.

Question asked by kupchyk.daniil on Jul 28, 2014
Latest reply on Jul 31, 2014 by Clive One
Good afternoon, I am trying to init UART5 on STM32L152 and it is work wrong.
In the end of the sw_uart5_init function 0xAA (0b10101010) value is sent to the UART5 data register. The transmission result, registred with osciloscope not same as value sent to the data register. Can you find a mistake in the code or give me some workaround how to solve this problem?
I'm really appreciate your help. 

PS. The same deal with DMA, corrupted data.

void sw_uart5_init(void)
{
   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC|RCC_AHBPeriph_GPIOD, ENABLE);
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
 
   GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5);
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5);
 
 // Configure GPIO pin : PD0 -> WS-VEN;  PD1 -> WS-FC
   GPIO_InitTypeDef      GPIO_InitStruct;              
   GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1; 
   GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
   GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
   GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
   GPIO_InitStruct.GPIO_Speed = GPIO_Speed_400KHz;
   GPIO_Init(GPIOD, &GPIO_InitStruct);
 
 //PC12   ------> UART5_TX
   GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;   
   GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
   GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
   GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
   GPIO_InitStruct.GPIO_Speed = GPIO_Speed_40MHz;
   GPIO_Init(GPIOC, &GPIO_InitStruct);
 
 //PD2   ------> UART5_RX
   GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;   
   GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
   GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
   GPIO_Init(GPIOD, &GPIO_InitStruct);
 
   USART_InitTypeDef     USART_InitStruct;
   USART_InitStruct.USART_BaudRate = 1200;
   USART_InitStruct.USART_WordLength = USART_WordLength_8b;
   USART_InitStruct.USART_StopBits = USART_StopBits_1;
   USART_InitStruct.USART_Parity = USART_Parity_No ;
   USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
   USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
   USART_Init(UART5, &USART_InitStruct);
   USART_Cmd(UART5, ENABLE);
 
   while (USART_GetFlagStatus(UART5, USART_FLAG_TC) == RESET);
 
 
   USART_SendData(UART5,0xaa);
}

uart5.jpg

Outcomes