Example for using the MAX1472 RF Transmitter for low power data transmission.

Dependencies:   mbed-dev2 max32630fthr USBDevice

Committer:
tlyp
Date:
Fri Sep 04 20:41:34 2020 +0000
Revision:
4:2e3db197b7e2
Parent:
2:33b3b46a9c0d
Cleaned up header

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tlyp 2:33b3b46a9c0d 1 /*******************************************************************************
tlyp 2:33b3b46a9c0d 2 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
tlyp 2:33b3b46a9c0d 3 *
tlyp 2:33b3b46a9c0d 4 * Permission is hereby granted, free of charge, to any person obtaining a
tlyp 2:33b3b46a9c0d 5 * copy of this software and associated documentation files (the "Software"),
tlyp 2:33b3b46a9c0d 6 * to deal in the Software without restriction, including without limitation
tlyp 2:33b3b46a9c0d 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
tlyp 2:33b3b46a9c0d 8 * and/or sell copies of the Software, and to permit persons to whom the
tlyp 2:33b3b46a9c0d 9 * Software is furnished to do so, subject to the following conditions:
tlyp 2:33b3b46a9c0d 10 *
tlyp 2:33b3b46a9c0d 11 * The above copyright notice and this permission notice shall be included
tlyp 2:33b3b46a9c0d 12 * in all copies or substantial portions of the Software.
tlyp 2:33b3b46a9c0d 13 *
tlyp 2:33b3b46a9c0d 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
tlyp 2:33b3b46a9c0d 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
tlyp 2:33b3b46a9c0d 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
tlyp 2:33b3b46a9c0d 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
tlyp 2:33b3b46a9c0d 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
tlyp 2:33b3b46a9c0d 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
tlyp 2:33b3b46a9c0d 20 * OTHER DEALINGS IN THE SOFTWARE.
tlyp 2:33b3b46a9c0d 21 *
tlyp 2:33b3b46a9c0d 22 * Except as contained in this notice, the name of Maxim Integrated
tlyp 2:33b3b46a9c0d 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
tlyp 2:33b3b46a9c0d 24 * Products, Inc. Branding Policy.
tlyp 2:33b3b46a9c0d 25 *
tlyp 2:33b3b46a9c0d 26 * The mere transfer of this software does not imply any licenses
tlyp 2:33b3b46a9c0d 27 * of trade secrets, proprietary technology, copyrights, patents,
tlyp 2:33b3b46a9c0d 28 * trademarks, maskwork rights, or any other form of intellectual
tlyp 2:33b3b46a9c0d 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
tlyp 2:33b3b46a9c0d 30 * ownership rights.
tlyp 2:33b3b46a9c0d 31 *******************************************************************************
tlyp 2:33b3b46a9c0d 32 * @file MAX30208.cpp
tlyp 2:33b3b46a9c0d 33 * @brief This is the C++ file used for the MAX30208 human body temperature sensor library.
tlyp 2:33b3b46a9c0d 34 * @version 1.0
tlyp 2:33b3b46a9c0d 35 * @notes This file needs to be imported along with MAX30208.h for the program to work properly. This is library containing basic functions to be used in conjunction with the MAX30208. This library does not support any other devices. This is an MBed tested library.
tlyp 2:33b3b46a9c0d 36 *****************************************************************************/
tlyp 2:33b3b46a9c0d 37
tlyp 2:33b3b46a9c0d 38
tlyp 2:33b3b46a9c0d 39 #include "MAX30208.h"
tlyp 2:33b3b46a9c0d 40
tlyp 2:33b3b46a9c0d 41
tlyp 2:33b3b46a9c0d 42 //******************************************************************************
tlyp 2:33b3b46a9c0d 43 MAX30208::MAX30208(I2C &i2c, uint8_t slaveAddress):
tlyp 2:33b3b46a9c0d 44 m_i2c(i2c), m_writeAddress(slaveAddress << 1),
tlyp 2:33b3b46a9c0d 45 m_readAddress((slaveAddress << 1) | 1)
tlyp 2:33b3b46a9c0d 46 {
tlyp 2:33b3b46a9c0d 47 }
tlyp 2:33b3b46a9c0d 48
tlyp 2:33b3b46a9c0d 49
tlyp 2:33b3b46a9c0d 50 //******************************************************************************
tlyp 2:33b3b46a9c0d 51 MAX30208::~MAX30208(void) {
tlyp 2:33b3b46a9c0d 52 //empty block
tlyp 2:33b3b46a9c0d 53 }
tlyp 2:33b3b46a9c0d 54
tlyp 2:33b3b46a9c0d 55 //******************************************************************************
tlyp 2:33b3b46a9c0d 56 int32_t MAX30208::writeInterruptRegister(Configuration_InterruptEnable config) {
tlyp 2:33b3b46a9c0d 57 return(writeRegister(MAX30208::Interrupt_Enable,(config.all << 8),2));
tlyp 2:33b3b46a9c0d 58 }
tlyp 2:33b3b46a9c0d 59
tlyp 2:33b3b46a9c0d 60 //******************************************************************************
tlyp 2:33b3b46a9c0d 61 int32_t MAX30208::readInterruptRegister(Configuration_InterruptEnable &config) {
tlyp 2:33b3b46a9c0d 62 uint16_t data;
tlyp 2:33b3b46a9c0d 63 int32_t status;
tlyp 2:33b3b46a9c0d 64 status = readRegister(MAX30208::Interrupt_Enable, data, 1);
tlyp 2:33b3b46a9c0d 65 if(status == 0) {
tlyp 2:33b3b46a9c0d 66 config.all = data;
tlyp 2:33b3b46a9c0d 67 }
tlyp 2:33b3b46a9c0d 68 return(status);
tlyp 2:33b3b46a9c0d 69 }
tlyp 2:33b3b46a9c0d 70
tlyp 2:33b3b46a9c0d 71 //******************************************************************************
tlyp 2:33b3b46a9c0d 72 int32_t MAX30208::readStatus(uint16_t &value) {
tlyp 2:33b3b46a9c0d 73 return(readRegister(MAX30208::Status,value, 1));
tlyp 2:33b3b46a9c0d 74 }
tlyp 2:33b3b46a9c0d 75
tlyp 2:33b3b46a9c0d 76 //******************************************************************************
tlyp 2:33b3b46a9c0d 77 int32_t MAX30208::readWritePointer(uint16_t &value) {
tlyp 2:33b3b46a9c0d 78 return (readRegister(MAX30208::FIFO_Write_Pointer,value, 1));
tlyp 2:33b3b46a9c0d 79 }
tlyp 2:33b3b46a9c0d 80
tlyp 2:33b3b46a9c0d 81 //******************************************************************************
tlyp 2:33b3b46a9c0d 82 int32_t MAX30208::readReadPointer(uint16_t &value) {
tlyp 2:33b3b46a9c0d 83 return (readRegister(MAX30208::FIFO_Read_Pointer,value,1));
tlyp 2:33b3b46a9c0d 84 }
tlyp 2:33b3b46a9c0d 85
tlyp 2:33b3b46a9c0d 86 //******************************************************************************
tlyp 2:33b3b46a9c0d 87 int32_t MAX30208::writeReadPointer(uint8_t config) {
tlyp 2:33b3b46a9c0d 88 return(writeRegister(MAX30208::FIFO_Read_Pointer, (config << 8),2));
tlyp 2:33b3b46a9c0d 89 }
tlyp 2:33b3b46a9c0d 90
tlyp 2:33b3b46a9c0d 91 //******************************************************************************
tlyp 2:33b3b46a9c0d 92 int32_t MAX30208::readOverflow(uint16_t &value) {
tlyp 2:33b3b46a9c0d 93 return(readRegister(MAX30208::FIFO_Overflow_Counter,value, 1));
tlyp 2:33b3b46a9c0d 94 }
tlyp 2:33b3b46a9c0d 95
tlyp 2:33b3b46a9c0d 96 //******************************************************************************
tlyp 2:33b3b46a9c0d 97 int32_t MAX30208::readDataCounter(uint16_t &value) {
tlyp 2:33b3b46a9c0d 98 return(readRegister(MAX30208::FIFO_Data_Counter,value, 1));
tlyp 2:33b3b46a9c0d 99 }
tlyp 2:33b3b46a9c0d 100
tlyp 2:33b3b46a9c0d 101 //******************************************************************************
tlyp 2:33b3b46a9c0d 102 int32_t MAX30208::readData(uint16_t &value) {
tlyp 2:33b3b46a9c0d 103 return(readRegister(MAX30208::FIFO_Data,value, 2));
tlyp 2:33b3b46a9c0d 104 }
tlyp 2:33b3b46a9c0d 105
tlyp 2:33b3b46a9c0d 106 //******************************************************************************
tlyp 2:33b3b46a9c0d 107 int32_t MAX30208::takeDataMeasurment() {
tlyp 2:33b3b46a9c0d 108 return(writeRegister(MAX30208::Temp_Sensor_Setup,0xFF00,2));
tlyp 2:33b3b46a9c0d 109 }
tlyp 2:33b3b46a9c0d 110
tlyp 2:33b3b46a9c0d 111 //******************************************************************************
tlyp 2:33b3b46a9c0d 112 int32_t MAX30208::readFIFOConfig1(uint16_t &value) {
tlyp 2:33b3b46a9c0d 113 return (readRegister(MAX30208::FIFO_Config1,value, 1));
tlyp 2:33b3b46a9c0d 114 }
tlyp 2:33b3b46a9c0d 115
tlyp 2:33b3b46a9c0d 116 //******************************************************************************
tlyp 2:33b3b46a9c0d 117 int32_t MAX30208::writeFIFOConfig1(uint8_t config) {
tlyp 2:33b3b46a9c0d 118 return(writeRegister(MAX30208::FIFO_Config1,(config << 8),2));
tlyp 2:33b3b46a9c0d 119 }
tlyp 2:33b3b46a9c0d 120
tlyp 2:33b3b46a9c0d 121 //******************************************************************************
tlyp 2:33b3b46a9c0d 122 int32_t MAX30208::readFIFOConfig2(Configuration_FIFOConfig2 &config) {
tlyp 2:33b3b46a9c0d 123 uint16_t data;
tlyp 2:33b3b46a9c0d 124 int32_t status;
tlyp 2:33b3b46a9c0d 125 status = readRegister(MAX30208::FIFO_Config2, data, 1);
tlyp 2:33b3b46a9c0d 126 if(status == 0){
tlyp 2:33b3b46a9c0d 127 config.all = data;
tlyp 2:33b3b46a9c0d 128 }
tlyp 2:33b3b46a9c0d 129 return(status);
tlyp 2:33b3b46a9c0d 130 }
tlyp 2:33b3b46a9c0d 131
tlyp 2:33b3b46a9c0d 132 //******************************************************************************
tlyp 2:33b3b46a9c0d 133 int32_t MAX30208::writeFIFOConfig2(Configuration_FIFOConfig2 config) {
tlyp 2:33b3b46a9c0d 134 return(writeRegister(MAX30208::FIFO_Config2,(config.all << 8),2));
tlyp 2:33b3b46a9c0d 135 }
tlyp 2:33b3b46a9c0d 136
tlyp 2:33b3b46a9c0d 137 //******************************************************************************
tlyp 2:33b3b46a9c0d 138 int32_t MAX30208::resetDevice() {
tlyp 2:33b3b46a9c0d 139 return(writeRegister(MAX30208::System_Control,(0x01 << 8),2));
tlyp 2:33b3b46a9c0d 140 }
tlyp 2:33b3b46a9c0d 141
tlyp 2:33b3b46a9c0d 142 //******************************************************************************
tlyp 2:33b3b46a9c0d 143 int32_t MAX30208::readAlarmHigh(uint16_t &temp) {
tlyp 2:33b3b46a9c0d 144 return readRegister(MAX30208::Alarm_High_MSB,temp, 2);
tlyp 2:33b3b46a9c0d 145 }
tlyp 2:33b3b46a9c0d 146
tlyp 2:33b3b46a9c0d 147 //******************************************************************************
tlyp 2:33b3b46a9c0d 148 int32_t MAX30208::writeAlarmHigh(uint16_t temp) {
tlyp 2:33b3b46a9c0d 149 return(writeRegister(MAX30208::Alarm_High_MSB, temp, 3));
tlyp 2:33b3b46a9c0d 150 }
tlyp 2:33b3b46a9c0d 151
tlyp 2:33b3b46a9c0d 152 //******************************************************************************
tlyp 2:33b3b46a9c0d 153 int32_t MAX30208::readAlarmLow(uint16_t &value) {
tlyp 2:33b3b46a9c0d 154 return (readRegister(MAX30208::Alarm_Low_MSB,value, 2));
tlyp 2:33b3b46a9c0d 155 }
tlyp 2:33b3b46a9c0d 156
tlyp 2:33b3b46a9c0d 157 //******************************************************************************
tlyp 2:33b3b46a9c0d 158 int32_t MAX30208::writeAlarmLow(uint16_t temp) {
tlyp 2:33b3b46a9c0d 159 return(writeRegister(MAX30208::Alarm_Low_MSB,temp,3));
tlyp 2:33b3b46a9c0d 160 }
tlyp 2:33b3b46a9c0d 161
tlyp 2:33b3b46a9c0d 162 //******************************************************************************
tlyp 2:33b3b46a9c0d 163 int32_t MAX30208::readGPIOSetup(Configuration_GPIOSetup &config) {
tlyp 2:33b3b46a9c0d 164 uint16_t data;
tlyp 2:33b3b46a9c0d 165 int32_t status;
tlyp 2:33b3b46a9c0d 166 status = readRegister(MAX30208::GPIO_Setup, data, 1);
tlyp 2:33b3b46a9c0d 167 if(status == 0) {
tlyp 2:33b3b46a9c0d 168 config.all = data;
tlyp 2:33b3b46a9c0d 169 }
tlyp 2:33b3b46a9c0d 170 return(status);
tlyp 2:33b3b46a9c0d 171 }
tlyp 2:33b3b46a9c0d 172
tlyp 2:33b3b46a9c0d 173 //******************************************************************************
tlyp 2:33b3b46a9c0d 174 int32_t MAX30208::writeGPIOSetup(Configuration_GPIOSetup config) {
tlyp 2:33b3b46a9c0d 175 return(writeRegister(MAX30208::GPIO_Setup,(config.all << 8),2));
tlyp 2:33b3b46a9c0d 176 }
tlyp 2:33b3b46a9c0d 177
tlyp 2:33b3b46a9c0d 178 //******************************************************************************
tlyp 2:33b3b46a9c0d 179 int32_t MAX30208::readGPIOControl(Configuration_GPIOControl &config) {
tlyp 2:33b3b46a9c0d 180 uint16_t data;
tlyp 2:33b3b46a9c0d 181 int32_t status;
tlyp 2:33b3b46a9c0d 182 status = readRegister(MAX30208::GPIO_Control, data, 1);
tlyp 2:33b3b46a9c0d 183 if(status == 0) {
tlyp 2:33b3b46a9c0d 184 config.all = data;
tlyp 2:33b3b46a9c0d 185 }
tlyp 2:33b3b46a9c0d 186 return(status);
tlyp 2:33b3b46a9c0d 187 }
tlyp 2:33b3b46a9c0d 188
tlyp 2:33b3b46a9c0d 189 //******************************************************************************
tlyp 2:33b3b46a9c0d 190 int32_t MAX30208::writeGPIOControl(Configuration_GPIOControl config) {
tlyp 2:33b3b46a9c0d 191 return(writeRegister(MAX30208::GPIO_Control,(config.all << 8),2));
tlyp 2:33b3b46a9c0d 192 }
tlyp 2:33b3b46a9c0d 193
tlyp 2:33b3b46a9c0d 194 //******************************************************************************
tlyp 2:33b3b46a9c0d 195 float MAX30208::toCelsius(uint16_t rawTemp) {
tlyp 2:33b3b46a9c0d 196 float celsius;
tlyp 2:33b3b46a9c0d 197 celsius = 0.005*rawTemp;
tlyp 2:33b3b46a9c0d 198 return celsius;
tlyp 2:33b3b46a9c0d 199 }
tlyp 2:33b3b46a9c0d 200
tlyp 2:33b3b46a9c0d 201 //******************************************************************************
tlyp 2:33b3b46a9c0d 202 float MAX30208::toFahrenheit(float temperatureC) {
tlyp 2:33b3b46a9c0d 203 float temperatureF;
tlyp 2:33b3b46a9c0d 204 temperatureF = (temperatureC * 1.8F) + 32.0f;
tlyp 2:33b3b46a9c0d 205 return temperatureF;
tlyp 2:33b3b46a9c0d 206 }
tlyp 2:33b3b46a9c0d 207
tlyp 2:33b3b46a9c0d 208 //******************************************************************************
tlyp 2:33b3b46a9c0d 209 int32_t MAX30208::writeRegister(Registers_e reg, uint16_t value, int bytesWritten) {
tlyp 2:33b3b46a9c0d 210
tlyp 2:33b3b46a9c0d 211 int32_t ret;
tlyp 2:33b3b46a9c0d 212
tlyp 2:33b3b46a9c0d 213 uint8_t hi = ((value >> 8) & 0xFF);
tlyp 2:33b3b46a9c0d 214 uint8_t lo = (value & 0xFF);
tlyp 2:33b3b46a9c0d 215 char val[3] = {reg, hi, lo};
tlyp 2:33b3b46a9c0d 216
tlyp 2:33b3b46a9c0d 217 ret = m_i2c.write(m_writeAddress, val, bytesWritten, false);
tlyp 2:33b3b46a9c0d 218 return (ret);
tlyp 2:33b3b46a9c0d 219 }
tlyp 2:33b3b46a9c0d 220
tlyp 2:33b3b46a9c0d 221 //******************************************************************************
tlyp 2:33b3b46a9c0d 222 int32_t MAX30208::readRegister(Registers_e reg, uint16_t &value, int bytesRead) {
tlyp 2:33b3b46a9c0d 223
tlyp 2:33b3b46a9c0d 224 int32_t ret;
tlyp 2:33b3b46a9c0d 225 char cmdata[1] = {reg};
tlyp 2:33b3b46a9c0d 226 char dataRead[2];
tlyp 2:33b3b46a9c0d 227
tlyp 2:33b3b46a9c0d 228 ret = m_i2c.write(m_readAddress,cmdata,1,true);
tlyp 2:33b3b46a9c0d 229 if (ret == 0) {
tlyp 2:33b3b46a9c0d 230 ret = m_i2c.read(m_readAddress,dataRead,bytesRead,false);
tlyp 2:33b3b46a9c0d 231 if(ret == 0 && bytesRead == 2){
tlyp 2:33b3b46a9c0d 232 value = ((dataRead[0]<<8)+ dataRead[1]);
tlyp 2:33b3b46a9c0d 233 }
tlyp 2:33b3b46a9c0d 234 else if (ret == 0 && bytesRead == 1){
tlyp 2:33b3b46a9c0d 235 value = dataRead[0];
tlyp 2:33b3b46a9c0d 236 }
tlyp 2:33b3b46a9c0d 237 }
tlyp 2:33b3b46a9c0d 238 return(ret);
tlyp 2:33b3b46a9c0d 239 }