Steven Kay
/
MCP9803_NUCLEO_Driver
Initial I2C Working
MCP9803/MCP9803.h@2:832cb4376d2a, 2017-03-29 (annotated)
- Committer:
- sk398
- Date:
- Wed Mar 29 17:55:38 2017 +0000
- Revision:
- 2:832cb4376d2a
- Parent:
- 1:444546e8cd20
Working version on the NUCLEO-F446RE board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sk398 | 0:fbf82bf637bb | 1 | /******************************************************************************************** |
sk398 | 0:fbf82bf637bb | 2 | |
sk398 | 0:fbf82bf637bb | 3 | Filename: MCP9803.h |
sk398 | 0:fbf82bf637bb | 4 | |
sk398 | 0:fbf82bf637bb | 5 | Original Author: Steven Kay |
sk398 | 0:fbf82bf637bb | 6 | |
sk398 | 0:fbf82bf637bb | 7 | Development Group: Autonomous Systems Group, RAL Space |
sk398 | 0:fbf82bf637bb | 8 | |
sk398 | 0:fbf82bf637bb | 9 | Original Creation Date: April 2017 |
sk398 | 0:fbf82bf637bb | 10 | |
sk398 | 0:fbf82bf637bb | 11 | Description: <Desc> |
sk398 | 0:fbf82bf637bb | 12 | |
sk398 | 0:fbf82bf637bb | 13 | Revision History: Version 1.0 - Initial Release |
sk398 | 0:fbf82bf637bb | 14 | |
sk398 | 0:fbf82bf637bb | 15 | *********************************************************************************************/ |
sk398 | 0:fbf82bf637bb | 16 | |
sk398 | 0:fbf82bf637bb | 17 | #ifndef MCP9803_H |
sk398 | 0:fbf82bf637bb | 18 | #define MCP9803_H |
sk398 | 0:fbf82bf637bb | 19 | |
sk398 | 0:fbf82bf637bb | 20 | #include "mbed.h" |
sk398 | 0:fbf82bf637bb | 21 | |
sk398 | 2:832cb4376d2a | 22 | #define SUCCESS 0 |
sk398 | 2:832cb4376d2a | 23 | #define FAILURE 1 |
sk398 | 2:832cb4376d2a | 24 | |
sk398 | 2:832cb4376d2a | 25 | #define FAIL_EVEN_VALUE 0xFF |
sk398 | 2:832cb4376d2a | 26 | #define FAIL_ODD_VALUE 0x00 |
sk398 | 2:832cb4376d2a | 27 | |
sk398 | 2:832cb4376d2a | 28 | #define TEMP_REG_POINT 0x00 |
sk398 | 2:832cb4376d2a | 29 | #define CONFIG_REG_POINT 0x01 |
sk398 | 2:832cb4376d2a | 30 | #define TEMP_HYST_POINT 0x02 |
sk398 | 2:832cb4376d2a | 31 | #define TEMP_LIM_SET_POINT 0x03 |
sk398 | 2:832cb4376d2a | 32 | |
sk398 | 2:832cb4376d2a | 33 | #define CONFIG_CMD_LENGTH 2 |
sk398 | 2:832cb4376d2a | 34 | #define TEMP_DATA_LENGTH 2 |
sk398 | 2:832cb4376d2a | 35 | |
sk398 | 2:832cb4376d2a | 36 | #define READ_TEMP_FAIL_VALUE 0x0FF0 |
sk398 | 2:832cb4376d2a | 37 | #define READ_TEMP_FAIL_ERROR -2000 |
sk398 | 2:832cb4376d2a | 38 | |
sk398 | 2:832cb4376d2a | 39 | #define CELCIUS 0x01 |
sk398 | 2:832cb4376d2a | 40 | #define FARENHEIT 0x02 |
sk398 | 2:832cb4376d2a | 41 | #define KELVIN 0x03 |
sk398 | 2:832cb4376d2a | 42 | #define FORMAT_FAIL -1000 |
sk398 | 2:832cb4376d2a | 43 | |
sk398 | 2:832cb4376d2a | 44 | #define RAW_TO_C 0.0625 |
sk398 | 2:832cb4376d2a | 45 | #define C_F_1 1.8 |
sk398 | 2:832cb4376d2a | 46 | #define C_F_2 32 |
sk398 | 2:832cb4376d2a | 47 | #define C_TO_F 273.15 |
sk398 | 2:832cb4376d2a | 48 | |
sk398 | 2:832cb4376d2a | 49 | |
sk398 | 0:fbf82bf637bb | 50 | union CONFIG_REG |
sk398 | 0:fbf82bf637bb | 51 | { |
sk398 | 0:fbf82bf637bb | 52 | struct |
sk398 | 0:fbf82bf637bb | 53 | { |
sk398 | 0:fbf82bf637bb | 54 | unsigned int SHUTDOWN_BIT: 1; |
sk398 | 0:fbf82bf637bb | 55 | unsigned int COMP_INT_BIT: 1; |
sk398 | 0:fbf82bf637bb | 56 | unsigned int ALERT_POLARITY_BIT: 1; |
sk398 | 0:fbf82bf637bb | 57 | unsigned int FAULT_QUEUE: 2; |
sk398 | 0:fbf82bf637bb | 58 | unsigned int ADC_RES: 2; |
sk398 | 0:fbf82bf637bb | 59 | unsigned int ONE_SHOT: 1; |
sk398 | 0:fbf82bf637bb | 60 | } CONFIG_BITS; |
sk398 | 0:fbf82bf637bb | 61 | |
sk398 | 0:fbf82bf637bb | 62 | uint8_t CONFIG_VALUE; |
sk398 | 0:fbf82bf637bb | 63 | }; |
sk398 | 0:fbf82bf637bb | 64 | |
sk398 | 0:fbf82bf637bb | 65 | class MCP9803 |
sk398 | 0:fbf82bf637bb | 66 | { |
sk398 | 0:fbf82bf637bb | 67 | |
sk398 | 0:fbf82bf637bb | 68 | public: |
sk398 | 0:fbf82bf637bb | 69 | MCP9803(PinName sda, PinName scl, int Address, int frequency); |
sk398 | 2:832cb4376d2a | 70 | int ConfigSensor( int shutdown, int comp_int, int alert_polarity, |
sk398 | 2:832cb4376d2a | 71 | int fault_guide, int adc_res, int one_shot); |
sk398 | 2:832cb4376d2a | 72 | |
sk398 | 2:832cb4376d2a | 73 | |
sk398 | 2:832cb4376d2a | 74 | int RawTempValue(); |
sk398 | 2:832cb4376d2a | 75 | float FormattedTempValue(int format); |
sk398 | 0:fbf82bf637bb | 76 | |
sk398 | 0:fbf82bf637bb | 77 | private: |
sk398 | 0:fbf82bf637bb | 78 | I2C *_I2C; |
sk398 | 0:fbf82bf637bb | 79 | int chipAddress; |
sk398 | 0:fbf82bf637bb | 80 | union CONFIG_REG CONFIG_REG_VALUE; |
sk398 | 1:444546e8cd20 | 81 | |
sk398 | 1:444546e8cd20 | 82 | char *inBuffer; |
sk398 | 1:444546e8cd20 | 83 | |
sk398 | 2:832cb4376d2a | 84 | int I2C_Write(char *dataOut,int dataLen); |
sk398 | 2:832cb4376d2a | 85 | char *I2C_Read(int dataLen); |
sk398 | 2:832cb4376d2a | 86 | void setBufferSize(int dataLen); |
sk398 | 0:fbf82bf637bb | 87 | |
sk398 | 0:fbf82bf637bb | 88 | }; |
sk398 | 0:fbf82bf637bb | 89 | |
sk398 | 0:fbf82bf637bb | 90 | #endif |