Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SX1276GenericLib USBDevice
Fork of NonPingPong_PICO_LoRa by
OT07Lib/OT07_lib.h@5:9e751733a6f3, 2020-10-13 (annotated)
- Committer:
- walterluu
- Date:
- Tue Oct 13 00:45:46 2020 +0000
- Revision:
- 5:9e751733a6f3
- Parent:
- 3:85fc843a9d7d
Firmware Master and Slave in functional stage
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| walterluu | 3:85fc843a9d7d | 1 | #include "mbed.h" | 
| walterluu | 3:85fc843a9d7d | 2 | |
| walterluu | 3:85fc843a9d7d | 3 | //OT07 Registers | 
| walterluu | 3:85fc843a9d7d | 4 | #define OT07_STATUS 0x00 // OT07 status regiter | 
| walterluu | 3:85fc843a9d7d | 5 | #define OT07_INT_EN 0x01 // OT07 Interrupt Enable | 
| walterluu | 3:85fc843a9d7d | 6 | #define OT07_FIFO_W 0x04 // OT07 FIFO Write Pointer | 
| walterluu | 3:85fc843a9d7d | 7 | #define OT07_FIFO_R 0x05 // OT07 FIFO Read Pointer | 
| walterluu | 3:85fc843a9d7d | 8 | #define OT07_FIFO_OF 0x06 // OT07 FIFO Overflow Counter | 
| walterluu | 3:85fc843a9d7d | 9 | #define OT07_FIFO_COUNT 0x07 // OT07 FIFO Data Count | 
| walterluu | 3:85fc843a9d7d | 10 | #define OT07_FIFO_DATA 0x08 // OT07 FIFO Data | 
| walterluu | 3:85fc843a9d7d | 11 | #define OT07_FIFO_CNFG1 0x09 // OT07 FIFO Configuration 1 (FIFO_A_FULL) | 
| walterluu | 3:85fc843a9d7d | 12 | #define OT07_FIFO_CNFG2 0x0A // OT07 FIFO Configuration 2 | 
| walterluu | 3:85fc843a9d7d | 13 | #define OT07_SYS 0x0C // OT07 System Configuration | 
| walterluu | 3:85fc843a9d7d | 14 | #define OT07_ALARM_HIGH_MSB 0x10 // OT07 Alarm High MSB | 
| walterluu | 3:85fc843a9d7d | 15 | #define OT07_ALARM_HIGH_LSB 0x11 // OT07 Alarm High LSB | 
| walterluu | 3:85fc843a9d7d | 16 | #define OT07_ALARM_LOW_MSB 0x12 // OT07 Alarm Low MSB | 
| walterluu | 3:85fc843a9d7d | 17 | #define OT07_ALARM_LOW_LSB 0x13 // OT07 Alarm LOW LSB | 
| walterluu | 3:85fc843a9d7d | 18 | #define OT07_ADC_SETUP 0x14 // OT07 Temp Seneor Setup (ADC_RES[7:6]) & Convert Temperature [0] | 
| walterluu | 3:85fc843a9d7d | 19 | #define OT07_GPIO_SETUP 0x20 // OT07 GPIO Setup, sets GPIO modes | 
| walterluu | 3:85fc843a9d7d | 20 | #define OT07_GPIO_CTRL 0x21 // OT07 GPIO control | 
| walterluu | 3:85fc843a9d7d | 21 | #define OT07_ROM_ID 0x31 // OT07 ROM_ID address of LSB? | 
| walterluu | 3:85fc843a9d7d | 22 | |
| walterluu | 3:85fc843a9d7d | 23 | #define DEVICE_ACK 0 | 
| walterluu | 3:85fc843a9d7d | 24 | #define DEVICE_NACK 1 | 
| walterluu | 3:85fc843a9d7d | 25 | #define DEVICE_BAD_RESP 2 | 
| walterluu | 3:85fc843a9d7d | 26 | |
| walterluu | 3:85fc843a9d7d | 27 | #define MAX_DEVICES 64 // Maximum number of rom devices allowed | 
| walterluu | 3:85fc843a9d7d | 28 | #define ID_LENGTH 6 // Rom ID length in bytes | 
| walterluu | 3:85fc843a9d7d | 29 | |
| walterluu | 3:85fc843a9d7d | 30 | struct OT07_struct { | 
| walterluu | 3:85fc843a9d7d | 31 | char rom_id[ID_LENGTH]; // device ROM ID | 
| walterluu | 3:85fc843a9d7d | 32 | char I2C_address; // I2C addess, based on GPIO0 and GPIO1 at power up | 
| walterluu | 3:85fc843a9d7d | 33 | // Why char? | 
| walterluu | 3:85fc843a9d7d | 34 | }; | 
| walterluu | 3:85fc843a9d7d | 35 | |
| walterluu | 3:85fc843a9d7d | 36 | struct TempResponse { | 
| walterluu | 3:85fc843a9d7d | 37 | double tempC; // Temperature in °C | 
| walterluu | 3:85fc843a9d7d | 38 | int status; // Status of Temperature read. 0 for success, 1 for error | 
| walterluu | 3:85fc843a9d7d | 39 | }; | 
| walterluu | 3:85fc843a9d7d | 40 | |
| walterluu | 3:85fc843a9d7d | 41 | // ***************************************************************************** | 
| walterluu | 3:85fc843a9d7d | 42 | // OT07_write_register(char, char, char) writes single byte to OT07 | 
| walterluu | 3:85fc843a9d7d | 43 | // char I2C address | 
| walterluu | 3:85fc843a9d7d | 44 | // char OT07 register address | 
| walterluu | 3:85fc843a9d7d | 45 | // char data byte to be writen | 
| walterluu | 3:85fc843a9d7d | 46 | // returns 0 on success ACK, 1 on NACK | 
| walterluu | 3:85fc843a9d7d | 47 | // ***************************************************************************** | 
| walterluu | 3:85fc843a9d7d | 48 | int OT07_write_register(I2C *i2c, char I2C_add, char reg_add, char byte); | 
| walterluu | 3:85fc843a9d7d | 49 | |
| walterluu | 3:85fc843a9d7d | 50 | /// **************************************************************************** | 
| walterluu | 3:85fc843a9d7d | 51 | // OT07_write_register(char, char, char *, int) writes multiple bytes to OT07 | 
| walterluu | 3:85fc843a9d7d | 52 | // char I2C address | 
| walterluu | 3:85fc843a9d7d | 53 | // char OT07 register address | 
| walterluu | 3:85fc843a9d7d | 54 | // char * data vector of bytes to be written | 
| walterluu | 3:85fc843a9d7d | 55 | // int number of bytes to write | 
| walterluu | 3:85fc843a9d7d | 56 | // returns 0 on success ACK, 1 on NACK | 
| walterluu | 3:85fc843a9d7d | 57 | // ***************************************************************************** | 
| walterluu | 3:85fc843a9d7d | 58 | int OT07_write_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n); | 
| walterluu | 3:85fc843a9d7d | 59 | |
| walterluu | 3:85fc843a9d7d | 60 | // ***************************************************************************** | 
| walterluu | 3:85fc843a9d7d | 61 | // OT07_read_register(char, char, char *, int) writes single byte to OT07 | 
| walterluu | 3:85fc843a9d7d | 62 | // char I2C address | 
| walterluu | 3:85fc843a9d7d | 63 | // char OT07 register address | 
| walterluu | 3:85fc843a9d7d | 64 | // char * data vector for read bytes to be stored in | 
| walterluu | 3:85fc843a9d7d | 65 | // int number of bytes to read | 
| walterluu | 3:85fc843a9d7d | 66 | // returns 0 on success, 1 on fail | 
| walterluu | 3:85fc843a9d7d | 67 | // ***************************************************************************** | 
| walterluu | 3:85fc843a9d7d | 68 | int OT07_read_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n); | 
| walterluu | 3:85fc843a9d7d | 69 | |
| walterluu | 3:85fc843a9d7d | 70 | // ***************************************************************************** | 
| walterluu | 3:85fc843a9d7d | 71 | // convert_temperature(char) sends convert command to OT07 device | 
| walterluu | 3:85fc843a9d7d | 72 | // char I2C address | 
| walterluu | 3:85fc843a9d7d | 73 | // ***************************************************************************** | 
| walterluu | 3:85fc843a9d7d | 74 | void convert_temperature(I2C *i2c, char I2C_add); | 
| walterluu | 3:85fc843a9d7d | 75 | |
| walterluu | 3:85fc843a9d7d | 76 | //****************************************************************************** | 
| walterluu | 3:85fc843a9d7d | 77 | // get_temperature(char) read temperature from OT07 device FIFO register | 
| walterluu | 3:85fc843a9d7d | 78 | // char I2C address | 
| walterluu | 3:85fc843a9d7d | 79 | // returns TempResponse tempC = temperature in oC | 
| walterluu | 3:85fc843a9d7d | 80 | // status = register read result | 
| walterluu | 3:85fc843a9d7d | 81 | //****************************************************************************** | 
| walterluu | 5:9e751733a6f3 | 82 | TempResponse get_temperature(I2C *i2c, char I2C_add); | 
| walterluu | 5:9e751733a6f3 | 83 | |
| walterluu | 5:9e751733a6f3 | 84 | double calc_temperature(char *data); | 
