Kampi
Posts: 66
Joined: Sun Oct 07, 2012 12:05 am
Location: Monheim, Germany
Contact: Website

I²C

Sun Oct 07, 2012 12:12 am

Hello Guys,

i want to connect my Raspberry Pi with an PSoC I²C Slave, an 24C128 EEPROM and a PCF8574 via the I²C Bus. The communication between the PCF8574 works very fine (i use the Console first).
But the Communication with the EEPROM works not so fine. If i write a 0x10 with

i2cset -y 0 0x50 0x00 0x10

into the EEPROM and read it out with

i2cget -y 0 0x50 0x00

i recieve an 0x97. The communication with my PSoC Device fails directly. The Raspberry prints

Error: Write failed

when i write something with

i2cset -y 0 0x40 0x00 0x10

I think it´s a Problem with ACK/NACK but i´m not sure.
Here is the Datasheet of the I²C Module of my PSoC:

http://www.cypress.com/?docID=34801

Can someone help me?
Thank you!
Daniel
Meine Homepage:

www.Kampis-Elektroecke.de

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: I²C

Tue Oct 09, 2012 6:39 pm

Kampi wrote:Hello Guys,

i want to connect my Raspberry Pi with an PSoC I²C Slave, an 24C128 EEPROM and a PCF8574 via the I²C Bus. The communication between the PCF8574 works very fine (i use the Console first).
But the Communication with the EEPROM works not so fine. If i write a 0x10 with

i2cset -y 0 0x50 0x00 0x10
So you have addressed location 0x10, and not written any data. The internal RAM data pointer is 16 bits long (consisting oif 2 x 8 bit bytes).
into the EEPROM and read it out with

i2cget -y 0 0x50 0x00
Why the extra 0x00 on the end ?

Anyway you are attempting to read a location that has not been written to.
i recieve an 0x97. The communication with my PSoC Device fails directly. The Raspberry prints
How do you know it has failed and you have not done anything else to confuse things, how do you know the PSOC is working correctly.
Error: Write failed

when i write something with

i2cset -y 0 0x40 0x00 0x10

I think it´s a Problem with ACK/NACK but i´m not sure.
Here is the Datasheet of the I²C Module of my PSoC:

http://www.cypress.com/?docID=34801

Can someone help me?
Thank you!
Daniel
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

Kampi
Posts: 66
Joined: Sun Oct 07, 2012 12:05 am
Location: Monheim, Germany
Contact: Website

Re: I²C

Tue Oct 09, 2012 6:51 pm

Thank you for an answer.
You are right. I forgot that the Adresspointer is 16 Bit long.
I will try it with four Databytes.
I have to set an EEPROM Start Pointer if i want to read out the EEPROM. So i write 0x00 or is it wrong?
I know that the communication with the PSoC fails cause the Raspberry Pi prints

Error: Read failed

I tested the PSoC with an Mega32 over I²C and it works fine so i know that the Software on the Chip works.

I tested the communication now with

i2cget -y 0 0x40

and so it works (tested it cause of your Answer).
But the Write don´t work.
What is the right Command? The PSoC works like an EEPROM. Is the Command something like this

i2cset -y 0 0x40 0x00 0x00 0x01

Cause with one Adressbyte it returns an Error.
Thank you!
Meine Homepage:

www.Kampis-Elektroecke.de

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: I²C

Tue Oct 09, 2012 8:58 pm

Kampi wrote:Thank you for an answer.
You are right. I forgot that the Adresspointer is 16 Bit long.
I will try it with four Databytes.
I have to set an EEPROM Start Pointer if i want to read out the EEPROM. So i write 0x00 or is it wrong?
Right lets try and get this straight (and as in the device datasheets) EEPROM with 16 bit addressing is accessed in following way

i2cset -y 0 0x50 0x00 0x00 0x01 [optional extra bytes of data in a block]

Which is
  • i2set - program
  • -y optoin
  • 0 i2c bus to use
  • 0x50 I2C address of EEPROM
  • 0x00 0x00 TWO datatbytes which become the 16bit EEPROM INTERNAL data pointer
  • 0x01 etc actual data to write to sequential locations STARTing at the data pointer
After each Write or Read of an actual byte the internal data pointer is incremented to the next byte location in the EEPROM.
If you do a write of two data bytes as an internal data pointer with NO following data bytes this sets the INTERNAL data pointer.

Any reads (i2cget) gets data byte(s) from the current data pointer location and onwards.

So if you want to write to a location, and the read it back you must Write the data, write the address again then read the EEPROM byte

Code: Select all

i2cset -y 0 0x50 0x00 0x00 0x01
i2cset -y 0 0x50 0x00 0x00
i2cget -y 0 0x50
All this assumes your EEPROM is at 0x50 I2C address
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

Kampi
Posts: 66
Joined: Sun Oct 07, 2012 12:05 am
Location: Monheim, Germany
Contact: Website

Re: I²C

Tue Oct 09, 2012 9:29 pm

Hey,

thank you for this very good help :)
Yes my EEPROM has Adress 0x50. I will try it and then i try it with my PSoC.
But if i use this Command:

i2cset -y 0 0x50 0x00 0x00 0x01

My Raspberry answer

Error: Invalid mode '0x01'!
Usage: i2cset [-f] [-y] [-m MASK] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]
I2CBUS is an integer or an I2C bus name
ADDRESS is an integer (0x03 - 0x77)
MODE is one of:
c (byte, no value)
b (byte data, default)
w (word data)
i (I2C block data)
s (SMBus block data)
Append p for SMBus PEC
Meine Homepage:

