I've been experimenting with an I2c 256k eeprom by Microchip in order to gain more knowledge, as its fairly new to me. I've managed to write to the high and low address (0x00) and store a byte of data (number). I then wrote to another address (0x01) then requested two bytes and was able to print the two values to the serial monitor. If I wanted to write more data to the eeprom, would I increment the high and low byte like so: 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14... 20, 21....etc?
Another question is that I decided to change my eepromWrite function data parameter to a char, but when I try and pass in a char I get numbers displayed within the serial monitor. Can I also confirm that all I2c devices can only send 1 byte of data at a time?
Before, the next byte transmitted by the master is the high-order byte of theword address and will be written into the addresspointer of the 24XX256. The next byte is the Least Significant Address Byte. After receiving another
Acknowledge signal from the 24XX256, the master device will transmit the data word to be written into the addressed memory location.
You could pass a word (2 bytes) to fill the HighByte and LowByte.
If I wanted to write more data to the eeprom, would I increment the high and low byte like so: 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14... 20, 21....etc?
Yes.Be aware you are occupying 2 bytes so you must know first word will be stored at 0x00 and 0x01 and the next word must start at 0x02(High Part) and 0x03(low Part) to not overlap memory positions.
Can I also confirm that all I2c devices can only send 1 byte of data at a time?
It can seend only a byte from the moment you make "Start condition" in the I2C bus to the ACK (acknowledge)
Read this for better undestand of I2C protocol
I started to work my way through the link you provided and added some LED's to provide feedback regarding if a transmission has actually ended, etc. I'm also intrigued to know that I only have to set the register pointer once to 0x00,0x0, then I can actually keep writing data in the correct memory locations to the to the IC without providing further high parts e.g. 0x02 and low parts e.g. 0x03.
Here is my code so far:
#include <Wire.h> // When using I2c, 0 == write and 1 == read
#define ADDRESS 0x50
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
// If we want the Arduino to be a slave device we pass in an argument to the method below
Wire.begin();
delay(15);
Wire.beginTransmission(ADDRESS);
Wire.write((byte)0);
Wire.write((byte)0);
Wire.write((byte)5);
Wire.write((byte)10);
Wire.write((byte)15);
Wire.write((byte)20);
Wire.write((byte)25);
Wire.endTransmission();
delay(5);
}
void loop() {
Wire.beginTransmission(ADDRESS);
Wire.write((byte)0);
Wire.write((byte)0);
if(Wire.endTransmission() == 0) {
digitalWrite(2, HIGH);
}
delay(2000);
digitalWrite(2, LOW);
Wire.requestFrom(ADDRESS, 5); // Request 5 bytes
while(Wire.available() == 0) {
// Wire.available returns the number of bytes available for reading
}
Serial.print(Wire.read());
Serial.print(',');
Serial.print(Wire.read());
Serial.print(',');
Serial.print(Wire.read());
Serial.print(',');
Serial.print(Wire.read());
Serial.print(',');
Serial.println(Wire.read());
delay(2000);
}