1

With regards to Arduino EEPROM when writing and reading to certain EEPROM devices it asks for a transmission of the following format:

Wire.beginTransmission(ADDR);
Wire.write(highADDR);
Wire.write(lowADDR);
Wire.write(data);
Wire.endTransmission();

What do the high address and low address mean? Why can I not just tell it to write to the byte at address 4. Why do I need to prove a high and low?

Jister13
  • 149
  • 1
  • 13

1 Answers1

1

It looks to me like you are using I2C, I am going to make that assumption and base my answer off of it. Perhaps you should clarify which EEPROM you are using.

The way I2C works is that you can have one master (your Arduino) communicate with multiple slaves (your EEPROM for example) on the same I2C bus. Since it is possible to have multiple slaves connected on the same bus, I2C protocol requires you to specify what slave device you are communicating with. This is what Wire.beginTransmission(ADDR) does. It is selecting which device it wants to initiate communication with. If you want to communicate with your EEPROM you will need to send the address of your EEPROM (you should be able to find the address in the EEPROM datasheet).

Next, you need to specify the memory location inside your EEPROM where you want to access. This is done using the two bytes highADDR and lowADDR. If for instance you wanted to access the address 0x01AB, then set highADDR to 0x01 and lowADDR to 0xAB.

The rest is fairly simple. You send your data then end the transmission.

To Summarize:

Select device to communicate with (Select your EEPROM)

Wire.beginTransmission(ADDR);

Tell your EEPROM what memory address you want to write to

Wire.write(highADDR);      // Send the most significant address bits
Wire.write(lowADDR);       // Send the least significant address bits

Send data to write.

Wire.write(data);

End the transmission

Wire.endTransmission();

I strongly recommend reading more about how the I2C protocol works. http://en.wikipedia.org/wiki/I%C2%B2C#Message_protocols

swolfe
  • 916
  • 5
  • 8
  • So I guess my question is really: "Why does I2C not allow you to just do 0x01AB ... Why do you have to send it as 0x01 and 0xAB?" – Jister13 Jun 08 '14 at 02:20
  • Oh, basically its part of I2C spec. So what I think your asking is why doesn't the library function Wire.write() take care of the bit manipulation for you. Good question, IIRC some devices may not use two byte addressing. Suppose you had a device that only used one byte addressing and you wanted to write to address 0x01, you wouldn't want the Wire.wire() to interpret that as the 16-bit value 0x0001 and send two a two byte address when your slave device is designed to only accept one byte addresses. – swolfe Jun 08 '14 at 02:43
  • Also, you could always just write a function that does the dirty work: void writeAddr(uint16_t addr){ (uint8_t) highADDR = (uint8_t)((addr & 0xFF00) >> 8); (uint8_t) lowADDR = (uint8_t)(addr & 0x00FF); wire.Write(highADDR); wire.Write(lowADDR); } – swolfe Jun 08 '14 at 03:00
  • So what is the max low address and the max high address (and how can I determine this)? This is the product I am using: https://www.sparkfun.com/products/525 – Jister13 Jun 08 '14 at 03:39
  • Your device stores 32K bytes (256K bits / 8). A memory address corresponds to a byte in memory. Therefore you need 32K memory addresses to be able to address every byte of memory in the EEPROM. 32K is equal to 2^15 so you need your address to be at least 15 bits long. So your addresses should range from 0x0000 to 0x7FFF. Look at figure 5-2 on the datasheet. It says the the MSB on the high address byte is ignored and the remaining 15 bits specify a memory location. – swolfe Jun 08 '14 at 14:33