BT module HC-05 -incorrect incoming transmission

Welcome
In my program I use BT module HC-05 (9600 clock) connected to the RX and TX.
Because of the need to conserve memory microcontroller
(in the program instead of Serial.print () I use procedures like: usart_putc (), usart_puti (), usart_puts) SerialPort is configured as follows (from book Arduino Internals):

// Optimization monitor series
#define BAUD_RATE 9600
#define BAUD_RATE_DIVISOR (F_CPU / 16 / BAUD_RATE - 1)
(...)
void setup()
{
 // Open serial communications and wait for port to open:
 
 UCSR0A = 0 << TXC0 | 0 << U2X0 | 0 << MPCM0;
 UCSR0B = 0 << RXCIE0 | 0 << TXCIE0 | 0 << UDRIE0 | 0 << RXEN0 | 1 << TXEN0 | 0 << UCSZ02 | 0 << TXB80;
 UCSR0C = 0 << UMSEL01 | 0 << UMSEL00 | 0 << UPM01 | 0 << UPM00 | 0 << USBS0 | 1 << UCSZ01 | 1 << UCSZ00 | 0 << UCPOL0;

 UBRR0 = BAUD_RATE_DIVISOR;
(...)

When receiving (from application of Android) via the BT module long strings of characters
(like :
"0a1a2a3a4a5a6a7a8a9a10a11a12a13a14a15a16a17a18a19a20a-")

often getting the Arduino at the output of erroneous strings such as

(0a1a2a3ÿa4a5a6a7a8a9a10a11a12a13a14a15a16a17a18a19a20a
or other like
0ÿÿa1a2a3a4a5a6a7a8a9a10a11a12a13a14a15a16ÿa17a18a19a20a)

  • Containing inclusions letter unocode(signed) "ÿ".

From the few topics from the Internet It appears that ARDUINO reads 'ÿ' because there is no char to read in the buffer.

1)Is raising the serial port baud rate should help or incorrect transmission has other reasons?

Therefore, I want to try to change the bitrate from 9600 do19200bps.
I know (though not yet tried) to change the baundrate BT module (HC-05), but do not know how to do it in the Arduino code?

Is it enough to change
#define BAUD_RATE 9600
on
#define BAUD_RATE?

Do I need to make a change also in the line:
#define BAUD_RATE_DIVISOR (F_CPU / 16 / BAUD_RATE - 1).
If so, what changes?

Yours and I am counting on your help.

You need to configure the HC-05 in AT mode

http://www.martyncurrey.com/arduino-with-hc-05-bluetooth-module-at-mode/

Nick_Pyner:
You need to configure the HC-05 in AT mode

Arduino with HC-05 (ZS-040) Bluetooth module – AT MODE – Martyn Currey

I know that and this is no problem - though not yet tried.
I know the link but concerns the configuration of the speed-side HC-05.

My question (after a careful reading my post) refers to the speed configuration in Arduino code - side Arduino UNO.

You set the rate to match that of the HC-05 e.g

Serial.begin(115200);

or whatever...

I do not use the library serial.library so I do not use the command
Serial.begin (115200), etc.

Please read my post carefully (It's like I'm asking for fries and chips got information. both are potato but some others. :wink: )

Question is: how to modify the code below:

#define BAUD_RATE 9600
#define BAUD_RATE_DIVISOR (F_CPU / 16 / BAUD_RATE - 1)
(...)
void setup()
{
 // Open serial communications and wait for port to open:
 
 UCSR0A = 0 << TXC0 | 0 << U2X0 | 0 << MPCM0;
 UCSR0B = 0 << RXCIE0 | 0 << TXCIE0 | 0 << UDRIE0 | 0 << RXEN0 | 1 << TXEN0 | 0 << UCSZ02 | 0 << TXB80;
 UCSR0C = 0 << UMSEL01 | 0 << UMSEL00 | 0 << UPM01 | 0 << UPM00 | 0 << USBS0 | 1 << UCSZ01 | 1 << UCSZ00 | 0 << UCPOL0;

 UBRR0 = BAUD_RATE_DIVISOR;
(...)

to get the speed 19200bps ???

czosnekltd:
I do not use the library serial.library so I do not use the command
Serial.begin (115200), etc.

Ah, well, good luck to you. It is your prerogative to make an easy job hard but, when you stop banging your head against the brickwork, you might find it a pretty pointless exercise, which goes some way to explain why nobody does it very often. If you want Arduino to do something, you have to send instructions. A library is just a convenient way to do it for humans, and Arduino doesn't have much of an opinion on how the instructions go into the IDE, it just wants something from the compiler

Because of the need to conserve memory microcontroller ....

Do you mean that your sketch use so much memory that you need to reduce it by not using Serial.begin etc?

Maybe you could show your complete code, there could be improvements to do, instead of using low level instructions.

About baud speed, yes, from my tests, the greater the baud speed is, the less % of error you will get (because more characters are transmitted correctly), but you cannot completely avoid those errors unless you add some error detection and correction methods.

How far away is the HC-05 from your smartphone? These BT modules have a range of 10-15 meters, without walls or other obstacles.