Driver for the NXP PCT2075 digital temperature sensor and thermal watchdog
NXP PCT2075 temperature sensor driver for mbed
This library is a driver for the [NXP PCT2075](http://www.nxp.com/products/sensors/i2c-temperature-voltage-monitors/ic-bus-fm-plus-1-degree-c-accuracy-digital-temperature-sensor-and-thermal-watchdog:PCT2075). It only handles the I2C communication with the sensor, it does not handle the OS interrupt line. The [mbed InterruptIn](https://developer.mbed.org/handbook/InterruptIn) library can be used for this.
example usage
#include <mbed.h> #include <PCT2075.h> Serial s(USBTX, USBRX); // tx, rx InterruptIn TempPinInt(PC4); LowPowerTicker ticker; static volatile bool temp_int = false; static volatile bool tick_int = false; int main( void ) { TempPinInt.mode(PullUp); PCT2075::Configuration config = { PCT2075::OS_FAULT_QUE_1, PCT2075::OS_ACTIVE_LOW, PCT2075::OS_MODE_INTERRUPT, PCT2075::DEVICE_MODE_SHUTDOWN }; temp_sensor.set_configuration(config); temp_sensor.set_idle_time(PCT2075::TIDLE_MAX); temp_sensor.set_hyst_temperature(2000); temp_sensor.set_os_temperature(2500); TempPinInt.fall(&on_fall); ticker.attach(&tick, 2.0); while(true) { sleep(); // wait to be woken up by ticker or temp sensor if (tick_int) { s.printf("Tick\r\n"); config.device_mode = PCT2075::DEVICE_MODE_NORMAL; temp_sensor.set_configuration(config); tick_int = false; } if (temp_int) { config.device_mode = PCT2075::DEVICE_MODE_SHUTDOWN; temp_sensor.set_configuration(config); uint16_t t = temp_sensor.read_temperature(); s.printf("Temperature: %d\r\n", t); temp_int = false; } } }
README.md@1:a2b7889eb4e9, 2016-09-23 (annotated)
- Committer:
- Seppe Stas
- Date:
- Fri Sep 23 15:38:34 2016 +0200
- Revision:
- 1:a2b7889eb4e9
- Parent:
- 0:396665cc3ea0
Added library files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
seppestas | 0:396665cc3ea0 | 1 | NXP PCT2075 temperature sensor driver for mbed |
seppestas | 0:396665cc3ea0 | 2 | ============================================== |
seppestas | 0:396665cc3ea0 | 3 | |
seppestas | 0:396665cc3ea0 | 4 | This library is a driver for the [NXP PCT2075](http://www.nxp.com/products/sensors/i2c-temperature-voltage-monitors/ic-bus-fm-plus-1-degree-c-accuracy-digital-temperature-sensor-and-thermal-watchdog:PCT2075). |
seppestas | 0:396665cc3ea0 | 5 | It only handles the I2C communication with the sensor, it does not handle the OS |
seppestas | 0:396665cc3ea0 | 6 | interupt line. The [mbed InterruptIn](https://developer.mbed.org/handbook/InterruptIn) library can be used for this. |
seppestas | 0:396665cc3ea0 | 7 | |
seppestas | 0:396665cc3ea0 | 8 | Example usage: |
seppestas | 0:396665cc3ea0 | 9 | |
seppestas | 0:396665cc3ea0 | 10 | ``` |
seppestas | 0:396665cc3ea0 | 11 | #include <mbed.h> |
seppestas | 0:396665cc3ea0 | 12 | #include <PCT2075.h> |
seppestas | 0:396665cc3ea0 | 13 | |
seppestas | 0:396665cc3ea0 | 14 | Serial s(USBTX, USBRX); // tx, rx |
seppestas | 0:396665cc3ea0 | 15 | |
seppestas | 0:396665cc3ea0 | 16 | InterruptIn TempPinInt(PC4); |
seppestas | 0:396665cc3ea0 | 17 | LowPowerTicker ticker; |
seppestas | 0:396665cc3ea0 | 18 | |
seppestas | 0:396665cc3ea0 | 19 | static volatile bool temp_int = false; |
seppestas | 0:396665cc3ea0 | 20 | static volatile bool tick_int = false; |
seppestas | 0:396665cc3ea0 | 21 | |
seppestas | 0:396665cc3ea0 | 22 | int main( void ) |
seppestas | 0:396665cc3ea0 | 23 | { |
seppestas | 0:396665cc3ea0 | 24 | TempPinInt.mode(PullUp); |
seppestas | 0:396665cc3ea0 | 25 | |
seppestas | 0:396665cc3ea0 | 26 | PCT2075::Configuration config = { |
seppestas | 0:396665cc3ea0 | 27 | PCT2075::OS_FAULT_QUE_1, |
seppestas | 0:396665cc3ea0 | 28 | PCT2075::OS_ACTIVE_LOW, |
seppestas | 0:396665cc3ea0 | 29 | PCT2075::OS_MODE_INTERRUPT, |
seppestas | 0:396665cc3ea0 | 30 | PCT2075::DEVICE_MODE_SHUTDOWN |
seppestas | 0:396665cc3ea0 | 31 | }; |
seppestas | 0:396665cc3ea0 | 32 | temp_sensor.set_configuration(config); |
seppestas | 0:396665cc3ea0 | 33 | temp_sensor.set_idle_time(PCT2075::TIDLE_MAX); |
seppestas | 0:396665cc3ea0 | 34 | |
seppestas | 0:396665cc3ea0 | 35 | temp_sensor.set_hyst_temperature(2000); |
seppestas | 0:396665cc3ea0 | 36 | temp_sensor.set_os_temperature(2500); |
seppestas | 0:396665cc3ea0 | 37 | |
seppestas | 0:396665cc3ea0 | 38 | TempPinInt.fall(&on_fall); |
seppestas | 0:396665cc3ea0 | 39 | ticker.attach(&tick, 2.0); |
seppestas | 0:396665cc3ea0 | 40 | |
seppestas | 0:396665cc3ea0 | 41 | while(true) { |
seppestas | 0:396665cc3ea0 | 42 | sleep(); // wait to be woken up by ticker or temp sensor |
seppestas | 0:396665cc3ea0 | 43 | |
seppestas | 0:396665cc3ea0 | 44 | if (tick_int) { |
seppestas | 0:396665cc3ea0 | 45 | s.printf("Tick\r\n"); |
seppestas | 0:396665cc3ea0 | 46 | config.device_mode = PCT2075::DEVICE_MODE_NORMAL; |
seppestas | 0:396665cc3ea0 | 47 | temp_sensor.set_configuration(config); |
seppestas | 0:396665cc3ea0 | 48 | tick_int = false; |
seppestas | 0:396665cc3ea0 | 49 | } |
seppestas | 0:396665cc3ea0 | 50 | |
seppestas | 0:396665cc3ea0 | 51 | if (temp_int) { |
seppestas | 0:396665cc3ea0 | 52 | config.device_mode = PCT2075::DEVICE_MODE_SHUTDOWN; |
seppestas | 0:396665cc3ea0 | 53 | temp_sensor.set_configuration(config); |
seppestas | 0:396665cc3ea0 | 54 | uint16_t t = temp_sensor.read_temperature(); |
seppestas | 0:396665cc3ea0 | 55 | s.printf("Temperature: %d\r\n", t); |
seppestas | 0:396665cc3ea0 | 56 | temp_int = false; |
seppestas | 0:396665cc3ea0 | 57 | } |
seppestas | 0:396665cc3ea0 | 58 | } |
seppestas | 0:396665cc3ea0 | 59 | } |
seppestas | 0:396665cc3ea0 | 60 | |
seppestas | 0:396665cc3ea0 | 61 | ``` |