8 years, 5 months ago.

Nucleo STM32L053R8 and HC-05

Hello mbed developers, I'm having trouble understanding the following code for the bluetooth module HC-05 to interract with the kit

  1. include "mbed.h"

Serial pc(USBTX, USBRX); Serial device(PTC17, PTC16);

int main() { device.baud(9600); pc.baud(9600); while (1) { if(pc.readable()) { device.putc(pc.getc()); } if(device.readable()) { pc.putc(device.getc()); } } } Please if anyone can provide me some explanations or a better solution, I'd be grateful.

1 Answer

8 years, 5 months ago.

Please use the <<code >> and <</code>> tags on separate lines around your posted code to keep it readable.

The code example defines two separate serial ports. One is the serial port to a terminal program on your host pc, the second is a port that should be connected to the serial interface of the hc05. The software will then enter an endless loop to just transparantly forward all received characters between the host pc and hc05. You can use that to manually configure or test the hc05. The problem is that the serial pins for the hc05 are identified as ptc17, ptc16. These are not valid pinnames for the nucleo. The code was written for another platform. Modify the pins and compile for the nucleo.