简体   繁体   中英

Wire High&Low Address

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM