AnsweredAssumed Answered

USART Problems

Question asked by moreira.luis.001 on Oct 26, 2012
Latest reply on Apr 28, 2013 by jacks.michael
Hi Guys,
Been trying to get the USART to work for a couple of days now and is time to get some help...
This is my code:

GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
  * @brief  Main program
  * @param  None
  * @retval None
int main(void)
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);  
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);    
  /* GPIO Pins configuration for Alternative Function */
/* for TX Pin */   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;             
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;    
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;  
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;  
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
/* for RX Pin */   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;             
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;    
  //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  
  //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;  
  //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOD, &GPIO_InitStructure); 
    /* USARTx configured as follow:
        - BaudRate = 115200 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(USART2, &USART_InitStructure);
  /* Output a message on Hyperterminal using printf function */
  //printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");
    //RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
    //RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
    USART_SendData(USART2, (uint8_t) 0x31);
  while (1)

I tried pretty much all the USARTs on the board and I can not send anything.
I looped back the TX & RX pins on my USB to Serial converter and that works fine.
The processor seems to be cycling fine thorough the code when on Debug.
I am complety at a loss why the program will not work, Any assistance would be appreciated.
Best Regards