www.mikrocontroller.net

Forum: Mikrocontroller und Digitale Elektronik I²C EEprom communication (reading/writing)


Autor: Enishi (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Entschuldigen sie mir bitte,ich bin französich, ich verstehe nicht so 
gut deutsch und mein deutsch ist so schlecht.


Es ist möglich auf english zu schreiben ?

Ich habe ein renesas kit RSKM16C29 :

http://documentation.renesas.com/en...km16c29_qsg.pdf

eine EEprom 24C16 von Microchip


http://www.datasheetcatalog.com/dat...C/24LC16B.shtml

Ich benutze HEW4 und ich programmiere auf C sprache.

Ich benutze sample program von Renesas für die I²C interface :

http://documentation.renesas.com/en...0030_m16cap.pdf

Mein projekt programme ist :

http://www.megaupload.com/fr/?d=JQ0RQBUT


Ich habe funktion für shcreiben und lesen in die sample program gesehen 
aber ich weiß nicht, wie sie zu benutzen

können sie mir helfen bitte.


Autor: Frank N. (betafrank)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Hi Enishi,

Sorry, I have no experience with renesas.

Anyway - most of the links you posted doesn't work... ;-)

Regards Frank

Autor: Enishi (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert

Autor: KlaRa (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Hallo,
vielleicht findes Du hier etwas:
http://www.cc2net.de/Module/module.html

eeprom.zip
eeprom2k.zip

Gruss Klaus.

Autor: Frank Zöllner (frankovic)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Hi Eneshi,

how to use I²C you can learn for example at the Elektor Homepage: 
www.elektor.de. Maybe there is a similar french page. There's a forum 
for the Renesas R8C/13. This Controller is similar to the M16C.

The ATMEL AT24C16 is used in the following way:

your have to know the address of the EEPROM, for example
deviceadress_write = 0xa0;
deviceadress_read = 0xa1;

the page your want to read / write is:
0 <= addr <= 2048

writing with function Write_Byte(addr-1, BYTE data);
reading with          Read_Byte(address);

the functions in detail:

void Write_Byte(int adress, BYTE data)
{
BYTE page = 0x00 | (int) (adress / 256);
page <<=1;
Send_Startcondition();
Send_Byte(page | deviceadress_write);
waitms = 5;
Send_Byte(adress & 0xff);
Send_Byte(data);
Send_Stopcondition();
waitms = 0;
};


BYTE Read_Byte(int adress)
{
BYTE page = 0x00  | (int) (adress / 256);
page <<=1;
waitms = 0;
Send_Startcondition();
Send_Byte(page | deviceadress_write); // device adress
Send_Byte(adress & 0xff); // word adress
Send_Startcondition();
Send_Byte(deviceadress_read); // device adress and next: read
BYTE res = Get_Byte();
Send_Stopcondition();
return res;
};


Regards,
Frank

Autor: Frank Zöllner (frankovic)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
just saw there's a french elektor site www.elektor.fr. Search for "I2C" 
in the R8C/13-forum. Maybe the M16C has hardware-based I²C? The R8C/13 
uses Software I²C. By the way: The R8C/13 has 4KByte of user accessible 
ROM. So often an external EEPROM is not necessary. It's programmed in a 
simple way via the Renesas FDT.

Autor: Enishi (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Thanks for your reply. I understand what you show me and I understand 
the I²C principe but I have to use the Renesas sample program.

In this program, there is some function for reading and wrting on the 
EEprom but actually I don't know how to use them

the eeprom_operation function in the file i2c_function.c  is defined 
like this  :

unsigned char eeprom_operation(unsigned char slave, unsigned char 
memaddr,
unsigned char *buffer, unsigned char length,
unsigned char rw)
unsigned char eeprom_operation(unsigned char slave, unsigned char memaddr,
unsigned char *buffer, unsigned char length,
unsigned char rw)
{
  if((bb == 1) || (iic_mode != MODE_IDLE)) {
    return(0);                 /* fail to start operation */
  }
  else {
    asm("pushc FLG");            /* protect FLG register */
    asm("fclr I");               /* disable interrupt */
    iic_slave = slave << 1;         /* set device address */
    iic_rw = 0;               /* set read/write bit */
    iic_length = length;           /* set data (bytes) in operation */
    iic_pointer = buffer;           /* set buffer pointer */
    iic_memaddr = memaddr;           /* set memory address */
    if(rw == 0) {               /* write operation */
      if(iic_length > BYTE_LIMIT) {     /* limit the data (bytes) in */
                        /* page write operation */
        iic_length = BYTE_LIMIT;
      }
      iic_mode = MODE_WRITE;
      submode = WRITE_MEMADDR;
    }
    else {                   /* read operation */
      iic_mode = MODE_READ;
      submode = READ_MEMADDR;
    }
    s10 = 0xE0;               /* start condition */
    s00 = iic_slave;
    asm("popc FLG");             /* restore FLG register */
    return(1);                 /* success starting operation */
  }
}

I've read the eeprom documentation again and I think the eeprom adress 
can be write like this :  #define EEPROM_ADDR 0b01010001

because in the documentation the eeprom control code is 1010, then it's 
the block select bits on 3 bits and then the R/W bit (0 for writing and 
1 for reading)

the eeprom_operation function manage two other function : 
master_transfer and  master_receive we can read in the comment that 
theses function write and read on the eeprom, but in order to use them I 
think  I have to use the eeprom_operation function


have you any idea for using these functions please ?

Thank !

Autor: Frank Zöllner (frankovic)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
ok, i don't have the time at this moment to really investigate the code, 
but here is my estimation:

>> unsigned char eeprom_operation(unsigned char slave, unsigned char
>> memaddr,
>> unsigned char *buffer, unsigned char length,
>> unsigned char rw)

slave: adress of slave
memaddr: page you want to read of / write to
buffer: contains data to read / write
length: lenght of buffer (number of elements of type unsigned char)
rw read or write flag

use for write "Hello" on eeprom with slave address 0xa0 @ address 0x00:

char *hello = "Hello"; // 5 characters -> length = 5
eeprom_operation(0xa0, 0x00, hello, 5, 1);

Frank

Autor: Enishi (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
I've trying your code but actually i've got two little errors as the 
program don't know a variable. I'm currently trying to fix it.

Thanks for your help !

Autor: Enishi (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
It works !!!... but I don't know how !

I fix the calling for function like this :

  char hello[8] = {'H','e','l','l','o','B','o','y'};
  char x[8] = {'0','0','0','0','0','0','0','0'};

  eeprom_operation(0xa0, 0x00, hello, 8, 0); //writing

        eeprom_operation(0xa0, 0x10, x, 8, 1); //reading

  for (i=0; i<8; i++)
    {
      x[i]=x[i+8]; //without this, it displays only 0000000
    }
  DisplayString(LCD_LINE2,x); //disply on the lcd

I associate the writing with the button 1 and reading/displaying with 
button2

but when I start the program, if i press directly the button 2, it 
displays HelloBoy as if I have push the button1 and I don't know why and 
how to fix it, have you any idea ?

Thanks a lot for your help !

Autor: Frank Zöllner (frankovic)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
wow! i am sure you'll fix the remaining problems.
char hello[] = 'hello' or hello = "hello" is not working?

the reading adress is one higher then writing
deviceadress_write = 0xa0;
deviceadress_read = 0xa1;

maybe your [i] = [i+8] has something to do with that?



Regards,
Frank

Autor: Enishi (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
char hello[] display a strange character and hello = "hello" display 
compilation error


it seems when I change reading adress from 0xa0 to 0xa1 nothing else 
happened  it's the same as 0xa0

and if I delete the line [i]= [i+8] I only display 00000000 on the lcd 
that's why iI've add this line

Autor: Enishi (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
I will add somen I²C temperatures sensors :

a AD5161 and a AD5252

In order to display the data from the sensors to the LCD, I have to 
convert Data into a char string.

I think I will procede like this :

Binary data in char string ---> Binary data in Int string
 an int variable (J) = Intstring[0]*128 + 
Intstring[1]*64.....Intstring[7]*1
i=0;
intstring2[8];
while (J!=0){
      instring2[i]=J%10;
      J=J/10;
      i++;}

char string[8]={'0','0','0','0','0','0','0','0'}
for (i=0;i<8;i++) {
      char string[i]=intstring2[i]; }


Autor: Enishi (Gast)
Datum:

Bewertung
0 lesenswert
nicht lesenswert
Finally, i've received an AD7418 from analog device

http://www.analog.com/UploadedFiles/Data_Sheets/AD...

but it seems my reading function can't work with this sensors or I have 
to add something to enable the sensors but I don't know what

Antwort schreiben

Die Angabe einer E-Mail-Adresse ist freiwillig. Wenn Sie automatisch per E-Mail über Antworten auf Ihren Beitrag informiert werden möchten, melden Sie sich bitte an.

Wichtige Regeln - erst lesen, dann posten!

  • Groß- und Kleinschreibung verwenden
  • Längeren Sourcecode nicht im Text einfügen, sondern als Dateianhang

Formatierung (mehr Informationen...)

  • [c]C-Code[/c]
  • [avrasm]AVR-Assembler-Code[/avrasm]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] - Link zu Artikel
  • Verweis auf anderen Beitrag einfügen: Rechtsklick auf Beitragstitel,
    "Adresse kopieren", und in den Text einfügen




Bild automatisch verkleinern, falls nötig
Bitte das JPG-Format nur für Fotos und Scans verwenden!
Zeichnungen und Screenshots im PNG- oder
GIF-Format hochladen. Siehe Bildformate.
Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt.
Bitte hier nur auf die ursprüngliche Frage antworten,
für neue Fragen einen neuen Beitrag erstellen.

Mit dem Abschicken bestätigst du, die Nutzungsbedingungen anzuerkennen.