Thermometer indicating temperature and humidity by LED blink pattern
Dependencies: BLE_API mbed nRF51822
uvis25.cpp
00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is property of Nordic Semiconductor ASA. 00004 * Terms and conditions of usage are described in detail in NORDIC 00005 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 *df 00011 */ 00012 00013 #include <stdbool.h> 00014 #include <stdint.h> 00015 00016 #include <mbed.h> 00017 #include "uvis25.h" 00018 00019 I2C i2c_uvi(p22, p20); //SDA, SCL 00020 00021 static const char uvis25_expected_who_am_i = 0xCAU; //!< Expected value to get from WHO_AM_I register. 00022 00023 bool uvis25_init(void) 00024 { 00025 bool transfer_succeeded = true; 00026 00027 i2c_uvi.frequency(400000); 00028 uvis25_register_write(0x20 , 0x01); 00029 00030 // Read and verify product ID 00031 transfer_succeeded &= uvis25_verify_product_id(); 00032 00033 return transfer_succeeded; 00034 } 00035 00036 bool uvis25_verify_product_id(void) 00037 { 00038 char who_am_i[1]; 00039 uvis25_register_read(UVIS25_ADDRESS_WHO_AM_I, &who_am_i[0], 1); 00040 if (who_am_i[0] != uvis25_expected_who_am_i) return false; 00041 else return true; 00042 } 00043 00044 void uvis25_register_write(uint8_t register_address, uint8_t value) 00045 { 00046 char w2_data[2]; 00047 00048 w2_data[0] = register_address; 00049 w2_data[1] = value; 00050 i2c_uvi.write(UVIS25_WriteADDE, w2_data, 2); 00051 00052 } 00053 00054 void uvis25_register_read(char register_address, char *destination, uint8_t number_of_bytes) 00055 { 00056 i2c_uvi.write(UVIS25_WriteADDE, ®ister_address, 1, 1); 00057 i2c_uvi.read(UVIS25_WriteADDE, destination, number_of_bytes); 00058 } 00059 00060 00061 uint8_t UVIS25_ReadUVI(void) 00062 { 00063 char UVI_reading; 00064 uvis25_register_read(0x28, &UVI_reading, 1); 00065 return (uint8_t) UVI_reading; 00066 }
Generated on Fri Aug 26 2022 21:33:01 by 1.7.2