±0.5°C Maximum Accuracy Digital Temperature Sensor
Dependents: mbed-os5-F303-18650-Manager-tp4056
Diff: MCP9808.cpp
- Revision:
- 3:54515d036e93
- Parent:
- 2:da266f1b2273
--- a/MCP9808.cpp Thu Apr 25 10:39:40 2019 +0000 +++ b/MCP9808.cpp Thu Apr 25 18:27:56 2019 +0000 @@ -121,8 +121,8 @@ myCONFIG.alert_stat | myCONFIG.alert_cnt | myCONFIG.alert_sel | myCONFIG.alert_pol | myCONFIG.alert_mod ); cmd[0] = MCP9808_CONFIG; - cmd[1] = (char)( myConfigAux >> 8U ); - cmd[2] = (char)( myConfigAux & 0xFF ); + cmd[1] = (uint8_t)( myConfigAux >> 8U ); + cmd[2] = (uint8_t)( myConfigAux & 0xFF ); aux = _i2c.write ( _MCP9808_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), false ); @@ -210,8 +210,8 @@ */ MCP9808::MCP9808_status_t MCP9808::MCP9808_GetTA ( MCP9808_data_t* myTA ) { - char myUpperByte = 0U; - char myLowerByte = 0U; + uint8_t myUpperByte = 0U; + uint8_t myLowerByte = 0U; MCP9808::MCP9808_status_t aux; /* Read the register */ @@ -225,17 +225,17 @@ myTA->t_a_sign = (MCP9808_t_a_sign_t)( myTA->t_a_raw & T_A_TA_SIGN_MASK ); /* Mask the ambient temperature value */ - myUpperByte = (char)( myTA->t_a_raw >> 8U ); - myLowerByte = (char)( myTA->t_a_raw & 0xFF ); + myUpperByte = (uint8_t)( myTA->t_a_raw >> 8U ); + myLowerByte = (uint8_t)( myTA->t_a_raw & 0xFF ); /* Clean the flags */ - myUpperByte &= ~(char)( ( T_A_TA_VS_TCRIT_MASK | T_A_TA_VS_TUPPER_MASK | T_A_TA_VS_TLOWER_MASK ) >> 8U ); + myUpperByte &= ~(uint8_t)( ( T_A_TA_VS_TCRIT_MASK | T_A_TA_VS_TUPPER_MASK | T_A_TA_VS_TLOWER_MASK ) >> 8U ); /* Check if T_A is negative/positive */ if ( myTA->t_a_sign == T_A_TA_SIGN_NEGATIVE ) { - /* Ambient temperature is NEGATIVE */ - myUpperByte &= ~(char)( T_A_TA_SIGN_MASK >> 8U ); // Clear the SIGN flag + /* Ambient uint8_t is NEGATIVE */ + myUpperByte &= ~(uint8_t)( T_A_TA_SIGN_MASK >> 8U ); // Clear the SIGN flag myTA->t_a = 256.0f - (float)( ( myUpperByte * 16.0f ) + ( myLowerByte / 16.0f ) ); // Ambient temperature value } else @@ -466,7 +466,7 @@ { char cmd[2] = { 0U }; int8_t myDecimal = 0U; - char myIntegral = 0U; + int8_t myIntegral = 0U; uint32_t aux; /* Only temperature limit registers can keep going */ @@ -478,7 +478,7 @@ { /* Parse the data */ myIntegral = (int8_t)myTValue_Limit.t_upper; - myDecimal = (char)( ( myTValue_Limit.t_upper - myIntegral ) * 100.0f ); + myDecimal = (uint8_t)( ( myTValue_Limit.t_upper - myIntegral ) * 100.0f ); /* Check the decimal part is correct; Valid decimal values: 0.00, 0.25, 0.50 or 0.75 */ myIntegral <<= 4U; @@ -532,7 +532,7 @@ MCP9808::MCP9808_status_t MCP9808::MCP9808_GetT_Limit ( MCP9808_registers_t myTLimit, MCP9808_data_t* myTValue_Limit ) { char cmd = 0U; - char myDecimal = 0U; + uint8_t myDecimal = 0U; float myAuxValue = 0U; uint32_t aux; @@ -575,7 +575,6 @@ default: return MCP9808_FAILURE; - break; }