cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 Discovery + HC-05 bluetooth + PC putty

robert239955
Associate II
Posted on August 11, 2014 at 15:16

Hello,

i am new to forum, and also to stm32 discovery. So please some patience :).

I am trying to send from discovery to PC.

Tried with USART6 + UART2USB and in putty on PC everything works.

Then i connected HC-05 to same USART6, just set baudrate to 38400 and tried again.

Everytime i reset whole system (connecting BT, running code) in manage to get 2 character aA but then just ▒  signs. I do not understand, what i missed. My code in bellow. I tried to lower to 9600 without success.

Any idea or advice for lost begginer?

thank you for help, with regards

Robert

my code:

/* Includes ------------------------------------------------------------------*/

#include ''main.h''

#include ''stm32f4xx.h''

#include ''stm32f4_discovery.h''

/* Private variables ---------------------------------------------------------*/

static __IO uint32_t uwTimingDelay;

RCC_ClocksTypeDef RCC_Clocks;

/* Private function prototypes -----------------------------------------------*/

static void Delay(__IO uint32_t nTime);

void RCC_Configuration(void) {

    /* ENABLE CLOCKS         */

         

    /* GPIOC clock enable */

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

        /* USART6 */

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);

}

void GPIO_Configuration(void) {

    GPIO_InitTypeDef GPIO_InitStructureUSART;

    GPIO_InitStructureUSART.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

    GPIO_InitStructureUSART.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructureUSART.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructureUSART.GPIO_PuPd = GPIO_PuPd_NOPULL;

    GPIO_InitStructureUSART.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOC, &GPIO_InitStructureUSART);

    GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);

    GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);

}

void USART_Configuration(void) {

    USART_InitTypeDef USART_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(USART6, &USART_InitStructure);

    USART_Cmd(USART6, ENABLE);    

}

int main(void)

{

  /* SysTick end of count event each 10ms */

  RCC_GetClocksFreq(&RCC_Clocks);

  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

    uint8_t Data;

    RCC_Configuration();

    GPIO_Configuration();

    USART_Configuration();

    while (1)

  {

           

    //a 

    Data = 0x61; 

    while(USART_GetFlagStatus(USART6, USART_FLAG_TXE) == RESET); // Wait for Empty

    USART_SendData(USART6, (uint8_t) Data); // Echo Char

    

    //A 

    Data = 0x41; 

    while(USART_GetFlagStatus(USART6, USART_FLAG_TXE) == RESET); // Wait for Empty

    USART_SendData(USART6, (uint8_t) Data); // Echo Char

    

  Data = 0;

    

  /* Insert 50 ms delay */

  Delay(20);

      

  /* Infinite loop */

  

  }

}

void Delay(__IO uint32_t nTime)

  uwTimingDelay = nTime;

  while(uwTimingDelay != 0);

}

/**

  * @brief  Decrements the TimingDelay variable.

  * @param  None

  * @retval None

  */

void TimingDelay_Decrement(void)

{

  if (uwTimingDelay != 0x00)

  { 

    uwTimingDelay--;

  }

}

0690X000006059WQAQ.png

8 REPLIES 8
Posted on August 11, 2014 at 16:27

So indicative that the wireless link fails..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
robert239955
Associate II
Posted on August 11, 2014 at 17:07

Ok, so this could indicate failed connection - means that on discovery would be everything right, i have to find out, why connection fails ...

Just one thing ... I send char every 0,2 seconds to PC- and when connection fails, this should stop ( i think). But every 0,2 i get one 

▒ 

sign. Like discovery is still sending, just something is wrong with data. Is this logical? I do not belive, that putty has some cache and shows randomly. And if i debug step by step when i click next, then i get next char, so putty is still under control of MC.

 

 

 

with regards, Robert

 

 

From: clive1

Posted: Monday, August 11, 2014 4:27 PM

Subject: STM32F407 Discovery + HC-05 bluetooth + PC putty

So indicative that the wireless link fails..

Posted on August 11, 2014 at 18:05

The code is not unreasonable, you could perhaps use 2-stop bits, but I don't think this is a synchronization issue.

You could also use other terminal applications, like RealTerm or TeraTerm.

You could use a scope or logic analyzer, and confirm for yourself that the data coming out of the STM32 is correct. You could also fork the TX output and connect that via a USB-to-CMOS-Serial adapter in addition to the BlueTooth route.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
stm32forum
Associate II
Posted on August 11, 2014 at 22:05

Default baudrate is 9600 unless you have changed it with the AT commands or pin34 is at high level.

Would advice you to spend a bit more money for example for a http://www.lairdtech.com module, they are so much better and well documented then the chinees modules with there crapy translated manuals.

robert239955
Associate II
Posted on August 11, 2014 at 22:51

Hello,

thank you for ideas, will try.

with regards, Robert

robert239955
Associate II
Posted on August 11, 2014 at 22:54

Hello,

thank you for advice. As this is personal low budget project on Faculty, can not afford at the moment, maybe later. It is more learning project than real use project.

with regards, Robert

Posted on August 11, 2014 at 23:06

Got some 3DR type devices using the HopeRF

https://store.3drobotics.com/products/3dr-radio-915-mhz-air-module

design with the SiK firmware that are relatively low cost and have quite a throw to them. Cheaper on eBay

And there's

http://www.thisisant.com/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
robert239955
Associate II
Posted on August 12, 2014 at 21:47

Hello,

thank you for advice, but discovery>BT>PC is just for testing. I want to get data to Android, so i need something smartphone supports :\ ... and for the moment BT is most used.

I thought about some uart/wifi modul, but i did not yet reserched, how complicated this would be. I need 2 way comunnication. In this case, also iPhone iis in reach.

with regrads, Robert