Pages: [1]   Go Down
Author Topic: i2c import / export from 24c01  (Read 645 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25861
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
'f' + i
is simply the ASCII characters 'f' ('f' + 0), 'g', 'h' ... 'o' ('f' + 9)
Logged

"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.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 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 ?

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

best..
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25861
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but what is the value B1010100
0x54.
Logged

"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.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25861
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void eeprom_i2c_write(byte address, byte from_addr, byte data)
Device address, memory address, data.
Logged

"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.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: