AnsweredAssumed Answered

STM32 - USART3 Sending problem

Question asked by b.gui on Apr 14, 2013
Latest reply on Apr 15, 2013 by b.gui
Dear everyone,

I want to use the USART3 to send strings, but I don't know why it doesn't work. I saw multiple examples here on the forum and I think my code is quite good, I can't seem to make it works... Well, I want to send the data using the Wifly, I see the light on this one that it is receiving something, but when I receive it one my computer, I just see that I receive a one byte word. If I connect the USART3 Tx to another microcontroller that I know is working to send to a hyperterminal on my computer, I see nothing. So I think I'm only sending NULL messages.

Here is the code:
/* main.c
  * @brief  Main program.
  * @param  None
  * @retval None
int main(void)
  RCC_ClocksTypeDef RCC_Clocks;
  /* SysTick end of count event each 10ms */
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); 
  SystemCoreClock = RCC_Clocks.HCLK_Frequency;
  // USART3 configuration to send data
  * @brief  Initializes the USART3 to send data    (tx => pin PD8   ;   rx => pin PD9)
  * @param  None
  * @retval None
void USART3_Config(void)
  USART_InitTypeDef USART_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
  /*-------------------------- GPIO Configuration ----------------------------*/
  /* USART3 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
  /* GPIOC clocks enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  //configure AF
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);     // Tx
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);     // Rx
  /* Configure USART Tx and Rx as alternate function push-pull */
  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;      // before: GPIO_PuPd_NOPULL   UP
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  /* NVIC configuration ------------------------------------------------------*/
  /* Enable the interrupt Rx and Tx USART3 */
  NVIC_InitTypeDef NVIC_InitStructure;
  /* Configure the NVIC Preemption Priority Bits */
  NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;     // we want to configure the USART3 interrupts
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;    // this sets the priority group of the USART3 interrupts
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;       // the USART3 interrupts are globally enabled
  /* USARTx configuration ------------------------------------------------------*/
  /* USARTx configured as follow:
  - BaudRate = 9600 baud
  - Word Length = 8 Bits
  - One Stop Bit
  - No parity
  - Hardware flow control not 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_None;
  USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
  USART_Init(USART3, &USART_InitStructure); 
/* stm32f4xx_it.c
/* Private variables ---------------------------------------------------------*/
__IO uint8_t Counter = 0x00;
__IO uint8_t CounterUSART3 = 0x00;
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
void SysTick_Handler(void)
    Counter ++;
    if (Counter == 10){
      Counter = 0x00;
      char data[] = "/MessageToSend";
      char *d = data;
          //while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
          USART_SendData(USART3, *d);
void USART3_IRQHandler(void)
    CounterUART3 ++;
    if (CounterUART3 == 10){ 
        USART_SendData(USART3, 'D');
        CounterUART3 = 0x00;

I commented the while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); since it seems to go into an endless loop.

Also, my USART3_IRQHandler doesn't want to work. So am I having problem with interrupt ?

Maybe worth noting, this is only part of my code. I'm also using 9 ADC with DMA (pins: PA0, PA1, PA2, PA3, PA4, PB0, PB1, PC0, PC2), 6 PWM outputs (pins: PC6, PC7, PC8, PC9, PE5m PE6) and one digital input (pin: PB4) and this is on the STM32F4DISCOVERY. So maybe something with all this give problem to my USART3 ?

Thanks a lot for any input ! That would be well appreciated !!