0
\$\begingroup\$

I'm using a PIC24H Microchip microcontroller to communicate via UART with a Bluetooth Module. The Bluetooth module's baud rate can be configured at runtime via software (over bluetooth or over UART) and the baud rate will change after a power cycle.

Unfortunately the only way for the microcontroller to find out what baud rate the Bluetooth module's UART is using is by asking it--over UART.

Is there a way that I can have the microcontroller test (maybe by trial and error) what the baud rate of the bluetooth module is set to? It can only be a limited set of values and will probably be set to either 115K or 230K if that makes it easier.

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

I once had a similar problem with a microcontroller which didn't have a UART nor exactly known clock frequency (crystal was too expensive). I let the other party send a specific byte, for instance 0x01 and measured the time the bus was low. This was 8 bit times (startbit + 7 zeros of data). So dividing this by 8 I got the value I should set my timer to.
So, before you configure the I/O pins for UART use them as common I/O until the Bluetooth module sent this agreed upon character and time it. You could do this running a loop, or use timer capture to detect the falling and rising edges (more accurate).

\$\endgroup\$
5
  • 1
    \$\begingroup\$ One tip: in 8N1 the character U happens to send a nice half-baud clock signal (1010101010) which you could time and then halve to get the bit time (1/baud) \$\endgroup\$
    – Majenko
    Commented Jun 17, 2011 at 18:25
  • \$\begingroup\$ I'm not sure I could get the bluetooth module to send a byte like you describe, but that's an interesting idea. \$\endgroup\$ Commented Jun 17, 2011 at 18:27
  • \$\begingroup\$ @Matt's on the right track. Isn't this a mode of some UARTs on PICs? \$\endgroup\$
    – kenny
    Commented Jun 17, 2011 at 22:39
  • \$\begingroup\$ @kenny for receiving, yes, if it's one with the EUSART \$\endgroup\$
    – Majenko
    Commented Jun 17, 2011 at 23:23
  • 1
    \$\begingroup\$ @Matt - I chose the longer sequence because it gives a result one order of magnitude more accurate. Dividing by 8 is just shifting 3 bits. But any character will do. \$\endgroup\$
    – stevenvh
    Commented Jun 18, 2011 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.