AnsweredAssumed Answered

USART3 send Data problem

Question asked by mac.sandrine on Mar 20, 2012
Latest reply on Mar 20, 2012 by fm
Hello,
I´m a newbie in microcontrollers and I'm just getting started with stm32f4 discovery.
I have this code below to send data through a wifi module  but i want to send data every 10 seconds. How can i do that? Does anyone can help me? Thank´s in advance!

int main(void)
{
    USART3Init();
    char str[] = "Testing...";
    char *s;
 
   while (1)
  {
      s=str;
      while(*s){
      while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
       USART_SendData(USART3, *s++);
       
      } 
  }
 return 1;
}
 
void USART3Init(void)
{
    USART_InitTypeDef USART_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
 
    /* Enable USART3 clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
 
    /* Connect PD8 and PD9 pins to AF */
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
 
    /* Configure USART3 Tx (PD8) as input floating */
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
    //speed
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    //
    GPIO_Init( GPIOD, &GPIO_InitStructure );
 
    /* Configure USART3 Rx (PD9) as input floating */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
    GPIO_Init( GPIOD, &GPIO_InitStructure );
 
    /* Initialise Structure USART3 */
    USART_InitStructure.USART_BaudRate = 9600;//9600
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;//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;
 
    /* Initialise USART3 */
    USART_Init(USART3,&USART_InitStructure);
 
    /* Enable the interrupt Rx USART3 */
    USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
 
    /* Enable the UART3 */
    USART_Cmd( USART3, ENABLE ); 
}

Outcomes