Arduino board run on Mbed-os6.8.1 (only test purpose not official). Need Mbed Studio(1.3.1) not online compiler. If you compile on the online compiler, you can get a hex file but it does NOT work!!!
Dependencies: APDS_9960 LPS22HB LSM9DS1 HTS221
1) DAPLink(LPC11U35)の準備
使用したボード →https://akizukidenshi.com/catalog/g/gK-12144/
プログラムは、nRF52840-MDK用に公開されているDAPLinkのコンパイル済のバイナリコードを使わせていただきました。
https://github.com/makerdiary/nrf52840-mdk/tree/master/firmware/daplink
LPC11U35への書込みは、SW1(ISP)を押したままSW2(RESET)を操作するとPCに「CRP DISABLD」という名称でマウントされるので、書込まれているfirmware.binを削除してから、上記のbinファイルをコピーすれば書き込みが行われます。
書込み完了後にSW1を押さずに起動すれば、「DAPLINK」として認識されます。
DETAILS.TXTでDAPLinkの内容を確認できます。
2) 接続
Arduino Nano 33 BLE Sense | LPC11U35 Interface CPU | コメント |
J3:Pin2 (ボード裏のパッド) | CN1:Pin3 P0_7 | SWDIO |
J3:Pin3 (ボード裏のパッド) | CN1:Pin4 P0_8 | SWCLK |
JP2:Pin14 GND | CN2:Pin1 GND | GND |
3)USBSerial
シリアル出力は、NANO 33 BLE SENSEボードのUSB端子経由で出力されます。
4)Mbed Studio 1.3.1を使って開発のこと!(オンラインコンパイラでは動作しません!)
5)ボードピン配置
3_check_LPS22HB/main3.cpp@2:9ee17e6e5900, 2021-02-28 (annotated)
- Committer:
- kenjiArai
- Date:
- Sun Feb 28 23:49:07 2021 +0000
- Revision:
- 2:9ee17e6e5900
- Parent:
- 1:cce280da16d4
change comments in select_example.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:f1a10797d9f6 | 1 | /* |
kenjiArai | 0:f1a10797d9f6 | 2 | * Mbed Application program |
kenjiArai | 1:cce280da16d4 | 3 | * Nano 33 BLE Sense board runs on mbed-OS6 |
kenjiArai | 0:f1a10797d9f6 | 4 | * LPS33HB -> MEMS nano pressure sensor: |
kenjiArai | 0:f1a10797d9f6 | 5 | * 260-1260 hPa absolute Digital output barometer |
kenjiArai | 0:f1a10797d9f6 | 6 | * by STMicroelectronics |
kenjiArai | 0:f1a10797d9f6 | 7 | * |
kenjiArai | 1:cce280da16d4 | 8 | * Copyright (c) 2020,'21 Kenji Arai / JH1PJL |
kenjiArai | 0:f1a10797d9f6 | 9 | * http://www7b.biglobe.ne.jp/~kenjia/ |
kenjiArai | 0:f1a10797d9f6 | 10 | * https://os.mbed.com/users/kenjiArai/ |
kenjiArai | 0:f1a10797d9f6 | 11 | * Started: January 22nd, 2020 |
kenjiArai | 1:cce280da16d4 | 12 | * Revised: February 28th, 2021 |
kenjiArai | 0:f1a10797d9f6 | 13 | */ |
kenjiArai | 0:f1a10797d9f6 | 14 | |
kenjiArai | 0:f1a10797d9f6 | 15 | // Pre-selection -------------------------------------------------------------- |
kenjiArai | 0:f1a10797d9f6 | 16 | #include "select_example.h" |
kenjiArai | 0:f1a10797d9f6 | 17 | //#define EXAMPLE_3_CHECK_LPS22HB |
kenjiArai | 0:f1a10797d9f6 | 18 | #ifdef EXAMPLE_3_CHECK_LPS22HB |
kenjiArai | 0:f1a10797d9f6 | 19 | |
kenjiArai | 0:f1a10797d9f6 | 20 | // Include -------------------------------------------------------------------- |
kenjiArai | 0:f1a10797d9f6 | 21 | #include "mbed.h" |
kenjiArai | 0:f1a10797d9f6 | 22 | #include "nano33blesense_iodef.h" |
kenjiArai | 0:f1a10797d9f6 | 23 | #include "LPS22HB.h" |
kenjiArai | 0:f1a10797d9f6 | 24 | |
kenjiArai | 0:f1a10797d9f6 | 25 | // Definition ----------------------------------------------------------------- |
kenjiArai | 0:f1a10797d9f6 | 26 | |
kenjiArai | 0:f1a10797d9f6 | 27 | // Constructor ---------------------------------------------------------------- |
kenjiArai | 0:f1a10797d9f6 | 28 | DigitalOut sen_pwr(PIN_VDD_ENV, 1); |
kenjiArai | 0:f1a10797d9f6 | 29 | DigitalOut i2c_pullup(PIN_I2C_PULLUP, 1); |
kenjiArai | 0:f1a10797d9f6 | 30 | I2C i2c(PIN_SDA1, PIN_SCL1); |
kenjiArai | 0:f1a10797d9f6 | 31 | LPS22HB *baro = NULL; |
kenjiArai | 0:f1a10797d9f6 | 32 | Timer t; |
kenjiArai | 0:f1a10797d9f6 | 33 | |
kenjiArai | 0:f1a10797d9f6 | 34 | // RAM ------------------------------------------------------------------------ |
kenjiArai | 0:f1a10797d9f6 | 35 | |
kenjiArai | 0:f1a10797d9f6 | 36 | // ROM / Constant data -------------------------------------------------------- |
kenjiArai | 0:f1a10797d9f6 | 37 | |
kenjiArai | 0:f1a10797d9f6 | 38 | // Function prototypes -------------------------------------------------------- |
kenjiArai | 1:cce280da16d4 | 39 | |
kenjiArai | 1:cce280da16d4 | 40 | // subroutin (must be at this below line and do NOT change order) ------------- |
kenjiArai | 1:cce280da16d4 | 41 | #include "usb_serial_as_stdio.h" |
kenjiArai | 1:cce280da16d4 | 42 | #include "check_revision.h" |
kenjiArai | 1:cce280da16d4 | 43 | #include "common.h" |
kenjiArai | 0:f1a10797d9f6 | 44 | |
kenjiArai | 0:f1a10797d9f6 | 45 | //------------------------------------------------------------------------------ |
kenjiArai | 0:f1a10797d9f6 | 46 | // Control Program |
kenjiArai | 0:f1a10797d9f6 | 47 | //------------------------------------------------------------------------------ |
kenjiArai | 0:f1a10797d9f6 | 48 | int main() |
kenjiArai | 0:f1a10797d9f6 | 49 | { |
kenjiArai | 1:cce280da16d4 | 50 | usb_serial_initialize(); |
kenjiArai | 1:cce280da16d4 | 51 | print_revision(); |
kenjiArai | 0:f1a10797d9f6 | 52 | i2c_pullup = 1; |
kenjiArai | 0:f1a10797d9f6 | 53 | sen_pwr = 1; |
kenjiArai | 1:cce280da16d4 | 54 | print_usb("Check LSM9DS1\r\n"); |
kenjiArai | 1:cce280da16d4 | 55 | ThisThread::sleep_for(200ms); |
kenjiArai | 0:f1a10797d9f6 | 56 | // check I2C line |
kenjiArai | 0:f1a10797d9f6 | 57 | check_i2c_connected_devices(); |
kenjiArai | 0:f1a10797d9f6 | 58 | baro = new LPS22HB(i2c, LPS22HB_G_CHIP_ADDR); |
kenjiArai | 0:f1a10797d9f6 | 59 | uint8_t id = baro->read_id(); |
kenjiArai | 0:f1a10797d9f6 | 60 | if (id == I_AM_LPS22HB) { |
kenjiArai | 1:cce280da16d4 | 61 | print_usb("LPS22H is ready. ID = 0x%x\r\n", id); |
kenjiArai | 0:f1a10797d9f6 | 62 | } else { |
kenjiArai | 1:cce280da16d4 | 63 | print_usb("LPS22H is NOT ready. return value = 0x%x\r\n", id); |
kenjiArai | 0:f1a10797d9f6 | 64 | } |
kenjiArai | 0:f1a10797d9f6 | 65 | baro->set_odr(); |
kenjiArai | 0:f1a10797d9f6 | 66 | uint32_t n = 0; |
kenjiArai | 0:f1a10797d9f6 | 67 | while(true) { |
kenjiArai | 0:f1a10797d9f6 | 68 | t.reset(); |
kenjiArai | 0:f1a10797d9f6 | 69 | t.start(); |
kenjiArai | 0:f1a10797d9f6 | 70 | baro->get(); |
kenjiArai | 0:f1a10797d9f6 | 71 | while (baro->data_ready() == 0){ |
kenjiArai | 1:cce280da16d4 | 72 | ThisThread::sleep_for(2ms); |
kenjiArai | 0:f1a10797d9f6 | 73 | } |
kenjiArai | 1:cce280da16d4 | 74 | print_usb("Pressure:,%6.1f,[hPa],Temperature:,%+4.1f,[degC],", |
kenjiArai | 0:f1a10797d9f6 | 75 | baro->pressure(), baro->temperature()); |
kenjiArai | 0:f1a10797d9f6 | 76 | ++n; |
kenjiArai | 1:cce280da16d4 | 77 | uint32_t passed_time = chrono::duration_cast<chrono::milliseconds>( |
kenjiArai | 1:cce280da16d4 | 78 | t.elapsed_time()).count(); |
kenjiArai | 1:cce280da16d4 | 79 | print_usb("processing time:,%2d,[ms],count:,%4d\r\n", passed_time, n); |
kenjiArai | 0:f1a10797d9f6 | 80 | if (passed_time < 999){ |
kenjiArai | 1:cce280da16d4 | 81 | ThisThread::sleep_for(chrono::milliseconds(1000 - passed_time)); |
kenjiArai | 0:f1a10797d9f6 | 82 | } |
kenjiArai | 0:f1a10797d9f6 | 83 | } |
kenjiArai | 0:f1a10797d9f6 | 84 | } |
kenjiArai | 0:f1a10797d9f6 | 85 | |
kenjiArai | 0:f1a10797d9f6 | 86 | #endif // EXAMPLE_3_CHECK_LPS22HB |