0

I have to connect my SMT32f103rb to bluetooth module hc-05 and make a transmission between mobile phone connected to bluetooth module and computer. I connected it like:

  • hc05 VCC -> +5V stm
  • hc05 GND -> GND stm
  • hc05 TXD -> PA10 stm
  • hc05 RXD -> PA9 stm

Next step was to connect my phone to hc-05 using standard password(1234). It worked Then I downloaded serial bluetooth terminal (like hterm on windows) on my android device.

Now I have no idea what to do next. App connects to BT, but I don't know how to send it to computer. To configure my stm I use CubeIDE.

pprunner
  • 95
  • 7
  • What do you try exactly? connect your phone to the embedded bluetooth ? please give more detail ? The bluetooth on the stm32 is configured? it is in a slave mode etc.... – TZof Dec 26 '19 at 21:27
  • Yes sure. I'm trying to make few phones connect to BT module and send informations via for example mobile terminal (I also created my own app but I don't really this gonna work now). I created connection phone- HC05 and it is pared. I also didn't make any features on CubeIDE in configuration. – pprunner Dec 29 '19 at 18:39
  • I also have my own working program code that is using USART comunication between f103rb and hterm – pprunner Dec 29 '19 at 18:41

2 Answers2

1

i think you are following a tutorial like this : https://www.electronicshub.org/hc-05-bluetooth-module/

i do not know what app you exactly have and what data it sends. This is very likely the problem. Apps like the one used here are not very complicated, any BT communication in Android is based on theBluetoothAdapter class. You can write your own app easily following https://www.youtube.com/watch?v=iFtjox9_zAI or copy code from the net.

To add sending and receiving functionality cf Android sample bluetooth code to send a simple string via bluetooth

The sending and receiving is done using RfcommSockets to that an OutputStream is attached , this is in the code

 if(bondedDevices.size() > 0) {
            Object[] devices = (Object []) bondedDevices.toArray();
            BluetoothDevice device = (BluetoothDevice) devices[position];
            ParcelUuid[] uuids = device.getUuids();
            BluetoothSocket socket = device.createRfcommSocketToServiceRecord(uuids[0].getUuid());
            socket.connect();
            outputStream = socket.getOutputStream();
            inStream = socket.getInputStream();

and

public void write(String s) throws IOException {
outputStream.write(s.getBytes());

Alternatively load the app Bluetooth Terminal HC-05 from PlayStore and try with it https://play.google.com/store/apps/details?id=project.bluetoothterminal&hl=de

If you want to send an entire .apk file and not simple command strings you have to use another protocol / bluetooth profile option (FTP, OPP or OBEX) . For this get the app Bluetooth File Transfer https://www.androidpit.com/how-to-send-apps-with-bluetooth

For being able to send entire files you have to implement a file system on your STM32, else you can only write binary into memory with a program that reads the data from the Bluetooth receiving buffer and then copies it to memory as raw binary data.

(the technology behind transfering files with bluetooth is explained in http://www.diva-portal.org/smash/get/diva2:1020079/FULLTEXT01.pdf - File Transfer Using Bluetooth)

ralf htp
  • 9,149
  • 4
  • 22
  • 34
  • I have written my own apps, but I want to see how it wokrs using basic BT terminal on my phone. I downloaded it but the problem is i have no idea how to configure my stm so that HC-05 will receive data from phone. I tried for first time, simple program, if stm detects command 'on;' the led on stm will be toggled, and if it detects 'off;' the led on stm will not be toggled. I have written my own usart code but it works for windows terminal commands (like ledon, ledoff, pulse and blink) – pprunner Dec 29 '19 at 18:45
  • and refering to your first link ( https://www.electronicshub.org/hc-05-bluetooth-module/ ) this is the solution (help) I am looking for but to stm not arduino. Specifically the code- would be different, wouldn't it? – pprunner Dec 29 '19 at 18:55
  • yes the code is different but you can easily translate the Arduino stuff to STM32 HAL library code, i.e. `Serial.read()` is `HAL_UART_Receive(&s_UARTHandle, buffer, sizeof(buffer), HAL_MAX_DELAY);`, what you have to decide if you want this interrupt-baased or not. `Serial.send()` is `HAL_UART_Transmit(&s_UARTHandle, buffer, sizeof(buffer), HAL_MAX_DELAY);` cf also https://visualgdb.com/tutorials/arm/stm32/uart/hal/ – ralf htp Dec 29 '19 at 19:19
  • okay.. i am really as green as grass here. How about converting those serial(/1). begin(9600)? is it baud? I guess pinMode in arduiono is switching in pinout view in cubeIDE PA8 into output? – pprunner Dec 29 '19 at 21:07
  • 9600 is baud rate. i also have nothing to do with arduino. google yields that *pinMode* simply means pins are configured as GPIO, no extra functions... – ralf htp Dec 29 '19 at 21:22
  • So basically, if i have program that works with hterm on same computer where is my stm connected, what should i change to get information not from hterm but from phone? Do You have any ideas? – pprunner Dec 30 '19 at 08:07
1

configure you stm32 pinout you can use STMCubeMX software STM32: Set the pin PA9 and PA10 as UART.

STM32 have some USART functions avalaible in Keil IDE. You can see the ask that I answered STM32 HAL rx interrupt can't get bytes correctly

HAL_UART_Receive(&s_UARTHandle, buffer, sizeof(buffer); //receive data over usart
HAL_UART_Transmit(&s_UARTHandle, buffer, sizeof(buffer), HAL_MAX_DELAY);//send data

HC-05 read the datasheet to know which command AT must be sent: THE HC-05 must be configured as slave with the AT COMMAND AT+ROLE=0

All AT command are sended by USART

Embedded systems requires a lot of documentation reads, especially datasheet. hc-05 datasheet http://www.electronicaestudio.com/docs/istd016A.pdf

TZof
  • 150
  • 1
  • 7