Go Down

Topic: i2c import / export from 24c01 (Read 961 times) previous topic - next topic

dr_no

:smiley-slim: hello..i starting on i2c interface with arduino..

something i 'not understood in red below :

about this code:
Quote
#include <Wire.h>

void eeprom_i2c_write(byte address, byte from_addr, byte data) {
  Wire.beginTransmission(address);
  Wire.send(from_addr);
  Wire.send(data);
  Wire.endTransmission();
}

byte eeprom_i2c_read(int address, int from_addr) {
  Wire.beginTransmission(address);
  Wire.send(from_addr);
  Wire.endTransmission();

  Wire.requestFrom(address, 1);
  if(Wire.available())
    return Wire.receive();
  else
    return 0xFF;
}

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

  for(int i = 0; i < 10; i++) {
    eeprom_i2c_write(B1010100, i, 'f'+i);
    delay(100);
  }

  Serial.println("Writen to memory!");
}

void loop() {
  for(int i = 0; i < 10; i++) {
  byte r = eeprom_i2c_read(B1010100, i);
    Serial.print(i);
    Serial.print(" - ");
    Serial.print(r);
    Serial.print("\n");
    delay(1000);
  }
}

what is the 'f' from " eeprom_i2c_write(B1010100, i, 'f'+i) " ? where it came from ?
cause we use "r" in serial .print (r), not "f" ...
some can explain it ?

many thanks to all  :smiley-mr-green:

AWOL

Code: [Select]
'f' + i
is simply the ASCII characters 'f' ('f' + 0), 'g', 'h' ... 'o' ('f' + 9)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dr_no

:smiley-red: understood !
but what is the value B1010100 ?
and why after reading from my memory, it send me from Serial.print(r) thoses numbers like 102,103,104,105 instead of the ascii value of f+i ?

:.(i gona do again the test to be shure wath i wrote here....i gone see tonight, but if you can tell....)

best..

AWOL

Quote
but what is the value B1010100

0x54.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dr_no

:smiley-eek: yeah ! what it is ?  code for write or read in memory ?

AWOL

Code: [Select]
void eeprom_i2c_write(byte address, byte from_addr, byte data)
Device address, memory address, data.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dr_no

XD ok...many thanks to u AWOL....
it's became clearly now..
i gona read again my notes...
:smiley-zipper:

dr_no

XD great ! ok... it's working..this is the real ascii code and the device is well called.. :smiley-eek:
thanks very much...

dhenry

Quote
where it came from ?


You should read the device datasheet against the code, then you will know why the code is coded that particular way.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy