AnsweredAssumed Answered

STM32L problem with USART --> DR empty after writing to it :(

Question asked by guzik.ireneusz on Jan 11, 2012
Latest reply on Jan 13, 2012 by Clive One
It's strange, I don't have a transmission with this function and I don't know why. State of registers after USART_Cmd(USART1, ENABLE) is:

SR -> 0x000000C0 (OK)
DR -> 0
BRR -> 0x00000683 (for HSI = 16 [MHz] -> OK)
CR1 -> 0x0000200C (OK)
CR2 -> 0
CR3 -> 0x00000300 (OK)
GTPR -> 0

In step-by-step working (debug in keil) i see that for example 'A' isn't written to DR(DR is still 0) I tried change USART1 for USART2 but problem wasn't solved.

void USART1forFUN(void)
{
     USART_InitTypeDef USART_InitStructure;
     GPIO_InitTypeDef GPIO_InitStructure;
 
/* Enable GPIOA and USART1 clock */
       RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
       RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
 
/* Connect P9 to USART1_Tx
      * Connect P10 to USART1_Rx
      * Connect P11 to USART1_CTS
      * Connect P12 to USART1_RTS
      */

       GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
       GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
       GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_USART1);
       GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_USART1);
 
/* Configure USART Tx and Rx as alternate function push-pull */
       GPIO_InitStructure.GPIO_Mode= GPIO_Mode_AF;
       GPIO_InitStructure.GPIO_Speed= GPIO_Speed_2MHz;
       GPIO_InitStructure.GPIO_OType= GPIO_OType_PP;
       GPIO_InitStructure.GPIO_PuPd= GPIO_PuPd_UP;
       GPIO_InitStructure.GPIO_Pin= GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
       GPIO_Init(GPIOA,&GPIO_InitStructure);
 
/* USARTx configured as follow:
       - BaudRate = 9600 baud 
       - Word Length = 8 Bits
       - One Stop Bit
       - No parity
       - Hardware flow control enabled (RTS and CTS signals)
       - Receive and transmit enabled
       */

     USART_InitStructure.USART_BaudRate=9600;
     USART_InitStructure.USART_WordLength= USART_WordLength_8b;
     USART_InitStructure.USART_StopBits= USART_StopBits_1;
     USART_InitStructure.USART_Parity= USART_Parity_No;
     USART_InitStructure.USART_HardwareFlowControl= USART_HardwareFlowControl_RTS_CTS;
     USART_InitStructure.USART_Mode= USART_Mode_Rx | USART_Mode_Tx;
     USART_Init(USART1,&USART_InitStructure);
 
/* Odblokowanie USART1 */
     USART_Cmd(USART1, ENABLE);
 
     USART_SendData(USART1,'A');
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE)== RESET);
     USART_SendData(USART1,'B');
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE)== RESET);
     USART_SendData(USART1,'C');
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE)== RESET);
     USART_SendData(USART1,'D');
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE)== RESET);
}

Outcomes