www.Kampis-Elektroecke.de

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: I²C

Tue Oct 09, 2012 9:55 pm

Kampi wrote:Hey,

thank you for this very good help :)
Yes my EEPROM has Adress 0x50. I will try it and then i try it with my PSoC.
But if i use this Command:

i2cset -y 0 0x50 0x00 0x00 0x01

My Raspberry answer

Error: Invalid mode '0x01'!
Usage: i2cset [-f] [-y] [-m MASK] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]
I2CBUS is an integer or an I2C bus name
ADDRESS is an integer (0x03 - 0x77)
MODE is one of:
c (byte, no value)
b (byte data, default)
w (word data)
i (I2C block data)
s (SMBus block data)
Append p for SMBus PEC
When doing i2cset use 'i' for block of data on end of command.

When doing i2cget the default of 'b' byte to read a single byte, check i2cget for how to get multiple bytes in one call.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

Kampi
Posts: 66
Joined: Sun Oct 07, 2012 12:05 am
Location: Monheim, Germany
Contact: Website

Re: I²C

Tue Oct 09, 2012 10:05 pm

Cool it works!
Thank you very much. Now i have to solve the Problem with writing into the PSoC.
Meine Homepage:

www.Kampis-Elektroecke.de

Kampi
Posts: 66
Joined: Sun Oct 07, 2012 12:05 am
Location: Monheim, Germany
Contact: Website

Re: I²C

Wed Oct 10, 2012 6:24 pm

Hello,

now i want to try it with an Nintendo Wii Nunchuk. Do you have any experience with it?
Meine Homepage:

www.Kampis-Elektroecke.de

gauravsharma0190
Posts: 103
Joined: Tue Oct 28, 2014 6:36 am

Re: I²C

Wed Nov 30, 2016 9:16 am

hey there i am using 24lc1025 eeprom ic which has address 0x50.
i used i2ctool and i2cset as
i2cset -y 1 0x50 0x00 0x00 0x21 i
and read it as i2cget -y 1 0x50 0x00
or using i2cget -y 1 0x50
but always seen 0xff.
when i seen resister usning i2cdump but all address is 0xff
plz give any solution

Leandro82
Posts: 2
Joined: Tue Jul 18, 2017 8:19 pm

Re: I²C

Sat Dec 02, 2017 6:13 pm

Hi,
Sorry my bad english.
The 24CXXX family memory the device adress byte is not equal for read and write procedures.
For exemple, in the 24C02 the first byte to send is:
BITS:
|7|6|5|4|3|2|1|0| LSB
|1|0|1|0|R|S|T|U|

R,S,T configued in A2,A1,A0 pins
U -> 0 to write or 1 to read

For Exemple, the C code (CCS Compiler) Microcontroller PIC16F877A fragment:
Note: (A2,A1,A0 in ground)
*******
#define DADO 0b11110000 (DATA to Write)
#define EEPROM_ADRESS_WRITE 0b10100000
#define EEPROM_ADRESS_READ 0b10100001
#define ENDERECO_INTERNO 0x05 (Memory Write/Read Locate)
*******

//Escrita 24C02 (Write sequence)
i2c_start(); //Coloca o barramento em condição de inicializar a comunicação
i2c_write(EEPROM_ADRESS_WRITE); //Endereço do dispositivo (escrita)
i2c_write(ENDERECO_INTERNO); //Endereço interno da memória para alocação do dado
i2c_write(DADO); //Grava o dado na memória
i2c_stop(); //Finaliza a comunicação com o barramento
delay_ms(11);

//Leitura 24C02 (Read sequence)
i2c_start(); //Coloca o barramento em condição de inicializar a comunicação
i2c_write(EEPROM_ADRESS_WRITE); //Device select
i2c_write(ENDERECO_INTERNO); //Endereço interno da memória para leitura do dado
i2c_start(); //Faz um restart
i2c_write(EEPROM_ADRESS_READ); //Agora como leitura
saida = i2c_read(0); //Lê o valor do bus I2C e mostra o valor nos leds
i2c_stop(); //Finaliza a comunicação com o barramento
*********
You should can try this in Linux Shell (i2c commands)
Good Lucky

kripashree1
Posts: 1
Joined: Wed Jan 10, 2018 8:52 am

Re: I²C

Wed Jan 10, 2018 9:07 am

Hi,

I am also facing the same problem.But in different board.
I am using AMD MF bettong DDR4 board.
kernel version is : 4.4.11-158-amd+

I am doing i2cset works fine.
But i2cget reads 0xff all the time.

commands used is:
sudo i2cset -y 6 0x50 0x6c 00
sudo i2cget -y 6 0x50 0x6c

i2cdump also reads 0xff all the time irrespective of the value written!!!

[email protected]:~$ sudo i2cdump 6 0x50
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-6, address 0x50, mode byte
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
10: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
20: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
40: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
[email protected]:~$

Please let me know why i am not able to write to EEPROM?

I am using one i2c test application to receive i2c 1 or 2 bytes.After running which only i2c slave will be attached to i2c bus!

And also running the application changes the register values,which is read using printk() in the driver.

That time also i2cdump or i2cget reads 0xff !!!!

Why is this happening?? can anyone please let me know?

Thanks & Regards,
Kripashree

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 8 guests