4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Nerves】i2cのクロックを400KHzに変更する方法

Last updated at Posted at 2024-08-13

はじめに

Nervesではデフォルトでi2cが使えるようになっていますが、このクロックは100KHzでした。
Raspberry Piのデフォルトでもあるようです。

このクロックを変更する方法を記述しておきます。

Raspberry pi OSの場合

config.txtに次のような記述をすればよいらしい。

dtparam=i2c_arm=on,i2c_arm_baudrate=400000

Nervesの場合

次の記述をconfig.exsに追加する

config.exs
config :nerves, :firmware,
  fwup_conf: "config/fwup.conf"

ターゲットに合った、fwup.confをconfigディレクトリにコピーする。
rpi0の場合、次のファイル。

cp deps/nerves_system_rpi0/fwup.conf config

fwup.confのconfig.txtに関する部分を次のように書き換える

fwup.conf
file-resource config.txt {
    host-path = "${NERVES_APP}/config/config.txt"
}

ターゲットに合った、config.txtをconfigディレクトリにコピーする。

cp deps/nerves_system_rpi0/config.txt config

config.txtのi2c_arm=onの行に、,i2c_arm_baudrate=400000を追加する

config.txt
dtparam=i2c_arm=on,i2c_arm_baudrate=400000

ファームウエアをビルドして起動すれば設定したクロックが反映されるはずです。

うまく行かなかった場合は、起動したNervesでcat "/boot/config.txt"を実行して設定が反映されてるか確認してみるとよいと思います。
反映されてない場合は、上記の何処かが抜けている可能性があるかとおもいます。

device treeを理解して特別な記述がいるのかもとヒヤヒヤしたんですが、config.txtの変更で対応できました。

i2cの規格では400KHzが上限だったと思うのですが、1MHzにしてみても設定できて動作しました。
プルアップ抵抗なので、これくらいが限界かも。

DS1Z_QuickPrint1.png

参考

4
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?