Pages: 1 [2]   Go Down
Author Topic: Bootloader Modifications for Pro Mini 8mhz  (Read 3086 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi wingnut87,

Quote
Now I would like to tweak the loader for the Arduino BT, but there is now makefile

just copy the Makefile from the "atmega" directory and insert the following section (just before "isp: $(TARGET)" line):
Code:
bt: TARGET = bt
bt: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3' -DBAUD_RATE=115200L '-DARDUINO_BT' '-DWATCHDOG_MODS'
bt: AVR_FREQ = 16000000L
bt: $(PROGRAM)_bt.hex

bt_isp: bt
bt_isp: TARGET = bt
bt_isp: HFUSE = DD
bt_isp: LFUSE = FF
bt_isp: EFUSE = 00
bt_isp: isp

To compile the bootloader use
Code:
make bt
I modified the wait time before leaving the bootloader and starting the sketch (-DMAX_TIME_COUNT=F_CPU>>1) and enabled the watchdog timer support (-DWATCHDOG_MODS).

Theoretically you can use the "bt_isp" target to program the ATmega, but I never tried this because I use a different programmer.

  MikeT


Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Mike, I was able to generate a hex file, but when I tried to burn the bootloader through the IDE, I got this message:

avrdude: ERROR: address 0x4010 out of range at line 129 of /Applications/Arduino.app/Contents/Resources/Java/hardware/bootloaders/bt/ATmegaBOOT_168.hex
avrdude: write to file '/Applications/Arduino.app/Contents/Resources/Java/hardware/bootloaders/bt/ATmegaBOOT_168.hex' failed

I also tried compiling the c file with avr studio.  It uploaded to the chip, but does not seem to do anything.  Led does not blink.  Any ideas?

Thanks!
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi wingnut87,

the ATmega168 on the Arduino-BT has 16kB flash and 2kB boot loader section (when fuses BOOTSZ0=0 and BOOTSZ1=0) at the end, starting at 0x3800. It seems your bootloader is some bytes too large, the maximum address must be less than 0x4000.

Have you used the original bootloader or did you modify it?

You can omit the following code from the boot loader, because it is not really needed:
Code:
  //message("SET BT PAGEMODE 3 2000 1");    
putch('S');
putch('E');
putch('T');
putch(' ');
putch('B');
putch('T');
putch(' ');
putch('P');
putch('A');
putch('G');
putch('E');
putch('M');
putch('O');
putch('D');
putch('E');
putch(' ');
putch('3');
putch(' ');
putch('2');
putch('0');
putch('0');
putch('0');
putch(' ');
putch('1');
putch(0x0D);

  
        //put_s("SET BT ROLE 0 f 7d00");  
      putch('S');
      putch('E');
      putch('T');
      putch(' ');
      putch('B');
      putch('T');
      putch(' ');
      putch('R');
      putch('O');
      putch('L');
      putch('E');
      putch(' ');
      putch('0');
      putch(' ');
      putch('f');
      putch(' ');
      putch('7');
      putch('d');
      putch('0');
      putch('0');
      putch(0x0D);


These commands make sure, that some settings of the WT-11 are restored to usable values.

If you need this feature, you better send the following commands once to the WT-11 in command mode (refer also to http://www.arduino.cc/en/Main/ArduinoBTInitializationSketch):
Code:
Serial.println(" SET CONTROL BIND 1 20 RISE SET BT AUTH * 12345");
  Serial.println(" SET CONTROL BIND 2 20 RISE SET CONTROL BAUD 115200,8n1");
  Serial.println(" SET CONTROL BIND 3 20 RISE SET BT PAGEMODE 3 2000 1");
  Serial.println(" SET CONTROL BIND 4 20 RISE SET BT ROLE 0 f 7d00");
  Serial.println(" SET CONTROL BIND 5 20 RISE SET CONTROL ECHO 0");
  Serial.println(" SET CONTROL BIND 6 20 RISE SET CONTROL ESCAPE - 00 1");
  Serial.println(" SET CONTROL BIND 7 20 RISE SET CONTROL CONFIG 102D");

To activate this commands, you need to apply LOW->HIGH edge (3,3V) at GPIO pin 5 of the WT-11 (pin 9 of connector SV2).
 

  MikeT

« Last Edit: November 26, 2009, 01:23:57 pm by nospam2000 » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Mike, I was able to get everything working.  Now I'm just wondering why it works.  I basically have a circuit similar to the arduino bt, but am running it at 8mhz for power reasons.  I ended up using a pro mini 168 8mhz bootloader.  I read through the bootloader and makefile and it should be running at 19200.  Then my program is running at 19200 for serial communication.  The weird thing is that is only works if my bluetooth module is configured to 115200 communication.  Why does this work, and only work this way?  I can communicate with my program via bluetooth, (i.e. serial commands control leds), but the arduino serial window is set at 19200.  I'm confused smiley-sad

thanks so much for your help so far!
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi wingnut87,

the baudrate of UART interface of the WT-11 bluetooth chip is totally independent of the transmission speed of the Bluetooth interface. The same is true for the baudrate of virtual Bluetooth COM ports on the PC, this means the PC baudrate is not relevant for this type of ports.

Which program do you mean with
Quote
Then my program is running at 19200 for serial communication.
the program on the ATmega or on the PC side?


Quote
The weird thing is that is only works if my bluetooth module is configured to 115200 communication

Which Bluetooth module do you mean?
A) the Bluetooth module connected to the ATmega
B) an extra Bluetooth module connected to a UART COM port of you PC
C) an extra Bluetooth module connected to a USB COM port of you PC (e.g. via FTDI)
D) a Bluetooth (USB) dongle

  MikeT
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
 
Code:
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 baudrateUBRR (floating point + 0.5)UBRRresultant baudrateerror
80000002304001,67013888912500008,51%
80000001152003,84027777831250008,51%
8000000576008,180555556855555,56-3,55%
80000003840012,520833331238461,540,16%
80000001920025,541666672519230,770,16%
8000000960051,58333333519615,3850,16%
73728002304001,512304000,00%
73728001152003,531152000,00%
7372800576007,57576000,00%
73728003840011,511384000,00%
73728001920023,523192000,00%
7372800960047,54796000,00%
160000002304003,84027777832500008,51%
160000001152008,1805555568111111,1-3,55%
160000005760016,861111111658823,532,12%
160000003840025,541666672538461,540,16%
160000001920051,583333335119230,770,16%
160000009600103,66666671039615,3850,16%

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

 MikeT
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Quote
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.

Quote
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.

Quote
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).

Quote
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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Tom,

Quote
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.

Quote
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.

Quote
Why is this?

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

Quote
Is this where my computer must match the bootloader to work?
For FTDI USB Arduinos: yes. For the Arduino-BT: doesn't matter.

Quote
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:
Code:
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
Logged

Pages: 1 [2]   Go Up
Jump to: