CostinC
CostinC

Reputation: 21

I cannot write to 24fc512 i2c memory chip from Linux

For few days now, I struggle to write some data in the memory of a 24fc512 i2c chip from Linux. I tried both a Raspberry Pi 4 and a Beaglebone Black. The IC has 4.7 KOhm pullup resistors on SCL and SDA. It is detected on the bus, having as address the 0x50 (0x52 is a similar chip, and the same behavior; also 0x54 and 0x56 should have been same type of chips, but the addresses are taken by some other devices I guess on Beaglebone Black, but they are shown on RPi4):

ebian@BeagleBone:~$ i2cdetect -y 2
Warning: Can't use SMBus Quick Write command, will skip some addresses
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                                                 
10:                                                 
20:                                                 
30: -- -- -- -- -- -- -- --                         
40:                                                 
50: 50 -- 52 -- UU -- UU -- -- -- -- -- -- -- -- -- 
60:                                                 
70:

... and the Python atempt:

>>> from smbus2 import SMBus
>>> bus = SMBus(2)
>>> bus.read_byte_data(0x50,0) # read one byte of data from address 0
2 # I wrote this to the chip using an Arduino
>>> bus.read_byte_data(0x50,1) # read one byte of date from address 1
255
>>> bus.write_byte_data(0x50, 1, 0) # write one byte of data from address 1
>>> bus.read_byte_data(0x50,1) 
255
>>> # nothing happened ... the same is valid for read/write_block_data()
>>> bus.close()
>>> 

What am I doing wrong?

Thank you,

Upvotes: 0

Views: 265

Answers (1)

Theodore
Theodore

Reputation: 1

Debug as follow:

  1. Check the status of WP pin
    There is a write-protect pin in 24fc512, make sure WP pin is high before write
  2. Check driver support
    Check your Linux kernel defconfig file, select 24fc512 driver in
    Device Drivers --> Misc devices --> EEProm support --> I2C EEPROM
    Add eeprom device to your I2C controller node in DTs as follow:
&i2c3 {     
  clock-frequency = <400000>;   
  pinctrl-names = "default";
  pinctrl-0 = <&pinctrl_i2c3>;  
  status = "okay";

  at24@50 {         
    compatible = "atmel,24c512";        
    pagesize = <64>;        
    reg = <0x50>;   
  }; 
};
  1. Test eeprom
    24fc512 will create as /dev/eeprom, you can use open/read/write to read/write eeprom, also support cat/echo too, such as:
cat /dev/eeprom
dd if=xxx of=dev/eeprom bs=512

Upvotes: 0

Related Questions