[[FrontPage]] #contents 2014/10/12からのアクセス回数 &counter; 組み込み系の場合I2Cを使えるととても便利です。 今回は、 [[インタフェース2014/8月号 汎用軽量OS uClinuxを試す>http://www.kumikomi.net/interface/sample/201408/if08_125.pdf]] で紹介されたI2Cを実際に試してみます。 ** I2C(GPIO版)のインストール設定((残念ながら、ハード版は失敗しました)) [#h3e2bb04] makeのmenuconfigで以下の箇所を選択します。 #pre{{ $ make menuconfig }} FM3 I2Cサポートの選択 - Device Drivers→I2C support - Device Drivers→I2C support→I2C device interface - Device Drivers→I2C support→I2C Hardware Bus support - Device Drivers→I2C support→I2C Hardware Bus support→GPIO-based bitbanging I2C I2C EEPROMの選択 - Device Drivers→Misc devices - Device Drivers→Misc devices→EEPROM support→I2C EEPROMs from most vendors *** initramfs内のファイルの変更 [#i01d878d] initramfsも修正したいので、オリジナルをinitramfs_orgにコピーします。 #pre{{ # mkdir initramfs_org # cp -r initramfs/* initramfs_org/ }} 今回はGPIO, USB, I2Cのみを使用するため、ネットワーク関連の設定を外します。 initramfs/etc/init.d/rcSを以下の様に修正します。 #pre{{ #!/bin/sh trap "" SIGHUP echo "Mounting proc" mount -t proc none /proc echo "Mounting sysfs" mount -t sysfs sysfs /sys }} 次にfstabにsysfsを追加しました。 #pre{{ # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc nodev,noexec,nosuid 0 0 sysfs /sys sysfs default 0 0 /dev/sda1 /vfat vfat noauto,rw 0 0 }} *** initramfs_lfcq1_min.txtの変更 [#u71ebb11] i2c関連の以下の設定を追加します。((RAMディスクの関連で、eepromとi2cdumpは外しました)) #pre{{ nod /dev/mem 600 0 0 c 1 1 nod /dev/kmem 600 0 0 c 1 2 nod /dev/zero 600 0 0 c 1 5 nod /dev/i2c-0 666 0 0 c 89 0 nod /dev/i2c-1 666 0 0 c 89 1 nod /dev/i2c-2 666 0 0 c 89 2 nod /dev/i2c-3 666 0 0 c 89 3 nod /dev/i2c-4 666 0 0 c 89 4 nod /dev/i2c-5 666 0 0 c 89 5 nod /dev/i2c-6 666 0 0 c 89 6 nod /dev/i2c-7 666 0 0 c 89 7 #ファイルの終わりに追加 dir /etc/init.d 755 0 0 file /etc/init.d/rcS initramfs/etc/init.d/rcS 755 0 0 file /bin/i2cdetect initramfs/i2c-tools/i2cdetect 755 0 0 #file /bin/i2cdump initramfs/i2c-tools/i2cdump 755 0 0 file /bin/i2cget initramfs/i2c-tools/i2cget 755 0 0 file /bin/i2cset initramfs/i2c-tools/i2cset 755 0 0 #file /bin/eeprom initramfs/i2c-tools/eeprom 755 0 0 }} *** uImageの再作成 [#d49f6e0f] 以下のコマンドでuImageの再作成をします。 #pre{{ $ export CROSS_COMPILE=arm-uclinuxeabi- $ export ARCH=arm $ make clean $ make uImage }} *** uImageのアップロード [#k17b92fa] GPIOと同様にpicocomを使ってシリアル通信でuImageをアップロードします。 #pre{{ $ sudo picocom --send-cmd "sb -vv" --receive-cmd "rb -vv" -b 115200 /dev/ttyUSB0 FM3> loady 0x60000000 Crtl-A Ctrl-S file: arch/arm/boot/uImage 転送途中経過Transfer complete *** exit status: 0 xyzMod? jI(j???? 6712(SOH)/0(STX)/0(CAN) packets, 7 retries ## Total Size = 0x000d1ae0 = 858848 Bytes }} uCLinuxをブートします。 #pre{{ FM3> bootm 0x60000000 ## Booting kernel from Legacy Image at 60000000 ... Image Name: Linux-2.6.33-arm1 Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 858784 Bytes = 838.7 kB Load Address: 60008000 Entry Point: 60008001 Verifying Checksum ... OK Loading Kernel Image ... OK 途中省略 Calibrating delay loop... 13.10 BogoMIPS (lpj=65536) Mount-cache hash table entries: 512 Switching to clocksource cm3-systick fuse init (API version 7.13) fm3_uart.0: ttyS0 at MMIO 0x40038000 (irq = 7) is a FM3 UART Port console [ttyS0] enabled i2c /dev entries driver i2c-gpio i2c-gpio.0: using pins 87 (SDA) and 88 (SCL) i2c-gpio i2c-gpio.1: using pins 52 (SDA) and 53 (SCL) Freeing init memory: 244K Welcome to ____ _ _ / __| ||_| _ _| | | | _ ____ _ _ _ _ | | | | | | || | _ \| | | |\ \/ / | |_| | |__| || | | | | |_| |/ \ | ___\____|_||_|_| |_|\____|\_/\_/ | | |_| Fujitsu FM3/FM4 port. For further information check: http://www.uclinux.org/ / # }} *** I2Cドライバーの動作確認 [#hc465959] i2cdetectで利用可能なアドレスを検索します。 #pre{{ i2cdetect -y 0 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: 50 51 52 53 54 55 56 57 -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- / # }} FRAMは、0x50から0x57に割り当てられています。 試しに0x50の0x01番に0xABを書き込んでみます。 最初に、0x01番の値を出力します。 #pre{{ / # i2cget -y 0 0x50 0x00 }} 0x50の0x01番に0xABを書き込み、再度読み直します。 #pre{{ / # i2cset -y 0 0x50 0x01 0xAB i / # i2cset -y 0 0x50 0x01 / # i2cget -y 0 0x50 0xab }} *** 温度センサーLM73を接続してみる [#cb8aea04] いつもの温度センサーLM73を接続してみます。 | FM3 | LM73 |h | CN3: 26 3.3V | 3: VDD | | CN2: 40 GND | 2: GND | | CN3: 43 SDA | 6: SDA | | CN2: 44 SCL | 4: SCL | &ref(LM73.png); これで、i2csetとi2cgetでLM73から温度を取得します。 #pre{{ / # cat <<\EOF >LM73.sh / # i2cset -y 1 0x4c 0x04 0x60 / # i2cset -y 1 0x4c 0x00 / # i2cget -y 1 0x4c 0x00 w 0xbc0c }} Macの計算機で0x0cbcを10進に変えると、3260であり、以下の計算から 25.5℃と求まります。 #pre{{ 3260*0.03125/4=25.4687 }} ** 参考文献 [#zfcb10ec] + [[インタフェース2014/8月号 汎用軽量OS uClinuxを試す>http://www.kumikomi.net/interface/sample/201408/if08_125.pdf]] ** コメント [#v212126f] #vote(おもしろかった,そうでもない,わかりずらい) 皆様のご意見、ご希望をお待ちしております。勉強会で分からなかったこと等、お気軽に問い合わせて下さい。 スパム防止に画像の文字列も入力してください。 #comment_kcaptcha