cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 using the USART

sam239955
Associate II
Posted on September 29, 2011 at 13:30

Hi,

I'm trying to use the USART from the STM32F103ZE to communicate with my Bluetoothmodul.

In Adruino I use the USART like this:

void setupBlueToothConnection()

{

    blueToothSerial.begin(38400);

    delay(1000);

    sendBlueToothCommand(''\r\n+STWMOD=0\r\n'');

    sendBlueToothCommand(''\r\n+STNA=SeeduinoBluetooth\r\n'');

    sendBlueToothCommand(''\r\n+STAUTO=0\r\n'');

    sendBlueToothCommand(''\r\n+STOAUT=1\r\n'');

    sendBlueToothCommand(''\r\n +STPIN=0000\r\n'');

    delay(2000); // This delay is required.

    sendBlueToothCommand(''\r\n+INQ=1\r\n'');

    delay(2000); // This delay is required.

}

But how can I send this command's with the STM32  USART, I didnt found a solution?

regards

Alex

#yet-another-example
1 REPLY 1
Posted on September 29, 2011 at 15:24

The forum, the FW library, and Keil/IAR, are replete with example code

 

..

  USART_InitTypeDef USART_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); /* Enable GPIO A for USART2 Rx,Tx Pins */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* Enable USART2 Clock */

  /* Configure USART2 Tx (PA.02) as alternate function push-pull */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Configure USART2 Rx (PA.03) as input floating */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  USART_InitStructure.USART_BaudRate            = 38400;

  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);

  USART_Cmd(USART2, ENABLE);  /* Enable the USART */

..

See your other thread for string output code using the FW library

void send_string(const char *s)

{

  while(*s)

  {

    while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);

    USART_SendData(USART2, *s++);

  }

}

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..