Pololu Orangutan X2 User Manual
Page 16

in normal mode:
baud = ( 20 MHz / 16 ) / ( UBRR + 1 ) = 1.25 MHz / ( UBRR + 1 ), so
UBRR = ( 1.25 MHz / baud ) – 1
in double-speed mode:
baud = ( 20 MHz / 8 ) / ( UBRR + 1 ) = 2.5 MHz / ( UBRR + 1 ), so
UBRR = ( 2.5 MHz / baud ) – 1
Note: If you are using firmware version 1.00, you must give the mega168 time to set its serial parameters to the
desired values before issuing a serial-transmit command. We recommend you wait at least 50 us after sending a
Set Serial Parameters command before attempting to use the UART. No such delay is needed if you are running
version 1.01 or later.
In addition to the serial setting parameters described above, there is a flag that can put the mega168 into
permanent program mode
, which means that incoming packets over the UART are treated as an attempt to
program the mega644. When set, all other serial parameters sent along with this command are ignored as the
UART is now reserved solely for programming. If put into permanent program mode, the mega644 can be
programmed without requiring the reset button be held until the yellow LED lights. Using permanent program
mode therefore can be more convenient for you if you’re doing a lot of incremental software development for the
mega644, but the tradeoff is that you cannot use the serial port for any other purpose (such as debugging, logging
values, etc).
In permanent program mode, the mega168 and mega644 will run normally until the mega168 receives a command
over the UART that it is to enter programming ISP mode. At this point the mega168 becomes the SPI master and
the mega644 is held reset. When the mega168 receives the UART command to leave programming ISP mode at
the completion of the ISP action, it will reset itself and the two microcontrollers will once again run normally.
If the save-to-EEPROM bit is one, these serial settings will persist after a hardware reset. Three EEPROM bytes
are used to encode these settings (one byte for UBRRH, one byte for UBRRL, and one byte for the rest). The
EEPROM encoding differs from the SPI encoding:
EEPROM byte 13: (permanent program mode bit << 6) |
(2-bit parity << 4) |
(stop-bits bit << 3) |
(2x-speed bit << 1)
EEPROM byte 14: UBRRH
EEPROM byte 15: UBRRL
If you want to store the permanent program mode setting so that you will still be in that mode after a hardware
reset, you can accomplish this by writing 0x40 to EEPROM byte 13. Warning: the parameters that are stored
in EEPROM can be written thousands of times, but not infinitely many. An automated setup that rewrites a
parameter over and over could potentially burn out the memory in a few minutes.
Values sent: baud (11 bits — UBRRH and UBRRL), 2x speed (1 bit), parity (2 bits), one or two stop bits (1 bit),
permanent program mode (1 bit), save to EEPROM (1 bit)
command byte = 200 | (2-bit parity << 1) | save to EEPROM bit
Orangutan X2 Command Documentation v1.01
© 2001–2010 Pololu Corporation
3. Low-Level SPI Commands
Page 16 of 27