Hello, I am a newbie to writing any kind of external device driver, I am trying to write some basic data to an eeprom, when I look at what I am trying to write to the eeprom here, all I see is "0". Can anyone see what I am doing wrong? I would at least expect to see 10 values written.
#define LEN 10
byte buf[LEN];
for(byte i =0; i < LEN; ++i)
buf[i] = i;
byte r = dev.write(0, buf, LEN);
Serial.print("written:");
Serial.println(r, HEX);
Please post complete code so we can e.g. see which library you're using.
Usually write methods return the number of bytes written, not the content. This does not explain why you would get 0 back, it should be 10 (0x0A). So it will not return the complete array if that is what you were expecting.
That is not complete code; please write a small example that uses that method. Note that we e.g. don't know what EEPROM_ADDR and m_addr are. You will also need to show the class (if it's not part of the ino file).
3. Upload the following sketch to write 0x37 at Location-12 (0x0C), read it back and show on SM (Serial Monitor). (I have not moderated your snippet sketch of post #1. Please, post full sketch so that I can do the moderation.)
#include<Wire.h>
#define deviceAddress 0x50 //101 0000
void setup()
{
Serial.begin(9600);
Wire.begin();
//----checking the presence of EEPROM om I2C Bus----------
Wire.beginTransmission(deviceAddress);
byte busStatus = Wire.endTransmission();
if (busStatus != 0x00)
{
Serial.println("EEPROM is not found!");
while (true); //wait for ever
}
Serial.println("EEPROM is present.");
//-----data write process--------
Wire.beginTransmission(deviceAddress);
Wire.write(0x0C); //pointing at EEPROM locatiom 12 = 0x0C
Wire.write(0x37); //data for EEPROM location, 12
Wire.endTransmission();
delay(5); //an EEPROM location tgakes about 5 ms time to absorb a data byte
//------- read after write verification----------
Wire.beginTransmission(deviceAddress);
Wire.write(0x0C); //pointing at EEPROM locatiom 12 = 0x0C
Wire.requestFrom(deviceAddress, 1); //request to read 1-byte form EEPROM
byte y = Wire.read();
Serial.println(y, HEX); //SM should show: 37
}
void loop() {}
4. Press RESET button of UNO.
Check that SM shows: 37
When you include the following lines in your sketch, the alternate functions SDA/SCL of Pins-27/28 of ATmega328P MCU (Fig-1) of the UNOR3 Board are routed to A4/A5 pins of the edge connector. (Thre is no legend like SDA/SCL on UNOR3 Board; they are shown on UNOR4 (Fig-2).)
Pay attention to PC4 and PC5 which show twice (A4/A5 and (SDA/SCL). Those two sets of pins are in parallel. So A4 and A5 are the I2C pins on an board with a 328P.
As mentioned in your first post...
Not correct. The pins near D13 are a duplicate of A4, A5.
Both sets connect to the same two I2C pins of the MCU.
Leo..