Skip to main content
Graduate II
January 6, 2024
Solved

UART doesn't receive data from HC-06

  • January 6, 2024
  • 3 replies
  • 4230 views

Hello ! 
My STM board is STM32-L073RZ. 

I've had a lot of problem with HC-06, tried to somehow send the command "AT" or "AT\r\n", but I didn't get anything back. The bluetooth wasn't connected to any device because the diode was blinking. 

- I tried changing the Baund Rate from 9600 to higher it didn't work.
- I've tried to add Pull up on TX,RX (I've read maybe it doesn't have internal so I've added but it didn't work) : 

Xenon02_0-1704552517089.png

- I've even took off the voltage divider and it didn't work, It was added from the start like in this example : 

Xenon02_1-1704552588281.png

Here is the code : 

 char response[100] = "";

 while (1)
 {
	 // Send AT command to HC-06
	 char atCommand[] = "AT\r\n";
	 HAL_UART_Transmit(&huart2, (uint8_t *)atCommand, sizeof(atCommand)-1, 500);

	 // Add a delay to allow time for the HC-06 to process the command
	 HAL_Delay(1000);

	 // Handle the response from HC-06 (you may need to implement a function to receive and process data)
	 // For simplicity, you can use a blocking receive function like HAL_UART_Receive.

	 // Example of receiving response
	 HAL_UART_Receive(&huart2, (uint8_t *)response, sizeof(response)-1, 500);
	 response[sizeof(response)-1] = '\0'; // Null-terminate the string
	 printf("%s --\n", response);
	 // Process or print the received response as needed
 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */
 }

 
I also thought that Arduino didn't add pull up for the HC-06 but maybe they have always turned on ? So I have to add pull up for STM32, I did but it still didn't work. I was expecting and "OK" response instead I had "--" and the response array was empty. 

I don't know where is the error. 

    This topic has been closed for replies.
    Best answer by STTwo-32

    You can find all solder bridges in the cad ressource of the board.

    The best solution to keep using the ST-LINK without issue is to use another USART interface.

    Best Regards.

    STTwo-32 

    3 replies

    Super User
    January 6, 2024

    Hi,

    Leave away the R1/2 , both chips are at 3v3 signal level.

    set : 9600 , 8N1 ;

    AND HC-06 is slave , so you only can connect from your mobile to the hc06 , not other way.

    Xenon02Author
    Graduate II
    January 6, 2024

    Here is the actual setting for the UART : 

    Xenon02_0-1704555557333.png

    I think it is the same like you've described "9600 , 8N1 ;"
    And I've also taken of the R1 and R2, but it still doesn't work. 

    >"AND HC-06 is slave , so you only can connect from your mobile to the hc06 , not other way." 

    So I cannot send a TX command to the bluetooth ? I am trying for now send the command to the bluetooth via STM32, so to see if it works and speaks with my STM. 

    Super User
    January 6, 2024

    8N1 , yes, ok.

    +

    Why using uart2 , which is connected to st-link onboard ?

    Try with uart1 , PA9 + 10 .

    (or remap inCube uart2 to pins PA14 + 15 , if possible )

    +

    HC-06 module first should be accessed by BT-master, maybe your mobile . (try: connect there)

    When connected, you can send ... then.

     

     

    Technical Moderator
    January 6, 2024

    Hello @Xenon02 

    According to the UM1724:

    "The USART2 interface available on PA2 and PA3 of the STM32 microcontroller can be connected to ST-LINK MCU, ST morpho connector, or to ARDUINO® connector. The choice can be changed by setting the related solder bridges. By default, the USART2 communication between the target STM32 and ST-LINK MCU is enabled, in order to support virtual COM port for Mbed™ (SB13 and SB14 ON, SB62 and SB63 OFF). If the communication between the target STM32 PA2 (D1) or PA3 (D0) and shield or extension board is required, SB62 and SB63 must be ON, while SB13 and SB14 must be OFF. 

    So, you can keep using the USART2 interface by closing the SB62 and SB63 and opening the SB13 and SB14. Or you can  use another USART interface.

    Best Regards.

    STTwo-32 

    Xenon02Author
    Graduate II
    January 6, 2024

    What is "SB13 and SB14 ON, SB62 and SB63 OFF" where can I find it ?
    I am using the Arduino connectors which is D0 and D1, and set the pull up in both D1 and D0. 

    Super User
    January 6, 2024

    [line 10]

     

    // Add a delay to allow time for the HC-06 to process the command
    HAL_Delay(1000);

     

    This delay possibly is the culprit. It causes you to miss the reply of HC06. The "HAL" library won't magically buffer the serial input like Arduino does.