D.02. command 240: write to eeprom, Section 3.d.02 – Pololu Orangutan X2 User Manual

Page 20

Advertising
background image

bit 3: STATUS_BUZZER_FINISHED

— the buzzer has finished playing and is now silent. This bit

reflects the real-time state of the buzzer and is not cleared by reading the status byte.

bit 4: STATUS_M1_FAULT

— a fault has occurred with motor 1. This bit is latched and will remain set

until the status byte is read.

bit 5: STATUS_M1_CURRENT_HIGH

— the average motor 1 current has met or exceeded the specified

current limit. This bit will never be set if the specified current limit is zero (i.e. no current limit). This bit is
latched and will remain set until the status byte is read.

bit 6: STATUS_M2_FAULT

— a fault has occurred with motor 2. This bit is latched and will remain set

until the status byte is read.

bit 7: STATUS_M2_CURRENT_HIGH

— the average motor 2 current has met or exceeded the specified

current limit. This bit will never be set if the specified current limit is zero (i.e. no current limit). This bit is
latched and will remain set until the status byte is read.

Values sent: none

command byte = 218

3.d.02. Command 240: Write to EEPROM

Effect: This command writes a byte to the specified address of the mega168’s EEPROM. The EEPROM is
addressed by a 9-bit value (512 bytes of memory). Using this command can potentially be dangerous as it’s
possible to overwrite saved mega168 settings. You should be very careful when writing to any EEPROM address
that’s 23 or less. Addresses 24 – 32 are used to hold pointers to melodies, so these may be changed freely so long
as you’re not using the EEPROM to store melodies. Melody notes are stored sequentially in three-byte blocks
starting at EEPROM address 33. If you wish to store both melodies and custom data in the mega168’s EEPROM,
we suggest you start storing your data at the end of the EEPROM as the melodies are stored from the front.

If EEPROM is already being written, it is not possible to perform the write. When processing the command
byte, the SPI interrupt routine checks to see if it’s currently possible to write to the EEPROM. It will load the
value of the EECR’s EEPE bit (programming enable bit of the EEPROM control register) into bit zero of SPDR.
It is recommended you do not begin transmission of the first data byte until 3 us after the transmission of the
command byte has completed. This is to make sure the mega168 has time to load the SPDR. If SPDR is zero after
transmission of this first data byte, it is possible to perform the write, otherwise the write will not be allowed. The
second data byte should be sent regardless of this returned value, however.

This command should be used to save settings so that they persist after a hardware reset. This command can also
be used to restore settings to their factory defaults by clearing EEPROM byte zero.

Warning:

An EEPROM memory address can be written thousands of times, but not infinitely many. An

automated setup that writes to an EEPROM memory address over and over could potentially burn out that
memory address in a few minutes.

Values sent: EEPROM address (9 bits), write data (8 bits)

command byte = 240 | (MSB of write data byte << 2) | (bit 7 of write address << 1) | bit 8 of write address

data byte 1 = seven lowest bits of write address (bits 6 – 0)

data byte 2 = seven lowest bits of write data

Orangutan X2 Command Documentation v1.01

© 2001–2010 Pololu Corporation

3. Low-Level SPI Commands

Page 20 of 27

Advertising