Fixed some I2C items to work on STM Nucleo F446RE

Committer:
dmwahl
Date:
Thu Aug 08 15:36:58 2019 +0000
Revision:
1:4fbdf7768530
Parent:
0:f33e95899738
Rewrote I2C related items from ykita's original code. Not sure if the original was tested or not, but I was getting compile errors for Nucleo boards.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ykita 0:f33e95899738 1 /* mbed MCP9600 Library, for the MCP9600 Thermocouple EMF to temperature Converter
ykita 0:f33e95899738 2 * Copyright (c) 2018, Yoshiteru Kita, ULVAC-PHI, INC.
ykita 0:f33e95899738 3 *
ykita 0:f33e95899738 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
ykita 0:f33e95899738 5 * of this software and associated documentation files (the "Software"), to deal
ykita 0:f33e95899738 6 * in the Software without restriction, including without limitation the rights
ykita 0:f33e95899738 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ykita 0:f33e95899738 8 * copies of the Software, and to permit persons to whom the Software is
ykita 0:f33e95899738 9 * furnished to do so, subject to the following conditions:
ykita 0:f33e95899738 10 *
ykita 0:f33e95899738 11 * The above copyright notice and this permission notice shall be included in
ykita 0:f33e95899738 12 * all copies or substantial portions of the Software.
ykita 0:f33e95899738 13 *
ykita 0:f33e95899738 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ykita 0:f33e95899738 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ykita 0:f33e95899738 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ykita 0:f33e95899738 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ykita 0:f33e95899738 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ykita 0:f33e95899738 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ykita 0:f33e95899738 20 * THE SOFTWARE.
dmwahl 1:4fbdf7768530 21
dmwahl 1:4fbdf7768530 22 * Modified by David Wahl to work with STM Nucleo boards (tested on Nucleo F446RE). Rewrote I2C related items.
ykita 0:f33e95899738 23 */
dmwahl 1:4fbdf7768530 24
ykita 0:f33e95899738 25 #ifndef MBED_MCP9600_H
ykita 0:f33e95899738 26 #define MBED_MCP9600_H
ykita 0:f33e95899738 27
ykita 0:f33e95899738 28 #include "mbed.h"
ykita 0:f33e95899738 29
dmwahl 1:4fbdf7768530 30 class MCP9600
dmwahl 1:4fbdf7768530 31 {
ykita 0:f33e95899738 32 public:
ykita 0:f33e95899738 33 // Constructor with I2C instance and I2C Device Address of MCP9600
dmwahl 1:4fbdf7768530 34 MCP9600(I2C &i2c, int addr);
dmwahl 1:4fbdf7768530 35
ykita 0:f33e95899738 36 // Set I2C Device Address of MCP9600
dmwahl 1:4fbdf7768530 37 //void setAddress(char addr);
dmwahl 1:4fbdf7768530 38
ykita 0:f33e95899738 39 // Get I2C Device Address of this instance
ykita 0:f33e95899738 40 char getAddress(void);
dmwahl 1:4fbdf7768530 41
ykita 0:f33e95899738 42 // Read Temperature from Temperature Register
ykita 0:f33e95899738 43 // tempRegister 0:TH / 1:Tdelta / 2: TC
ykita 0:f33e95899738 44 // Return value: temperature in float value (degree C)
ykita 0:f33e95899738 45 float readTempRegister(char tempRegister);
ykita 0:f33e95899738 46
ykita 0:f33e95899738 47 // Read ADC register
ykita 0:f33e95899738 48 // Return value: 24 bit ADC register value
ykita 0:f33e95899738 49 // Refer MCP9600 datasheet for details.
ykita 0:f33e95899738 50 long readADCRegister(void);
dmwahl 1:4fbdf7768530 51
ykita 0:f33e95899738 52 // Write to Status Register
ykita 0:f33e95899738 53 // statRegister: Status data to write
ykita 0:f33e95899738 54 // About register bit, refer MCP9600 datasheet.
ykita 0:f33e95899738 55 char writeStatusRegister( char statRegister );
dmwahl 1:4fbdf7768530 56
ykita 0:f33e95899738 57 // Read Status Register
ykita 0:f33e95899738 58 // About register bit, refer MCP9600 datasheet.
ykita 0:f33e95899738 59 char readStatusRegister( void );
ykita 0:f33e95899738 60
ykita 0:f33e95899738 61 // Write to Sensor Configuration Register
ykita 0:f33e95899738 62 // cnfgRegister: Sensor Config data to write
ykita 0:f33e95899738 63 // About register bit, refer MCP9600 datasheet.
ykita 0:f33e95899738 64 char writeSensorConfigRegister( char cnfgRegister );
dmwahl 1:4fbdf7768530 65
ykita 0:f33e95899738 66 // Read Sensor Configuration Register
ykita 0:f33e95899738 67 // About register bit, refer MCP9600 datasheet.
ykita 0:f33e95899738 68 char readSensorConfigRegister( void );
dmwahl 1:4fbdf7768530 69
ykita 0:f33e95899738 70 // Write to Device Configuration Register
ykita 0:f33e95899738 71 // cnfgRegister: Device Config data to write
ykita 0:f33e95899738 72 // About register bit, refer MCP9600 datasheet.
ykita 0:f33e95899738 73 char writeDeviceConfigRegister( char cnfgRegister );
dmwahl 1:4fbdf7768530 74
ykita 0:f33e95899738 75 // Read Device Configuration Register
ykita 0:f33e95899738 76 // About register bit, refer MCP9600 datasheet.
ykita 0:f33e95899738 77 char readDeviceConfigRegister( void );
dmwahl 1:4fbdf7768530 78
ykita 0:f33e95899738 79 // Write to Alert Configuration Register
ykita 0:f33e95899738 80 // alertCH: Alert CH (1 to 4)
ykita 0:f33e95899738 81 // alertConfig: Alert Configuration data to write to register
ykita 0:f33e95899738 82 // Return Value: Alert Configuration Register value (Read from register)
ykita 0:f33e95899738 83 // About register bit, refer MCP9600 datasheet.
ykita 0:f33e95899738 84 char writeAlertConfigRegister(char alertCH, char alertConfig);
ykita 0:f33e95899738 85
ykita 0:f33e95899738 86 // Read Alter Configuration Register
ykita 0:f33e95899738 87 // alertCH: Alert CH (1 to 4)
ykita 0:f33e95899738 88 // Return Value: Alert Configuration Register value
ykita 0:f33e95899738 89 // About register bit, refer MCP9600 datasheet.
ykita 0:f33e95899738 90 char readAlertConfigRegister(char alertCH);
ykita 0:f33e95899738 91
ykita 0:f33e95899738 92 // Write to Alert Histerisis Register
ykita 0:f33e95899738 93 // alertCH: Alert CH (1 to 4)
ykita 0:f33e95899738 94 // alertHist: Alert Histerisis data to write to register
ykita 0:f33e95899738 95 // Return Value: Alert Histerisis Register value (Read from register)
ykita 0:f33e95899738 96 char writeAlertHisterisisRegister(char alertCH, char alertHist);
ykita 0:f33e95899738 97
ykita 0:f33e95899738 98 // Read Alter Histerisis Register
ykita 0:f33e95899738 99 // alertCH: Alert CH (1 to 4)
ykita 0:f33e95899738 100 // Return Value: Alert Histerisis Register value
ykita 0:f33e95899738 101 char readAlertHisterisisRegister(char alertCH);
dmwahl 1:4fbdf7768530 102
ykita 0:f33e95899738 103 // Write to Alert Limit Value Register
ykita 0:f33e95899738 104 // alertCH: Alert CH (1 to 4)
ykita 0:f33e95899738 105 // alertLimit_val: Alert Limit value to write to register
ykita 0:f33e95899738 106 // Return Value: Alert Limit value in real value (Read from register)
ykita 0:f33e95899738 107 float writeAlertLimit_MCP9600(char alertCH, float alertLimit_val);
ykita 0:f33e95899738 108
ykita 0:f33e95899738 109 // Read Alert Limit Value Register
ykita 0:f33e95899738 110 // alertCH: Alert CH (1 to 4)
ykita 0:f33e95899738 111 // Return Value: Alert Limit value in real value (Read from register)
ykita 0:f33e95899738 112 float readAlertLimit_MCP9600(char alertCH);
ykita 0:f33e95899738 113
ykita 0:f33e95899738 114 // Read Device ID / Revision Register
ykita 0:f33e95899738 115 // Return Value: Device ID / Revision (Read from register)
ykita 0:f33e95899738 116 char readIDRevisionRegister(void);
ykita 0:f33e95899738 117
ykita 0:f33e95899738 118 // Destructor
ykita 0:f33e95899738 119 ~MCP9600();
ykita 0:f33e95899738 120
ykita 0:f33e95899738 121 private:
dmwahl 1:4fbdf7768530 122 I2C &i2c;
dmwahl 1:4fbdf7768530 123 uint8_t mi2cAddress;
ykita 0:f33e95899738 124 };
ykita 0:f33e95899738 125
ykita 0:f33e95899738 126 #endif