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


von Enishi (Gast)


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.


von Frank N. (betafrank)


Lesenswert?

Hi Enishi,

Sorry, I have no experience with renesas.

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

Regards Frank

von Enishi (Gast)


Lesenswert?


von KlaRa (Gast)


Lesenswert?

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

eeprom.zip
eeprom2k.zip

Gruss Klaus.

von Frank Z. (frankovic)


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

von Frank Z. (frankovic)


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.

von Enishi (Gast)


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)
1
unsigned char eeprom_operation(unsigned char slave, unsigned char memaddr,
2
unsigned char *buffer, unsigned char length,
3
unsigned char rw)
4
{
5
  if((bb == 1) || (iic_mode != MODE_IDLE)) {
6
    return(0);                 /* fail to start operation */
7
  }
8
  else {
9
    asm("pushc FLG");            /* protect FLG register */
10
    asm("fclr I");               /* disable interrupt */
11
    iic_slave = slave << 1;         /* set device address */
12
    iic_rw = 0;               /* set read/write bit */
13
    iic_length = length;           /* set data (bytes) in operation */
14
    iic_pointer = buffer;           /* set buffer pointer */
15
    iic_memaddr = memaddr;           /* set memory address */
16
    if(rw == 0) {               /* write operation */
17
      if(iic_length > BYTE_LIMIT) {     /* limit the data (bytes) in */
18
                        /* page write operation */
19
        iic_length = BYTE_LIMIT;
20
      }
21
      iic_mode = MODE_WRITE;
22
      submode = WRITE_MEMADDR;
23
    }
24
    else {                   /* read operation */
25
      iic_mode = MODE_READ;
26
      submode = READ_MEMADDR;
27
    }
28
    s10 = 0xE0;               /* start condition */
29
    s00 = iic_slave;
30
    asm("popc FLG");             /* restore FLG register */
31
    return(1);                 /* success starting operation */
32
  }
33
}

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 !

von Frank Z. (frankovic)


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

von Enishi (Gast)


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 !

von Enishi (Gast)


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 !

von Frank Z. (frankovic)


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

von Enishi (Gast)


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

von Enishi (Gast)


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]; }


von Enishi (Gast)


Lesenswert?

Finally, i've received an AD7418 from analog device

http://www.analog.com/UploadedFiles/Data_Sheets/AD7416_7417_7418.pdf

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

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.