LoginSignup
0
0

More than 3 years have passed since last update.

MDBT42Q (nRF52832) で I2C を使用する方法

Last updated at Posted at 2020-03-08

BLE モジュール MDBT42Q

台湾 Raytac 社の BLE モジュール MDBT42Q は nRF52832 を搭載しており、野良バッジ初号機で採用しています。
野良バッジ弐号機の開発にあたり I2C 接続対応が必要になりました。

I2C 対応

8x8 LED Matrix の小型化(ピッチ幅:3mm→1.9mm、サイズ:32mm→20mm)に合わせて制御ドライバICをMAX7219からHT16K33に変更します。
MAX7219は8x8 LED Matrix 1個を5線(VCC、GND、CLK、DIN、CS)で制御しますが、HT16K33は8x8 LED Matrix 2個を4線(VCC、GND、SDA、SCL)で制御できます。

開発環境

開発環境の構築は以下のページを参考にし、普段慣れている Arduino 開発環境を選択しました。
https://qiita.com/nanbuwks/items/d26447c0bfa28b1d05df

私の開発環境の変更箇所は以下でした。

書き込み装置

J-Link を使用しました。
(J-Linkと野良バッジ初号機との接続)

Arduino IDE の設定

「ツール」-「ボード:」→「Generic nRF52」
「ツール」-「Softdevice:」→「S132」
「ツール」-「Low Frequency Clock:」→「RC Oscillator」
「ツール」-「書込装置:」→「J-Link」

I2Cピン番号の指定ができない

Arduino や ESP8266、ESP32 と同じように Wire.begin() 関数でピン番号を指定することができませんでした。
(ピン番号を指定しない場合は問題ありません。)

MDBT42Q_I2C_00.ino
#include <Wire.h>

void setup() {
  Wire.begin(4, 5);  // 4:SDA 5:SCL
}

void loop() {
}

エラーの内容

Arduino:1.8.9 (Mac OS X), ボード:"Generic nRF52, S132, RC Oscillator"

/Users/kitazaki/Documents/Arduino/MDBT42Q_I2C_00/MDBT42Q_I2C_00.ino: In function 'void setup()':
MDBT42Q_I2C_00:4:17: error: no matching function for call to 'TwoWire::begin(int, int)'
   Wire.begin(4,5);
                 ^
In file included from /Users/kitazaki/Documents/Arduino/MDBT42Q_I2C_00/MDBT42Q_I2C_00.ino:1:0:
/Users/kitazaki/Documents/Arduino/hardware/sandeepmistry/nRF5/libraries/Wire/Wire.h:45:10: note: candidate: void TwoWire::begin()
     void begin();
          ^
/Users/kitazaki/Documents/Arduino/hardware/sandeepmistry/nRF5/libraries/Wire/Wire.h:45:10: note:   candidate expects 0 arguments, 2 provided
/Users/kitazaki/Documents/Arduino/hardware/sandeepmistry/nRF5/libraries/Wire/Wire.h:47:10: note: candidate: void TwoWire::begin(uint8_t)
     void begin(uint8_t);
          ^
/Users/kitazaki/Documents/Arduino/hardware/sandeepmistry/nRF5/libraries/Wire/Wire.h:47:10: note:   candidate expects 1 argument, 2 provided
exit status 1
no matching function for call to 'TwoWire::begin(int, int)'

解決方法

ソースコードを読んで Wire.setPins() 関数でピン番号を指定できることが分かりました。
(リポジトリ)
https://github.com/sandeepmistry/arduino-nRF5/libraries/Wire/
(ローカル環境の場合)
/Users/[ユーザー名]/Arduino/hardware/sandeepmistry/nRF5/libraries/Wire/
(ソースコード)
Wire.h
Wire_nRF52.cpp

MDBT42Q_I2C_01.ino
#include <Wire.h>

void setup() {
  Wire.setPins(4, 5);  // 4:SDA 5:SCL
  Wire.begin();
}

これで開発が一歩前進できて良かったです。

0
0
0

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
0
0