AnsweredAssumed Answered

USART STM32F4 PROBLEM

Question asked by claude.antoine on Mar 26, 2014
Latest reply on Mar 27, 2014 by claude.antoine
Hi, I have an error in my code and I can not seem identifying the problem
The erreur is : ..\main.c(97): error:  #169: expected a declaration
This is my code 

/**************************************************************************************/
 #include "stm32f4_discovery.h"
 #include <stm32f4xx_usart.h>
  GPIO_InitTypeDef GPIO_InitStructure;
         USART_InitTypeDef USART_InitStructure;
void RCC_Configuration(void);
void GPIO_Configuration(void);
void USART1_Configuration(void);
void RCC_Configuration(void)
{
  /* --------------------------- System Clocks Configuration -----------------*/
  /* USART1 clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
 
  /* GPIOA clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOD, ENABLE);
}
 
/**************************************************************************************/
 
void GPIO_Configuration(void)
{
 
  /*-------------------------- GPIO Configuration ----------------------------*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
 
  /* Connect USART pins to AF */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);   // USART1_TX
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);  // USART1_RX
     
       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
}
 
/**************************************************************************************/
 
void USART1_Configuration(void)
{


 
  /* USARTx configuration ------------------------------------------------------*/
  /* USARTx configured as follow:
        - BaudRate = 9600 baud
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (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_None;
 
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
 
  USART_Init(USART1, &USART_InitStructure);
 
  USART_Cmd(USART1, ENABLE);
}
 
/**************************************************************************************/
 char test;
int main(void)
{
    RCC_Configuration();
 
    GPIO_Configuration();
 
  USART1_Configuration();
 
   while(1)
  {
    uint16_t Data;
 
    while(USART_GetITStatus(USART1, USART_IT_RXNE) == RESET); // Wait for Char
 
    Data = USART_ReceiveData(USART1); // Collect Char
 
    while(USART_GetITStatus(USART1, USART_IT_TXE) == RESET); // Wait for Empty
 
    USART_SendData(USART3, Data); // Echo Char
  }
 
  while(1); // Don't want to exit
}
}

Outcomes