cancel
Showing results for 
Search instead for 
Did you mean: 

UART doesn't receive data from HC-06

Xenon02
Senior

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. 

1 ACCEPTED SOLUTION

Accepted Solutions

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 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

10 REPLIES 10
AScha.3
Chief II

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.

If you feel a post has answered your question, please click "Accept as Solution".
STTwo-32
ST Employee

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 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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. 

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. 

When I read it again I want to ask one more question. If I turn on USART2, and change it to work for peripherals and not for ST-Link, will my ST-link(OpenOCD) connection work without this PA2 and PA3 ? Because I don't understand if it will work without them why PA2 and PA3 are connected to ST-link. 

As I understood when I turn on the USART2 the active pins are the ST Link pins (CN2) ? :

Xenon02_2-1704556516796.png

There are 4 pins but I guess when USART2 is on then 2 pins from those 4 are active and D1 and D0 aren't functioning as USART ? I don't know.



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.

 

 

If you feel a post has answered your question, please click "Accept as Solution".

Pull a schematic for the board from the "CAD Resources" tab of the product.

The NUCLEO-64 boards can be difficult as the UART resource for the ST-LINK and ARDUINO D0/D1 are shared and there are solder bridges (or zero ohm resistors, aka wire) that get to determine exact connectivity.

If you want to keep using the ST-LINK/V2 VCP I'd suggest you find alternate UART and PINS to facilitate that, and wire to those.

The HC-06 should be signalling at 3.3V, so you don't need voltage dividers to connect the STM32

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

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 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Pavel A.
Evangelist III

[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.