Bootloader Modifications for Pro Mini 8mhz

So I have an atmel 168 running at 8mhz. I installed a pro8 bootloader, which should be expecting to communicate at 19200. There is a bluetooth module in my circuit which is connected to the UART on the 168. It is set to communicate at 115200. The arduino sketch which blinks an led based on serial commands is running at 19200. I'm sending commands using the Arduino IDE serial box. It is set to 19200 and I am using my laptop's built in bluetooth.

So everything is set to 19200 except the bluetooth module in the circuit. It is at 115200 and that is the only way it all works. I'm just wondering why. Is there something else I am missing or don't get yet?

thanks!

Hi wingnut87,

I also don’t understand this. What type of bluetooth module are you using? How do you know it is really set to 115200 baud?

Does the baudrate of your bt module depend on an external crystal or does it have an addidtional clock divider (prescaler)?

To use higher baud rates, you have to change the crystal value to a multiple of 1843200 Hz, otherwise the error of the resultant baud rate gets too high.

The boot loader uses a formula for the UBRR divider which gets a greater error for 115200 baud and 16 MHz crystal. For a 8 Mhz crystal even the modified formula doesn’t help, you will always have an error of +8.5% (125000 instead of 115200 baud).

Boot loader formula:    UBRR=((FOSC / 16)            / BAUD - 1)
HardwareSerial formula: UBRR=((FOSC / 16 + BAUD / 2) / BAUD - 1)

Here the table of the baudrate error using different CPU clocks:

CPU
clock
requested baudrate UBRR (floating point + 0.5) UBRR resultant baudrate error
8000000 230400 1,670138889 1 250000 8,51%
8000000 115200 3,840277778 3 125000 8,51%
8000000 57600 8,180555556 8 55555,56 -3,55%
8000000 38400 12,52083333 12 38461,54 0,16%
8000000 19200 25,54166667 25 19230,77 0,16%
8000000 9600 51,58333333 51 9615,385 0,16%
7372800 230400 1,5 1 230400 0,00%
7372800 115200 3,5 3 115200 0,00%
7372800 57600 7,5 7 57600 0,00%
7372800 38400 11,5 11 38400 0,00%
7372800 19200 23,5 23 19200 0,00%
7372800 9600 47,5 47 9600 0,00%
16000000 230400 3,840277778 3 250000 8,51%
16000000 115200 8,180555556 8 111111,1 -3,55%
16000000 57600 16,86111111 16 58823,53 2,12%
16000000 38400 25,54166667 25 38461,54 0,16%
16000000 19200 51,58333333 51 19230,77 0,16%
16000000 9600 103,6666667 103 9615,385 0,16%

See also here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1251415313#2

MikeT

One thing I forgot to mention is that I have Arduino BT selected as the board I am using in the IDE.

So in an earlier post, you were helping me compile the BT bootloader. One of the options was 115200 in the makefile. Am I correct in assuming the bluetooth module on the board must be communicating with the arduino at 115200 for the bootloader to accept a new program? On the arduino BT, it sounds like the bluetooth module is set to 115200. Does that mean that your arduino sketch must use the code:

Serial.begin(115200)?

I am aware of the highspeed problems, which is why I've been trying to run everything at 19200. I do have some intermittent problems which might be related. So when it only worked with the module configured to 115200, I was pretty confused.

By configured, I mean I connected to the module via bluetooth, entered command mode, and set the baud rate. It is the same as the instructions you gave me in the post where I removed those from the bootloader.

Also, when I select Arduino BT as my board in the IDE, various things change, one of which being how long the software will attempt to open a connection and upload a program. Is it possible to see and change these settings? I've looked around for files that allow me to make some adjustments, but have only found boards.txt under hardware, which does not seem to have it.

Am I correct in assuming the bluetooth module on the board must be communicating with the arduino at 115200 for the bootloader to accept a new program?

It depends on the setting of the bluetooth module and the bootloader. Both must match and your sketches have to use the same setting for Serial.begin(). You can also use 19200, 38400 or 57600.

So in an earlier post, you were helping me compile the BT bootloader. One of the options was 115200 in the makefile.

Be careful: The Arduino-BT bootloader ignores the baudrate setting from the Makefile, it uses a hardcoded constant. use a modified Duemilanove boot loader for my Arduino-BT and that's the reason for the 115200 in the Makefile.

On the arduino BT, it sounds like the bluetooth module is set to 115200. Does that mean that your arduino sketch must use the code: Serial.begin(115200)?

Yes, that's correct.

Also, when I select Arduino BT as my board in the IDE, various things change, one of which being how long the software will attempt to open a connection and upload a program.

The wait time in the boot loader of the Arduino-BT is longer and it might also take longer to open the bluetooth connection, but I don't think the IDE itself behaves differently. I couldn't find something specific by looking at the code (http://arduino.googlecode.com).

Is it possible to see and change these settings? I've looked around for files that allow me to make some adjustments, but have only found boards.txt under hardware, which does not seem to have it.

What do you want to change?

MikeT

So I read through the bootloader that most of the boards use and also the one for the BT. I know that all the 168 chip bootloaders run at 19200 and the 328 chips at 57600. Also, the BT bootloader runs at 115200. There are so many places to set the baud rate I just want to make sure I understand this. The rate in the bootloader determines the rate at which a new program is uploaded right?

In the files boards.txt, once again the 168 chips are set to 19200 and the 328 chips to 57600, but the BT is also set to 19200. Why is this? Is this where my computer must match the bootloader to work? If you make changes to the boards.txt do they take effect right away? Do I have to compile something?

I’m always worried I will make a change to something and assume it worked, but I was actually overridden by some other code. Or the changes didn’t take effect because of some other reason.

Thanks!
Tom

Hi Tom,

The rate in the bootloader determines the rate at which a new program is uploaded right?

Yes, this is the baudrate for the upload at the ATmega UART pins.

In the files boards.txt, once again the 168 chips are set to 19200 and the 328 chips to 57600, but the BT is also set to 19200.

This is the baudrate which avrdude uses for the PC serial port. As already mentioned, for the virtual Bluetooth serial ports this baudrate doesn’t matter. For FTDI USB serial ports, it has to match the UART baud rate of the ATmega.

Why is this?

I don’t know :slight_smile:
You can change it to 115200 baud if you feel better, but as said, it doesn’t matter.

Is this where my computer must match the bootloader to work?

For FTDI USB Arduinos: yes. For the Arduino-BT: doesn’t matter.

If you make changes to the boards.txt do they take effect right away?

You have to restart the Arduino-IDE to reload “boards.txt”.

When setting “upload.verbose=true” in “C:\Documents and Settings<username>\Application Data\Arduino\preferences.txt”, you can directly see what settings are used:

E:\arduino-0017\hardware/tools/avr/bin/avrdude
  -CE:\arduino-0017\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -pm168 -carduino
  -P\\.\COM21 -b19200 -D
  -Uflash:w:D:\Documents and Settings\michael\My Documents\Arduino\Boduino2\applet\Boduino2.cpp.hex:i 

avrdude: Version 5.8cvs, compiled on Nov  6 2009 at 22:28:43
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "E:\arduino-0017\hardware/tools/avr/etc/avrdude.conf"
         Using Port                    : \\.\COM21
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200

MikeT