B4R Question Use external eeprom

takhmin77

Member
You can try using the code with inline C...
hi
can you send b4a code sample
this code work fine for me :
B4X:
#include <Wire.h> 
#define eeprom 0x50 //defines the base address of the EEPROM

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

 unsigned int address = 0; 
 Serial.println("write");
 for(address = 0; address< 20; address++) {
 writeEEPROM(eeprom, address, address);
 delay(5);
 }
 
 for(address = 0; address< 20; address++) {
 Serial.print(readEEPROM(eeprom, address), HEX); 
 }
 }

 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