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.
Dependents: mbed-os5-F303-18650-Manager-tp4056
MCP9808 Class Reference
Example: More...
#include <MCP9808.h>
Detailed Description
Example:
#include "mbed.h" #include "MCP9808.h" MCP9808 myMCP9808 ( p28, p27, MCP9808::MCP9808_ADDRESS_0 , 400000 ); // I2C_SDA | I2C_SCL Serial pc ( USBTX, USBRX ); // tx, rx DigitalOut myled ( LED1 ); Ticker newAction; // @brief Constants. // @brief Variables. volatile uint32_t myState; // State that indicates when to perform a new sample // @brief FUNCTION PROTOTYPES void changeDATA ( void ); //@brief FUNCTION FOR APPLICATION MAIN ENTRY. int main() { MCP9808::MCP9808_status_t aux; MCP9808::MCP9808_config_reg_t myMCP9808_Config; MCP9808::MCP9808_data_t myMCP9808_Data; pc.baud ( 115200 ); myled = 1; wait(3); myled = 0; // Shutdown the device, low-power mode enabled aux = myMCP9808.MCP9808_GetCONFIG ( &myMCP9808_Config ); myMCP9808_Config.shdn = MCP9808::CONFIG_SHDN_SHUTDOWN ; aux = myMCP9808.MCP9808_SetCONFIG ( myMCP9808_Config ); // Get manufacturer ID aux = myMCP9808.MCP9808_GetManufacturerID ( &myMCP9808_Data ); // Get device ID and device revision aux = myMCP9808.MCP9808_GetDeviceID ( &myMCP9808_Data ); // Configure the device // - T_UPPER and T_LOWER limit hysteresis at 0C // - Continuous conversion mode // - T_CRIT unlocked // - Window lock unlocked // - Alert output control disabled // - Alert output select: Alert for T_UPPER, T_LOWER and T_CRIT // - Alert output polaruty: Active-low // - Alert output mode: Comparator output // myMCP9808_Config.t_hyst = MCP9808::CONFIG_T_HYST_0_C ; myMCP9808_Config.shdn = MCP9808::CONFIG_SHDN_CONTINUOUS_CONVERSION ; myMCP9808_Config.t_crit = MCP9808::CONFIG_CRIT_LOCK_UNLOCKED ; myMCP9808_Config.t_win_lock = MCP9808::CONFIG_WIN_LOCK_UNLOCKED ; myMCP9808_Config.alert_cnt = MCP9808::CONFIG_ALERT_CNT_DISABLED ; myMCP9808_Config.alert_sel = MCP9808::CONFIG_ALERT_SEL_TUPPER_TLOWER_TCRIT ; myMCP9808_Config.alert_pol = MCP9808::CONFIG_ALERT_POL_ACTIVE_LOW ; myMCP9808_Config.alert_mod = MCP9808::CONFIG_ALERT_MOD_COMPARATOR_OUTPUT ; aux = myMCP9808.MCP9808_SetCONFIG ( myMCP9808_Config ); // Set resolution: +0.0625C ( t_CON ~ 250ms ) myMCP9808_Data.resolution = MCP9808::RESOLUTION_0_0625_C ; aux = myMCP9808.MCP9808_SetResolution ( myMCP9808_Data ); myState = 0UL; // Reset the variable newAction.attach( &changeDATA, 1U ); // the address of the function to be attached ( changeDATA ) and the interval ( 1s ) // Let the callbacks take care of everything while(1) { sleep(); if ( myState == 1UL ) { myled = 1U; // Get ambient temperature aux = myMCP9808.MCP9808_GetTA ( &myMCP9808_Data ); // Send data through the UART pc.printf ( "T: %0.4f C\r\n", myMCP9808_Data.t_a ); // Reset the variables myState = 0UL; myled = 0U; } } } // @brief changeDATA ( void ) // // @details It changes myState variable // // @param[in] N/A // // @param[out] N/A. // // @return N/A. // // // @author Manuel Caballero // @date 25/April/2019 // @version 25/April/2019 The ORIGIN // @pre N/A // @warning N/A. // void changeDATA ( void ) { myState = 1UL; }
Library for the MCP9808 ±0.5°C Maximum Accuracy Digital Temperature Sensor.
Definition at line 155 of file MCP9808.h.
Member Enumeration Documentation
| enum MCP9808_addresses_t |
DEFAULT ADDRESSES.
- Enumerator:
| enum MCP9808_registers_t |
REGISTERS.
| enum MCP9808_resolution_t |
| enum MCP9808_status_t |
| enum MCP9808_t_a_sign_t |
- Enumerator:
Constructor & Destructor Documentation
| MCP9808 | ( | PinName | sda, |
| PinName | scl, | ||
| uint32_t | addr, | ||
| uint32_t | freq | ||
| ) |
Create an MCP9808 object connected to the specified I2C pins.
- Parameters:
-
sda I2C data pin scl I2C clock pin addr I2C slave address freq I2C frequency
±0.5°C Maximum Accuracy Digital Temperature Sensor. Function file.
- Returns:
- N/A
- Date:
- 25/April/2019
- Version:
- 25/April/2019 The ORIGIN
- Precondition:
- N/A.
- Warning:
- N/A
- Precondition:
- This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ). All rights reserved.
Definition at line 20 of file MCP9808.cpp.
| ~MCP9808 | ( | ) |
Delete MCP9808 object.
Definition at line 28 of file MCP9808.cpp.
Member Function Documentation
| MCP9808::MCP9808_status_t MCP9808_GetCONFIG | ( | MCP9808_config_reg_t * | myCONFIG ) |
It gets CONFIG register value.
MCP9808_GetCONFIG ( MCP9808_config_reg_t* )
It gets CONFIG register value.
- Parameters:
-
[in] N/A. [out] myCONFIG,: CONFIG register value.
- Returns:
- Status of MCP9808_GetCONFIG.
- Date:
- 25/April/2019
- Version:
- 25/April/2019 The ORIGIN
- Precondition:
- N/A
- Warning:
- N/A.
Definition at line 53 of file MCP9808.cpp.
| MCP9808::MCP9808_status_t MCP9808_GetDeviceID | ( | MCP9808_data_t * | myDeviceID ) |
It gets both device ID and device revision.
MCP9808_GetDeviceID ( MCP9808_data_t* )
It gets device ID and device revision.
- Parameters:
-
[in] N/A [out] myDeviceID,: Both device ID and device revision
- Returns:
- Status of MCP9808_GetDeviceID.
- Date:
- 25/April/2019
- Version:
- 25/April/2019 The ORIGIN
- Precondition:
- Device ID should be 0x04 ( hexadecimal ).
- Warning:
- N/A.
Definition at line 320 of file MCP9808.cpp.
| MCP9808::MCP9808_status_t MCP9808_GetManufacturerID | ( | MCP9808_data_t * | myManufacturerID ) |
It gets manufacturer ID.
MCP9808_GetManufacturerID ( MCP9808_data_t* )
It gets manufacturer ID.
- Parameters:
-
[in] N/A. [out] myManufacturerID,: Manufacturer ID code
- Returns:
- Status of MCP9808_GetManufacturerID.
- Date:
- 25/April/2019
- Version:
- 25/April/2019 The ORIGIN
- Precondition:
- It should be 0x0054 ( hexadecimal ).
- Warning:
- N/A.
Definition at line 272 of file MCP9808.cpp.
| MCP9808::MCP9808_status_t MCP9808_GetRawTA | ( | MCP9808_data_t * | myRawTA ) |
It gets ambient temperature register ( raw value ).
MCP9808_GetRawTA ( MCP9808_data_t* )
It gets ambient temperature register ( raw value ).
- Parameters:
-
[in] N/A [out] myRawTA,: Raw T_A data.
- Returns:
- Status of MCP9808_GetRawTA.
- Date:
- 25/April/2019
- Version:
- 25/April/2019 The ORIGIN
- Precondition:
- N/A
- Warning:
- N/A.
Definition at line 162 of file MCP9808.cpp.
| MCP9808::MCP9808_status_t MCP9808_GetResolution | ( | MCP9808_data_t * | myResolution ) |
It gets the sensor resolution.
MCP9808_GetResolution ( MCP9808_data_t* )
It gets the sensor resolution.
- Parameters:
-
[in] N/A. [out] myResolution,: Device resolution.
- Returns:
- Status of MCP9808_GetResolution.
- Date:
- 25/April/2019
- Version:
- 25/April/2019 The ORIGIN
- Precondition:
- Resolution vs timing conversion: · Resolution: +0.5°C ( t_CONV = 30ms typical ) · Resolution: +0.25°C ( t_CONV = 65ms typical ) · Resolution: +0.125°C ( t_CONV = 130ms typical ) · Resolution: +0.0625°C ( power-up default, t_CONV = 250ms typical )
- Warning:
- N/A.
Definition at line 418 of file MCP9808.cpp.
| MCP9808::MCP9808_status_t MCP9808_GetT_Limit | ( | MCP9808_registers_t | myTLimit, |
| MCP9808_data_t * | myTValue_Limit | ||
| ) |
It gets temperature limit for: T_UPPER, T_LOWER or T_CRIT.
MCP9808_GetT_Limit ( MCP9808_registers_t, MCP9808_data_t* )
It gets temperature limit for: T_UPPER, T_LOWER or T_CRIT.
- Parameters:
-
[in] myTLimit,: Temperature limit register: T_UPPER, T_LOWER or T_CRIT. [out] myTValue_Limit,: Temperature limit value for the chosen register.
- Returns:
- Status of MCP9808_GetT_Limit.
- Date:
- 25/April/2019
- Version:
- 25/April/2019 The ORIGIN
- Precondition:
- N/A.
- Warning:
- N/A.
Definition at line 532 of file MCP9808.cpp.
| MCP9808::MCP9808_status_t MCP9808_GetTA | ( | MCP9808_data_t * | myTA ) |
It gets ambient temperature register ( Celsius degrees ).
MCP9808_GetTA ( MCP9808_data_t* )
It gets ambient temperature register ( Celsius degrees ).
- Parameters:
-
[in] N/A [out] myTA,: T_A value and flags.
- Returns:
- Status of MCP9808_GetTA.
- Date:
- 25/April/2019
- Version:
- 25/April/2019 The ORIGIN
- Precondition:
- This function also updates the comparison flags.
- Warning:
- N/A.
Definition at line 211 of file MCP9808.cpp.
| MCP9808::MCP9808_status_t MCP9808_SetCONFIG | ( | MCP9808_config_reg_t | myCONFIG ) |
It sets CONFIG register value.
MCP9808_SetCONFIG ( MCP9808_config_reg_t )
It sets CONFIG register value.
- Parameters:
-
[in] myCONFIG,: CONFIG register value. [out] N/A.
- Returns:
- Status of MCP9808_SetCONFIG.
- Date:
- 25/April/2019
- Version:
- 25/April/2019 The ORIGIN
- Precondition:
- MCP9808_GetCONFIG function should be called first to mask the bits.
- Warning:
- Be aware that some commands can NOT be written depending on Crit.Lock and/or Win.Lock values.
Definition at line 113 of file MCP9808.cpp.
| MCP9808::MCP9808_status_t MCP9808_SetResolution | ( | MCP9808_data_t | myResolution ) |
It sets the sensor resolution.
MCP9808_SetResolution ( MCP9808_data_t )
It sets the sensor resolution.
- Parameters:
-
[in] myResolution,: Device resolution. [out] N/A
- Returns:
- Status of MCP9808_SetResolution.
- Date:
- 25/April/2019
- Version:
- 25/April/2019 The ORIGIN
- Precondition:
- Resolution vs timing conversion: · Resolution: +0.5°C ( t_CONV = 30ms typical ) · Resolution: +0.25°C ( t_CONV = 65ms typical ) · Resolution: +0.125°C ( t_CONV = 130ms typical ) · Resolution: +0.0625°C ( power-up default, t_CONV = 250ms typical )
- Warning:
- N/A.
Definition at line 371 of file MCP9808.cpp.
| MCP9808::MCP9808_status_t MCP9808_SetT_Limit | ( | MCP9808_registers_t | myTLimit, |
| MCP9808_data_t | myTValue_Limit | ||
| ) |
It sets temperature limit for: T_UPPER, T_LOWER or T_CRIT.
MCP9808_SetT_Limit ( MCP9808_registers_t, MCP9808_data_t )
It sets temperature limit for: T_UPPER, T_LOWER or T_CRIT.
- Parameters:
-
[in] myTLimit,: Temperature limit register: T_UPPER, T_LOWER or T_CRIT. [in] myTValue_Limit,: Temperature limit value. [out] N/A.
- Returns:
- Status of MCP9808_SetT_Limit.
- Date:
- 25/April/2019
- Version:
- 25/April/2019 The ORIGIN
- Precondition:
- N/A.
- Warning:
- N/A.
Definition at line 465 of file MCP9808.cpp.
Generated on Sat Jul 23 2022 05:40:28 by
1.7.2