B4R Question External EEPROM

takhmin77

Member
hi
My search resualt is :

"You wire your chips on a breadboard, with the +/- left rail for Vcc/GND, and the right +/- rail for SCL/SDA, plus a little acrobatics to connect everything.
Your chips can have 8 addresses, 0x50 to 0x57, set up with the A0/1/2 pins: all low = 0x00, all high = 0x07. The you read and write to the EEPROM of your choice with:"

B4X:
char i2c_eeprom_read_char(int deviceaddress, unsigned int eeaddress) {
  char rdata = 0xFF;
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8)); // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,1);
  if (Wire.available()) rdata = Wire.read();
  return rdata;
}

void i2c_eeprom_write_char(int deviceaddress, unsigned int eeaddress, char data) {
  int rdata = data;
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8)); // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(rdata);
  Wire.endTransmission();
}
Do you have any Arduino C example for this?


and this link :
http://playground.arduino.cc/Code/I2CEEPROM
and also this :
https://github.com/tardate/LittleAr...ster/playground/EEPROM/AT24C02/BasicReadWrite
 
Last edited:
Upvote 0

takhmin77

Member
Try this:
B4X:
Dim bc As ByteConverter
Dim msb As Int = Bit.ShiftRight(eeaddress, 8)
Dim lsb As Int = Bit.And(eeaddress, 0xff)
Dim data() As Byte = bc.IntsToBytes(Array As Int(msb, lsb))
wire.WriteTo(address, data)
hi
thanks for your reply
i change my code to this code , but not any data to log:
B4X:
Dim bc As ByteConverter
Private wire As WireMaster
Dim eeprom_Adress As Int = 0x50
Dim Memory_Adress As UInt =1

Dim msb As Int = Bit.ShiftRight(Memory_Adress, 8)
Dim lsb As Int = Bit.And(Memory_Adress, 0xff)
Dim data() As Byte = bc.IntsToBytes(Array As Int(msb, lsb))

wire.WriteTo(eeprom_Adress, data)

Dim data1() As Byte="A"
wire.WriteTo(eeprom_Adress, data1)

Delay(500)

Dim msb As Int = Bit.ShiftRight(Memory_Adress, 8)
Dim lsb As Int = Bit.And(Memory_Adress, 0xff)
Dim data() As Byte = bc.IntsToBytes(Array As Int(msb, lsb))
wire.WriteTo(eeprom_Adress, data)

Dim b() As Byte = wire.RequestFrom(eeprom_Adress, 1)
Log("data on address 1 : ",b)




in arduino IDE , this code is work fine for me (return 65 ) :


#include <Wire.h>
#define eeprom 0x50 //defines the base address of the EEPROM

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

Serial.println("write");
writeEEPROM(eeprom, 1, 'A');
delay(5);
Serial.print(readEEPROM(eeprom, 1), DEC);
}

void loop(){}

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) {
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); //writes the MSB
Wire.write((int)(eeaddress & 0xFF)); //writes the LSB
Wire.write(data);
Wire.endTransmission();
}

byte readEEPROM(int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); //writes the MSB
Wire.write((int)(eeaddress & 0xFF)); //writes the LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available())
rdata = Wire.read();
return rdata;
}
 
Last edited:
Upvote 0
Top