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: Arduino_Nano33BLESense_examples
Revision 3:1fc3a35d731a, committed 2019-05-31
- Comitter:
- mcm
- Date:
- Fri May 31 14:26:29 2019 +0000
- Parent:
- 2:a975c212f502
- Commit message:
- The driver was completed and tested ( NUCLEO-L152RE ), it works as expected.
Changed in this revision
| HTS221.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/HTS221.h Fri May 31 11:28:03 2019 +0000
+++ b/HTS221.h Fri May 31 14:26:29 2019 +0000
@@ -22,7 +22,129 @@
/**
Example:
@code
+#include "mbed.h"
+#include "HTS221.h"
+HTS221 myHTS221 ( I2C_SDA, I2C_SCL, HTS221::HTS221_ADDRESS, 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()
+{
+ HTS221::HTS221_status_t aux;
+ HTS221::HTS221_data_t myHTS221_Data;
+
+ pc.baud ( 115200 );
+
+
+ myled = 1;
+ wait(3);
+ myled = 0;
+
+ // Get device ID
+ aux = myHTS221.HTS221_GetDeviceID ( &myHTS221_Data );
+
+ // Boot the device
+ aux = myHTS221.HTS221_SetBoot ();
+
+ // Set device in ACTIVE mode
+ aux = myHTS221.HTS221_SetPowerDown ( HTS221::CTRL_REG1_PD_ACTIVE_MODE );
+
+ // Get calibration coefficients
+ aux = myHTS221.HTS221_GetCalibrationCoefficients ( &myHTS221_Data );
+
+ // Output registers not updated until MSB and LSB reading
+ myHTS221_Data.bdu = HTS221::CTRL_REG1_BDU_DEFAULT_MODE;
+ aux = myHTS221.HTS221_SetBlockDataUpdate ( myHTS221_Data );
+
+ // Set resolution: 16 AVGT, 32 AVGH
+ myHTS221_Data.temperatureResolution = HTS221::AV_CONF_AVGT_16;
+ myHTS221_Data.humidityResolution = HTS221::AV_CONF_AVGH_32;
+ aux = myHTS221.HTS221_SetResolution ( myHTS221_Data );
+
+ // ODR
+ myHTS221_Data.odr = HTS221::CTRL_REG1_ODR_ONE_SHOT;
+ aux = myHTS221.HTS221_SetOutputDataRate ( myHTS221_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;
+
+ // Trigger to get a new data value
+ aux = myHTS221.HTS221_SetOneShot ();
+
+ // Wait until there is a new data
+ do {
+ aux = myHTS221.HTS221_GetOneShot ( &myHTS221_Data );
+ } while( myHTS221_Data.one_shot == HTS221::CTRL_REG2_ONE_SHOT_WAITING );
+
+
+ aux = myHTS221.HTS221_GetCalibrationCoefficients ( &myHTS221_Data );
+
+ // Get temperature
+ do {
+ aux = myHTS221.HTS221_GetTemperatureDataAvailable ( &myHTS221_Data );
+ } while( myHTS221_Data.t_da == HTS221::STATUS_REGISTER_T_DA_DATA_NOT_AVAILABLE );
+
+ aux = myHTS221.HTS221_GetTemperature ( &myHTS221_Data );
+
+ // Get humidity
+ aux = myHTS221.HTS221_GetHumidity ( &myHTS221_Data );
+
+ // Send data through the UART
+ pc.printf ( "T: %0.1f C, RH: %0.1f %%\r\n", myHTS221_Data.temperature, myHTS221_Data.humidity );
+
+
+ // 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 31/May/2019
+ // @version 31/May/2019 The ORIGIN
+ // @pre N/A
+ // @warning N/A.
+void changeDATA ( void )
+{
+ myState = 1UL;
+}
@endcode
*/