chipKIT® Development Platform

Inspired by Arduino™

Wire Library

Created Mon, 05 Nov 2012 21:26:40 +0000 by Tigre


Tigre

Mon, 05 Nov 2012 21:26:40 +0000

Hi, i have a problem with Wire Library. I have Max32 and Network shield. I trying read and write to the I2C EEPROM of network shield. I connected J9 and J12 jumpers.

#include <Wire.h>

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}


  
void loop()
{
  
  // Write EEPROM I2C
  Wire.beginTransmission(0); // transmit to device #0
  Wire.send(0x00);    // Address High
  Wire.send(0x01);    // Address low
  Wire.send(0xFF);    // data
  Wire.endTransmission();    // stop transmitting
  Serial.print("WR: ");
  Serial.print(0xFF);
  Serial.print("\n");
  delay(5);
  
  // Read EEPROM I2C
  byte data;
  Wire.beginTransmission(0);  // transmit to device #0
  Wire.send((int)highByte(0x00) );  // Address High
  Wire.send((int)lowByte(0x01) );  // Address low

  Wire.requestFrom(0,(byte)6);
  while(Wire.available() == 0);
  data = Wire.receive();
  Wire.endTransmission();

   Serial.print("RD:");
   Serial.print(data);
   Serial.print("\n");
}

that has not worked. you can help me?


MGLSOFT

Tue, 06 Nov 2012 01:19:17 +0000

Are you sure that the Wire.h library is for use with I2C ?? For me 1Wire communication, wich is a different thing...


Tigre

Tue, 06 Nov 2012 08:41:41 +0000

i'm sure. I found an example that works.

[url]http://www.pjrc.com/teensy/td_libs_Wire.html[/url]

#include <Wire.h>

void setup() 
{
  Wire.begin();
  Serial.begin(9600);
}

void loop() 
{
  byte num;
  
  // set the 24C256 eeprom address to 0
  Wire.beginTransmission(80);
  Wire.send(0);  // address low byte
  Wire.send(0);  // address high byte
  Wire.endTransmission();
  
  // read 1 byte, from address 0
  Wire.requestFrom(80, 1);
  while(Wire.available()) {
    num = Wire.receive();
  }
  Serial.print("num = ");
  Serial.println(num, DEC);
  
  // increment num
  num = num + 1;
  
  // write "num" to 24C256 eeprom at address zero
  Wire.beginTransmission(80);
  Wire.send(0);    // address low byte
  Wire.send(0);    // address high byte
  Wire.send(num);  // any more send starts writing
  Wire.endTransmission();
  
  // next time loop runs, it should retrieve the
  // same number it wrote last time... even if you
  // shut off the power
  delay(5000);
}

But i don't understand why the wire library needs address 80 to communicate with this chip if the datasheet especific Device Address how: 1 0 1 0 A2 A1 A0 R/W

A2 = A1 = A0 = GND = 0 but 1 0 1 0 = 0xA-


les1943

Tue, 06 Nov 2012 11:09:59 +0000

for I2c bus address 0 is a general call for all devices on the bus , 24LC256 have addresses starting with 0x5 'H the next 3 bits from the A0-A2 pins , the final bit is added by the master as the R/W bit .

search for UM10204.pdf as a good reference.


Tigre

Tue, 06 Nov 2012 16:34:11 +0000

Thanks les1943, but I mean the memory address, is 1010 = 0xA not 1000 = 0x8

I connected the osciloscope and the pic generate this byte 1 0 1 0 0 0 0 RD/WD as specified memory datasheet ,but we send "Wire.beginTransmission(80);" not Wire.beginTransmission(A0);

it is curious, but i don't understand why...


les1943

Tue, 06 Nov 2012 19:55:45 +0000

I have not used direct numbers into the wire.send(x) but an unsigned int EEaddress = 0 ; works fine so perhaps it is something to do with that.