B4R Question Use external eeprom

Discussion in 'B4R Questions' started by takhmin77, Jun 10, 2018.

  1. takhmin77

    takhmin77 Member

  2. Erel

    Erel Administrator Staff Member Licensed User

    Mostez and Peter Simpson like this.
  3. takhmin77

    takhmin77 Member

  4. Peter Simpson

    Peter Simpson Expert Licensed User

    You can try using the code with inline C...
     
  5. takhmin77

    takhmin77 Member

    hi
    can you send b4a code sample
    this code work fine for me :
    Code:
    #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 = 0address20address++) {
     writeEEPROM(eeprom, 
    addressaddress);
     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: Jun 12, 2018
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice