---
# System prepended metadata

title: 24lc512(raspberry pi)
tags: [raspberry pi]

---

# 24lc512(raspberry pi)
硬體平台:raspberry zero
目的:對24lc512實現簡易讀寫

## 接線圖

![](https://i.imgur.com/9A23nct.png)



SDA-GPIO3
SCL-GPIO3
WP-GPIO4
VCC-3.3V
VSS-GND

## 開啟i2c功能
```bash=
sudo raspi-config
```
## 讀寫24lc512
開啟IC寫入權限
```bash=
echo 4 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio4/direction 
#0為開啟寫入權限(WP)
echo 0 > /sys/class/gpio/gpio4/value
```
找尋i2C位址(0x50)
```bash=
i2cdetect -y 1
```
對0x0000位址連續寫入10個位址(從0x05遞增到0x0e)
```bash=
 i2ctransfer -y 1 w12@0x50 0x00 0x00 0x05+
```
從位址0x50連續讀取10個位址
```bash=
i2ctransfer -y 1 w2@0x50 0x00 0x00 r10
```
確認寫入的十個位置是否為0x05道0x0e的數值，寫入成功!!

參考資料:
[datasheet](http://ww1.microchip.com/downloads/en/devicedoc/21754m.pdf)
[i2ctransfer](https://manpages.debian.org/unstable/i2c-tools/i2ctransfer.8.en.html)

###### tags: `raspberry pi`