D.03. command 248: read from eeprom, D.04. command 254: check if eeprom is busy, Command (254 – Pololu Orangutan X2 User Manual

Page 21: Section 3.d.04

Advertising
background image

3.d.03. Command 248: Read from EEPROM

Effect: This command will read a byte from the specified address of the mega168’s EEPROM and return it to the
mega644 using the SPDR. The EEPROM is addressed by a 9-bit value (512 bytes of memory). When processing
the command byte, the SPI interrupt routine will check to see if it’s currently possible to read from 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 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 data byte, it is possible to perform the read, otherwise the read will not be allowed (the
only time a read is not allowed while a write is in progress) . After the transmission of the data byte completes, it
is recommended you wait another 3 us and then send a junk data byte or the NULL command. Upon completion
of this transmission SPDR will contain the byte stored at the specified EEPROM address, assuming the read was
allowed.

This command should be used to obtain the current mega168 settings if you need to figure out what they are.

Values sent: EEPROM address (9 bits)

command byte = 248 | (bit 7 of read address << 1) | bit 8 of read address

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

3.d.04. Command 254: Check If EEPROM Is Busy

Effect: This command will tell you if it’s possible to read from or write to the mega168’s EEPROM. Sending
a second byte (either the NULL command or a junk data byte) over the SPI once the return value is loaded will
transfer it to the mega644’s SPDR. It is recommended you do not begin transmission of this second 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, EEPROM is readable and writable. Otherwise, reading and writing are not
presently allowed. You may wish to send this command before attempting to read from or write to the mega168’s
EEPROM, though both the read and write commands also return success/failure indicators.

Note: if you are running firmware version 1.00, you should ensure EEPROM remains readable/writable for some
short duration (e.g. 300 us) before attempting a read or write. There is no need to do this if you are running
firmware version 1.01 or later.

Values sent: none

command byte = 254

3.d.05. Command 253: Get Firmware version (version = major byte . minor byte)

Effect: Returns the two bytes that specify the version of the code running on the mega168. The sequence for
obtaining this data is as follows:

1. send the command byte, wait for transmission to complete

2. wait for 3 us (so the mega168 has time to set the SPDR)

3. send any data byte, wait for transmission

4. read SPDR to obtain the major version byte

5. wait for 3 us (so the mega168 has time to set the SPDR)

6. send a junk data byte or the NULL command, wait for transmission

Orangutan X2 Command Documentation v1.01

© 2001–2010 Pololu Corporation

3. Low-Level SPI Commands

Page 21 of 27

Advertising