Raspberry Pi」カテゴリーアーカイブ

実験 共有(I2C AQM0802) PSoC4 Raspberry Pi Zero WH

実験 共有(I2C AQM0802 LCD) PSoC4 Raspberry Pi Zero WH
I2C Slave AQM0802(address 0x3E)共有
I2C Master Raspberry Pi
I2C Multi-Master-Slave PSoC4(address 0x08)
$ i2cdetect -y 1 #AQM0802 と PSoC4 を認識している

Code Python Raspberry Pi

import smbus,time

i2c1=smbus.SMBus(1) #0=(port I2C0), 1=(port I2C1)
i2c1.write_i2c_block_data(0x3E,0x00,[0x38,0x39,0x14,0x78,0x5E,0x6A]); time.sleep(0.200) #200ms
i2c1.write_i2c_block_data(0x3E,0x00,[0x0C,0x01]); time.sleep(0.002) #2ms
i2c1.write_byte_data(0x3E,0x00,0x06)
i2c1.write_byte_data(0x3E,0x00,0xC0) #0x80=1st line #0xC0=2nd
i2c1.write_i2c_block_data(0x3E,0x40,[ord(' '),ord(' '),ord('P'),ord('i'),ord(' '),ord('I'),ord('2'),ord('C')])

d=1
while 1:
    d=0x30+((1+d)%10) #9-0 countdown ascii
    time.sleep(1.000) #1s
    try:
        i2c1.write_byte_data(0x3E,0x00,0xC0) #0xC0=2nd line
        i2c1.write_byte_data(0x3E,0x40,d)
    except Exception as e:
        pass ;print(e) #error if exist

Code C PSoC4

...
    const uint8 b0[]={0x00,  0x80}; //1st 0x00 not valid //0x80=1st line 0xC0=2nd line
    const uint8 b1[]={0x00,  ' ',' ','P','S','o','C','4'}; //1st 0x00 not valid
    uint8   d[2];
	while(1) {
		CyDelay(1000);        
                I2C_write((uint8 *)b0, 0x3E, 0x00, 1);
                I2C_write((uint8 *)b1, 0x3E, 0x40, 7);
                d[1]=0x30+((1+d[1])%10); //9-0 countdown ascii
                I2C_write((uint8 *)b0, 0x3E, 0x00, 1);
                I2C_write((uint8 *)d,  0x3E, 0x40, 1);
...


I2C Master PSoC4 の設定でも共有可(通信のコンフリクトがあるだろう)

実験 I2C 接続 AE-AQM0802(LCD) Raspberry Pi Zero WH

実験 I2C 接続 AE-AQM0802(LCD) Raspberry Pi Zero WH
AQM0802(400Kbit/s) +3.3V駆動 参考 i2cset

★コマンドからI2Cへアクセス
$ sudo raspi-config #I2C を有効にする
$ i2cdetect -y 1 #I2C bus 1 に接続されているデバイスを調べる
$ i2cset -y 1 0x3e 0x00 0x38 0x39 0x14 0x78 0x5f 0x6a i #1=I2C bus 1 -y=no confirmation i=block data(not 1 byte)
$ i2cset -y 1 0x3e 0x00 0x0c 0x01 i
$ i2cset -y 1 0x3e 0x00 0x06 b #b=one byte data
$ i2cset -y 1 0x3e 0x00 0x80 b #1st line
$ i2cset -y 1 0x3e 0x40 0x48 0x65 0x6c 0x6c 0x6f i #’Hello’

★I2C通信速度変更 speed 要再起動
/boot/config.txt
dtparam=i2c_baudrate=50000 #50Kbit/s

★Python3からI2Cへアクセス (baudrate=400000) 動作OK

import smbus,time
i2c1=smbus.SMBus(1)
i2c1.write_i2c_block_data(0x3e,0x00,[0x38,0x39,0x14,0x78,0x5f,0x6a])
time.sleep(0.200) #1=1s 0.001=1ms
i2c1.write_i2c_block_data(0x3e,0x00,[0x0c,0x01])
time.sleep(0.002) #1=1s 0.001=1ms
i2c1.write_byte_data(0x3e,0x00,0x06)
i2c1.write_byte_data(0x3e,0x00,0x80)
i2c1.write_i2c_block_data(0x3e,0x40,[0x48,0x65,0x6c,0x6c,0x6f]) #'Hello'

★I2C エラー処理準備 (通信中に SDA,SCL,+3.3V (どの信号でも)の障害でエラー発生)
[Errno 121] Remote I/O error

import smbus,time

i2c1=smbus.SMBus(1) #0=(port I2C0), 1=(port I2C1)
i2c1.write_i2c_block_data(0x3e,0x00,[0x38,0x39,0x14,0x78,0x5f,0x6a]); time.sleep(0.200) #200ms
i2c1.write_i2c_block_data(0x3e,0x00,[0x0c,0x01]); time.sleep(0.002) #2ms
i2c1.write_byte_data(0x3e,0x00,0x06)
i2c1.write_byte_data(0x3e,0x00,0x80)
i2c1.write_i2c_block_data(0x3e,0x40,[0x48,0x65,0x6c,0x6c,0x6f]) #'Hello'

d=1
while 1:
    d=0x30+((1+d)%10) #9-0 countdown ascii
    time.sleep(1.000) #1s
    try:
        i2c1.write_byte_data(0x3e,0x00,0xc0) #2nd line
        i2c1.write_byte_data(0x3e,0x40,d)
    except Exception as e:
        pass ;print(e) #error if exist

カーネル対応のRTC(リアルタイムクロック デバイス) Raspberry Pi Zero WH

カーネル対応のRTC(リアルタイムクロック デバイス) Raspberry Pi Zero WH
/libmodules/…./kernel/drivers/rtc
ds1302 07(xtal外付、基板モジュール@秋月) 74 90
m41t80(I2C xtal外付) 93(SPI xtal外付) 94

非対応 rx8900(I2C xtal内蔵 セイコー 別シリーズは対応 IC+基板@秋月 347円@mouser)
非対応 M41T62(I2C xtal内蔵 ST 別シリーズは対応 223円@mouser VBAT切替問題?)