Skip to content

Sample I2C – Reading and writing I2C ROM

TakeoTakahashi2020 edited this page Sep 21, 2021 · 3 revisions
  • Use I2C of pyb module. The pyb module I2C is not implemented on the RA4M1 MCU.

image

  • Writes and reads 3-byte data (b'abc') from address 2 of the I2C ROM (24LC64).
  • Example of EK-RA6M2:
from pyb import I2C
import time

i2c = I2C(1)
i2c.init(baudrate=100000)
#i2c.scan()

i2c.mem_write("abc", 0x50, 2, timeout=1000, addr_size=16)
data = i2c.mem_read(3, 0x50, 2, timeout=1000, addr_size=16)
print(data)

image

image

image

  • EK-RA6M2 uses I2C channel 1.P400 for scl, P401 for sda.
  • Connect 4 pins of P400 for scl, P401 for sda, VCC and GND.

Home

ホーム

Clone this wiki locally