MAX1472 RF Transmitter demo code
Dependencies: max32630fthr USBDevice
Revision 10:d46390b7aa64, committed 2020-09-04
- Comitter:
- tlyp
- Date:
- Fri Sep 04 18:04:36 2020 +0000
- Parent:
- 9:02c5adb483c8
- Commit message:
- initial commit
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ForwardErrCorr.cpp Fri Sep 04 18:04:36 2020 +0000 @@ -0,0 +1,145 @@ +/******************************************************************************* +* Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +******************************************************************************* +*/ + +#include "ForwardErrCorr.h" + +Translator::Translator(char *SymmetricKey, char *TransTable): +m_SymmetricKey(SymmetricKey),m_TransTable(TransTable) +{ +} + +//****************************************************************************** +Translator::~Translator(void){ +} + +//****************************************************************************** +uint32_t Translator::Decrypt(char *tes, uint16_t *Output){ + int8_t ValOut,ValIn; + int key = 0; + Output[0] = 0; + printf("Recieved Data -> Decrypted Data:\r\n"); + for(int i = 2;i<10;i++){ + ValIn = tes[i]; + ValIn = ValIn ^ m_SymmetricKey[key]; //Unencrypt data + printf("%c -> %i\r\n",ValIn,tes[i]); + key++; + ValOut = 5; + for (int j=0;j<4;j++){ + if (ValIn == m_TransTable[j]){ + ValOut = j; + } + } + if (ValOut == 5){ + ValOut = ChkHam(ValIn); + } + if (ValOut == 4){ + printf("Transmission error -- Hamming Distance Collision\r\n"); + return (1); + } + Output[0] = (Output[0] << 2) + ValOut; + printf("Output: %d\r\n",Output[0]); + } + return(0); +} + +//****************************************************************************** +int Translator::ChkHam(char ChkVal){ + char trial = ChkVal & 0x1F; + bool dupe = 0; + int index, temp; + int min = 5; + for (int k = 0; k<4;k++){ + temp = HamDist(trial,m_TransTable[k]); + if (temp == 1){ + return (k); + } + else if (temp < min){ + min = temp; + index = k; + dupe = 0; + } + else if (temp == min){ + dupe = 1; + } + } + if (dupe == 1){ + return(4); + } + else{ + return (index); + } +} + +//****************************************************************************** +int Translator::HamDist(char ChkVal, char TableVal){ + int count=0; + char tes1,tes2; + for (int j =0;j<5;j++){ + tes1 = ChkVal >> j; + tes2 = TableVal >> j; + char temp = tes1 ^ tes2; + count += temp&1; + } + return (count); +} + +//****************************************************************************** +uint32_t Translator::Encrypt(uint16_t tempData,char *EncryptedData){ + char data; + int z=0; + printf("FEC Encoded Data:\r\n"); + for (int i=14;i>=0;i-=2){ + data = ((tempData >> i)&0x03); + data = m_TransTable[data]; + printf("%d ",data); + data = (data ^ m_SymmetricKey[z]); + EncryptedData[z]=data; + z++; + } + printf("\r\n"); + return(0); +} + +//****************************************************************************** +uint32_t Translator::Encrypt(char tempData, char *EncryptedData){ + char data; + int z =0; + for (int i=6;i>=0;i-=2){ + data = ((tempData >> i)&0x03); + data = m_TransTable[data]; + data = (data ^ m_SymmetricKey[z]); + EncryptedData[z] = data; + z++; + } + return(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ForwardErrCorr.h Fri Sep 04 18:04:36 2020 +0000 @@ -0,0 +1,122 @@ +/******************************************************************************* +* Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +******************************************************************************* +*/ + +/** + * @brief Library for the MAX30208\n + * + * @code + * #include "mbed.h" + * #include "max32630fthr.h" + * #include "ForwardErrCorr.h" + * + * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); + * + * #define SymmetricKey "PaSsWoRd" + * char TransTable[] = {0x1F,0x18,0x06,0x01}; + * + * //Create translator instance + * Translator transTx(SymmetricKey, TransTable); //Constructor takes 7-bit slave adrs + * + * int main(void) + * { + * //use Encoder + * } + * @endcode + */ + +#ifndef __FORWARDERRCORR_H_ +#define __FORWARDERRCORR_H_ + +#include "mbed.h" + +class Translator{ + +public: + + /** + * @brief Constructor using reference to Symmetric key for encryption and FEC translation table + * @param SymmetricKey - Symmetric Key used by tranmsitter and reciever to encrypt/decrypt transmitted messages + * @param TransTable - Translation table used for Forward Error Correction code + */ + Translator(char *SymmetricKey, char *TransTable); + + /** + * @brief De-constructor + */ + ~Translator(void); + + /** + * @brief Takes 2 byte data packet, converts to FEC 8 byte packet, and encrypts each byte + * @param tempData[IN] - 2 byte data that needs to be prepared for transmission + * @param EncryptedData[OUT] - Pointer to array where encrypted data will be stored, ready to send + * @return 0 on success, 1 on failure + */ + uint32_t Encrypt(uint16_t tempData,char *EncryptedData); + + /** + * @brief Takes 1 byte data packet, converts to FEC 8 byte packet, and encrypts each byte + * @param tempData[IN] - 2 byte data that needs to be prepared for transmission + * @param EncryptedData[OUT] - Pointer to array where encrypted data will be stroed, ready to send + * @return 0 on success, 1 on failure + */ + uint32_t Encrypt(char tempData, char*EncryptedData); + + /** + * @brief Calculates the hamming disatnce between 2 bytes + * @param ChkVal[IN] - Byte to use in hamming distance check + * @param TableVal[IN] - Byte to use in hamming distance check + * @return Hamming distance between the two provided bytes (range of 0-8) + */ + int HamDist(char ChkVal, char TableVal); + + /** + * @brief Converts 1 byte of FEC code back to original 2 bit data + * @param ChkVal - 1 byte of encoded data that needs to be decoded + * @return 0,1,2,3 to indicate correctly decoded table index, 4 on transmission error + */ + int ChkHam(char ChkVal); + + /** + * @brief Function that takes encrypted FEC data and converts it back to 2 byte data + * @param[IN] EncryptedData - Array of the encrypted data + * @param[OUT] Output - 16 bit data returned after decryption + * @return 0 on sucess, 1 on failure + */ + uint32_t Decrypt(char *EncryptedData, uint16_t *Output); + +private: + + char *m_TransTable, *m_SymmetricKey; +}; + +#endif /* __ForwardErrCorr_H_*/ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MAX30208.cpp Fri Sep 04 18:04:36 2020 +0000 @@ -0,0 +1,235 @@ +/******************************************************************************* +* Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +******************************************************************************* +*/ + + +#include "MAX30208.h" + + +//****************************************************************************** +MAX30208::MAX30208(I2C &i2c, uint8_t slaveAddress): +m_i2c(i2c), m_writeAddress(slaveAddress << 1), +m_readAddress((slaveAddress << 1) | 1) +{ +} + + +//****************************************************************************** +MAX30208::~MAX30208(void) { + //empty block +} + +//****************************************************************************** + int32_t MAX30208::writeInterruptRegister(Configuration_InterruptEnable config) { + return(writeRegister(MAX30208::Interrupt_Enable,(config.all << 8),2)); + } + +//****************************************************************************** + int32_t MAX30208::readInterruptRegister(Configuration_InterruptEnable &config) { + uint16_t data; + int32_t status; + status = readRegister(MAX30208::Interrupt_Enable, data, 1); + if(status == 0) { + config.all = data; + } + return(status); + } + +//****************************************************************************** + int32_t MAX30208::readStatus(uint16_t &value) { + return(readRegister(MAX30208::Status,value, 1)); + } + +//****************************************************************************** + int32_t MAX30208::readWritePointer(uint16_t &value) { + return (readRegister(MAX30208::FIFO_Write_Pointer,value, 1)); + } + +//****************************************************************************** + int32_t MAX30208::readReadPointer(uint16_t &value) { + return (readRegister(MAX30208::FIFO_Read_Pointer,value,1)); + } + +//****************************************************************************** + int32_t MAX30208::writeReadPointer(uint8_t config) { + return(writeRegister(MAX30208::FIFO_Read_Pointer, (config << 8),2)); + } + +//****************************************************************************** + int32_t MAX30208::readOverflow(uint16_t &value) { + return(readRegister(MAX30208::FIFO_Overflow_Counter,value, 1)); + } + +//****************************************************************************** + int32_t MAX30208::readDataCounter(uint16_t &value) { + return(readRegister(MAX30208::FIFO_Data_Counter,value, 1)); + } + +//****************************************************************************** + int32_t MAX30208::readData(uint16_t &value) { + return(readRegister(MAX30208::FIFO_Data,value, 2)); + } + +//****************************************************************************** + int32_t MAX30208::takeDataMeasurment() { + return(writeRegister(MAX30208::Temp_Sensor_Setup,0xFF00,2)); + } + +//****************************************************************************** + int32_t MAX30208::readFIFOConfig1(uint16_t &value) { + return (readRegister(MAX30208::FIFO_Config1,value, 1)); + } + +//****************************************************************************** + int32_t MAX30208::writeFIFOConfig1(uint8_t config) { + return(writeRegister(MAX30208::FIFO_Config1,(config << 8),2)); + } + +//****************************************************************************** + int32_t MAX30208::readFIFOConfig2(Configuration_FIFOConfig2 &config) { + uint16_t data; + int32_t status; + status = readRegister(MAX30208::FIFO_Config2, data, 1); + if(status == 0){ + config.all = data; + } + return(status); + } + +//****************************************************************************** + int32_t MAX30208::writeFIFOConfig2(Configuration_FIFOConfig2 config) { + return(writeRegister(MAX30208::FIFO_Config2,(config.all << 8),2)); + } + +//****************************************************************************** + int32_t MAX30208::resetDevice() { + return(writeRegister(MAX30208::System_Control,(0x01 << 8),2)); + } + +//****************************************************************************** + int32_t MAX30208::readAlarmHigh(uint16_t &temp) { + return readRegister(MAX30208::Alarm_High_MSB,temp, 2); + } + +//****************************************************************************** + int32_t MAX30208::writeAlarmHigh(uint16_t temp) { + return(writeRegister(MAX30208::Alarm_High_MSB, temp, 3)); + } + +//****************************************************************************** + int32_t MAX30208::readAlarmLow(uint16_t &value) { + return (readRegister(MAX30208::Alarm_Low_MSB,value, 2)); + } + +//****************************************************************************** + int32_t MAX30208::writeAlarmLow(uint16_t temp) { + return(writeRegister(MAX30208::Alarm_Low_MSB,temp,3)); + } + +//****************************************************************************** + int32_t MAX30208::readGPIOSetup(Configuration_GPIOSetup &config) { + uint16_t data; + int32_t status; + status = readRegister(MAX30208::GPIO_Setup, data, 1); + if(status == 0) { + config.all = data; + } + return(status); + } + +//****************************************************************************** + int32_t MAX30208::writeGPIOSetup(Configuration_GPIOSetup config) { + return(writeRegister(MAX30208::GPIO_Setup,(config.all << 8),2)); + } + +//****************************************************************************** + int32_t MAX30208::readGPIOControl(Configuration_GPIOControl &config) { + uint16_t data; + int32_t status; + status = readRegister(MAX30208::GPIO_Control, data, 1); + if(status == 0) { + config.all = data; + } + return(status); + } + +//****************************************************************************** + int32_t MAX30208::writeGPIOControl(Configuration_GPIOControl config) { + return(writeRegister(MAX30208::GPIO_Control,(config.all << 8),2)); + } + +//****************************************************************************** + float MAX30208::toCelsius(uint16_t rawTemp) { + float celsius; + celsius = 0.005*rawTemp; + return celsius; + } + +//****************************************************************************** + float MAX30208::toFahrenheit(float temperatureC) { + float temperatureF; + temperatureF = (temperatureC * 1.8F) + 32.0f; + return temperatureF; + } + +//****************************************************************************** +int32_t MAX30208::writeRegister(Registers_e reg, uint16_t value, int bytesWritten) { + + int32_t ret; + + uint8_t hi = ((value >> 8) & 0xFF); + uint8_t lo = (value & 0xFF); + char val[3] = {reg, hi, lo}; + + ret = m_i2c.write(m_writeAddress, val, bytesWritten, false); + return (ret); +} + +//****************************************************************************** +int32_t MAX30208::readRegister(Registers_e reg, uint16_t &value, int bytesRead) { + + int32_t ret; + char cmdata[1] = {reg}; + char dataRead[2]; + + ret = m_i2c.write(m_readAddress,cmdata,1,true); + if (ret == 0) { + ret = m_i2c.read(m_readAddress,dataRead,bytesRead,false); + if(ret == 0 && bytesRead == 2){ + value = ((dataRead[0]<<8)+ dataRead[1]); + } + else if (ret == 0 && bytesRead == 1){ + value = dataRead[0]; + } + } + return(ret); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MAX30208.h Fri Sep 04 18:04:36 2020 +0000 @@ -0,0 +1,335 @@ +/******************************************************************************* +* Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +******************************************************************************* +*/ +#ifndef __MAX30208_H_ +#define __MAX30208_H_ + +#include "mbed.h" + +/** + * @brief Library for the MAX30208\n + * + * @code + * #include "mbed.h" + * #include "max32630fthr.h" + * #include "MAX30208.h" + * + * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); + * + * //Get I2C instance + * I2C i2cBus(I2C1_SDA, I2C1_SCL); + * + * //Get temp sensor instance + * MAX30208 bodyTempSensor(i2cBus, 0x50); //Constructor takes 7-bit slave adrs + * + * int main(void) + * { + * //use sensor + * } + * @endcode + */ + +class MAX30208 +{ + +public: + /// MAX30208 Register Addresses + enum Registers_e { + Status = 0x00, + Interrupt_Enable = 0x01, + FIFO_Write_Pointer = 0x04, + FIFO_Read_Pointer = 0x05, + FIFO_Overflow_Counter = 0x06, + FIFO_Data_Counter = 0x07, + FIFO_Data = 0x08, + FIFO_Config1 = 0x09, + FIFO_Config2 = 0x0A, + System_Control = 0x0C, + Alarm_High_MSB = 0x10, + Alarm_Low_MSB = 0x12, + Temp_Sensor_Setup = 0x14, + GPIO_Setup = 0x20, + GPIO_Control = 0x21 + }; + + union Configuration_InterruptEnable{ + uint8_t all; + struct BitField_s{ + uint8_t TEMP_RDY_EN : 1; + uint8_t TEMP_HI_EN : 1; + uint8_t TEMP_LO_EN : 1; + uint8_t : 4; //unused bits + uint8_t A_FULL_EN : 1; + }config; + }; + + union Configuration_FIFOConfig2{ + uint8_t all; + struct BitField_s{ + uint8_t : 1; //unused bit + uint8_t FIFO_RO : 1; + uint8_t A_FULL_TYPE : 1; + uint8_t FIFO_STAT_CLR : 1; + uint8_t FLUSH_FIFO : 1; + uint8_t : 0; //unused bits + }config; + }; + + union Configuration_GPIOSetup{ + uint8_t all; + struct BitField_s{ + uint8_t GPIO0_MODE : 2; + uint8_t : 4; //unused bits + uint8_t GPIO1_MODE : 2; + }config; + }; + + union Configuration_GPIOControl{ + uint8_t all; + struct BitField_s{ + uint8_t GPIO0_LL : 1; + uint8_t : 2; //unused bits + uint8_t GPIO1_LL : 1; + uint8_t : 0; //unused bits + }config; + }; + + /** + * @brief Constructor using reference to I2C object + * @param i2c - Reference to I2C object + * @param slaveAddress - 7-bit I2C address + */ + MAX30208(I2C &i2c, uint8_t slaveAddress); + + /** @brief Destructor */ + ~MAX30208(void); + + /** + * @brief Write Interrupt Register + * @param config - Reference to Configuration type, config.all is written upon succesful register write + * @return 0 on success, non-zero on failure + */ + int32_t writeInterruptRegister(Configuration_InterruptEnable config); + + /** + * @brief Read Interrupt Register Configuration + * @param config - Reference to Configuration type, config.all is updated upon succesful register read + * @return 0 on success, non-zero on failure + */ + int32_t readInterruptRegister(Configuration_InterruptEnable &config); + + /** + * @brief Read Status Register + * @param[out] value - Status Register Value on succesful read + * @return 0 on success, non-zero on failure + */ + int32_t readStatus(uint16_t &value); + + /** + * @brief Read FIFO Write Pointer Value + * @param[out] value - FIFO Write Pointer value on succesful read + * @return 0 on success, non-zero on failure + */ + int32_t readWritePointer(uint16_t &value); + + /** + * @brief Read FIFO Read Pointer Value + * @param[out] value - FIFO Read Pointer value on succesful read + * @return 0 on success, non-zero on failure + */ + int32_t readReadPointer(uint16_t &value); + + /** + * @brief Write FIFO Read Pointer Value + * @param config - New FIFO Read Pointer value on succesful write + * @return 0 on success, non-zero on failure + */ + int32_t writeReadPointer(uint8_t config); + + /** + * @brief Read FIFO Overflow Register + * @param[out] value - Overflow Counter value on succesful read + * @return 0 on success, non-zero on failure + */ + int32_t readOverflow(uint16_t &value); + + /** + * @brief Read Data Counter Register + * @param[out] value - Data Count register value on succesful read + * @return 0 on success, non-zero on failure + */ + int32_t readDataCounter(uint16_t &value); + + /** + * @brief Read FIFO Data at FIFO Read Pointer + * @param[out] value - Temperature value from FIFO data register on succesful read + * @return 0 on success, non-zero on failure + */ + int32_t readData(uint16_t &value); + + /** + * @brief Take a new temperature reading + * @return 0 on success, non-zero on failure + */ + int32_t takeDataMeasurment(); + + /** + * @brief Read FIFO Config1 Register + * @param[out] value - FIFO Config1 value on succesful read + * @return 0 on success, non-zero on failure + */ + int32_t readFIFOConfig1(uint16_t &value); + + /** + * @brief Write FIFO Config1 register + * @param config - FIFO Config1 register data to write + * @return 0 on success, non-zero on failure + */ + int32_t writeFIFOConfig1(uint8_t config); + + /** + * @brief Read FIFO Config2 register + * @param[out] config - Reference to Configuration type, config.all is updated upon succesful register read + * @return 0 on success, non-zero on failure + */ + int32_t readFIFOConfig2(Configuration_FIFOConfig2 &config); + + /** + * @brief Read FIFO Config2 register + * @param config - Reference to Configuration type, config.all is written upon succesful register write + * @return 0 on success, non-zero on failure + */ + int32_t writeFIFOConfig2(Configuration_FIFOConfig2 config); + + /** + * @brief Reset Device to factory default + * @return 0 on success, non-zero on failure + */ + int32_t resetDevice(); //set bit 0 in system register to 1 to factory reset + + /** + * @brief Read High Temperature Alarm Value + * @param[out] temp - High Temperature Alarm Value + * @return 0 on success, non-zero on failure + */ + int32_t readAlarmHigh(uint16_t &temp); + + /** + * @brief Write High Temperature Alarm Value + * @param temp - 16-bit High Temperature Value to Write + * @return 0 on success, non-zero on failure + */ + int32_t writeAlarmHigh(uint16_t temp); + + /** + * @brief Read Low Temperature Alarm Value + * @param[out] temp - Low Temperature Alarm Value + * @return 0 on success, non-zero on failure + */ + int32_t readAlarmLow(uint16_t &value); + + /** + * @brief Write Low Temperature Alarm Value + * @param temp - 16-bit Low Temperature Value to Write + * @return 0 on success, non-zero on failure + */ + int32_t writeAlarmLow(uint16_t temp); + + /** + * @brief Read GPIO Setup register + * @param config - Reference to Configuration type, config.all is updated upon succesful register read + * @return 0 on success, non-zero on failure + */ + int32_t readGPIOSetup(Configuration_GPIOSetup &config); + + /** + * @brief Write GPIO Setup register + * @param config - Reference to Configuration type, config.all is written to register upon succesful register write + * @return 0 on success, non-zero on failure + */ + int32_t writeGPIOSetup(Configuration_GPIOSetup config); + + /** + * @brief Read GPIO Control register + * @param config - Reference to Configuration type, config.all is updated upon succesful register read + * @return 0 on success, non-zero on failure + */ + int32_t readGPIOControl(Configuration_GPIOControl &config); + + /** + * @brief Write GPIO Control register + * @param config - Reference to Configuration type, config.all is written to register upon succesful register write + * @return 0 on success, non-zero on failure + */ + int32_t writeGPIOControl(Configuration_GPIOControl config); + + /** + * @brief Convert Raw Sensor Data to degrees Celisus + * @param rawTemp - 16 bit raw temperature data + * @return Returns the converted Celsius Temperature + */ + float toCelsius(uint16_t rawTemp); + + /** + * @brief Convert Celsius Temperature to Fahrenheit + * @param temperatureC - Temperature in degrees Celsius that will be converted + * @return Returns the converted Fahrenheit temperature + */ + float toFahrenheit(float temperatureC); + +protected: + + /** + * @brief Write register of device at slave address + * @param reg - char array that contains address of register and write value + * @param value - Data written to register on sucessful write + * @param bytesWritten - Number of bytes to write + * @return 0 on success, non-zero on failure + */ + int32_t writeRegister(Registers_e reg, uint16_t value, int bytesWritten); + /** + * @brief Read register of device at slave address + * @param reg - Register address + * @param[out] value - Read data on successful read + * @param bytesRead - Number of bytes to read + * @return 0 on success, non-zero on failure + */ + int32_t readRegister(Registers_e reg, uint16_t &value, int bytesRead); + +private: + /// I2C object + I2C & m_i2c; + /// Device slave addresses + uint8_t m_writeAddress, m_readAddress; +}; + +#endif /* __MAX30208_H_ */
--- a/main.cpp Fri Sep 27 21:02:41 2019 +0000 +++ b/main.cpp Fri Sep 04 18:04:36 2020 +0000 @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved. +* Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -29,45 +29,165 @@ * property whatsoever. Maxim Integrated Products, Inc. retains all * ownership rights. ******************************************************************************* + +This is code for the MAX1472 RF Transmitter EV-Kit. This program will record a +temperature fom the MAX30208 EV-Kit, encrypt the data using the user-generated +Symmetric key, apply forward error correction (FEC) encoding, and then send the +message via the MAX1472 transmitter. + + Hardware Setup and connections: + + MAX32630FTHR-> MAX1472 Ev-Kit + + 3.3V -> VDD + GND -> VSS + P3_1 -> Data_In + P5_2 -> ENABLE + +******************************************************************************* + MAX32630FTHR-> MAX30208 Ev-Kit + + 1.8V -> VIN + GND -> GND + P3_4 -> SDA + P3_5 -> SCL + +******************************************************************************* */ + #include "mbed.h" #include "max32630fthr.h" #include "USBSerial.h" +#include "MAX30208.h" +#include "ForwardErrCorr.h" MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); -// Hardware serial port over DAPLink -Serial daplink(USBTX, USBRX); // Use USB debug probe for serial link -Serial uart(P2_1, P2_0); +//UART Port for Sending data +RawSerial uart(P3_1,P3_0);//tx,rx + + +I2C i2c(P3_4, P3_5); //sda,scl +MAX30208 TempSensor(i2c, 0x50); //Temperature Sensor Object for reading temperature data + +#define SymmetricKey "RfIsCoOl" //Set Symmetric Key here -- Make sure it is identical to receiver +char TransTable[] = {0x1F,0x18,0x06,0x01}; //Used to translate data for FEC -- Make sure it is identical to receiver +Translator transTx(SymmetricKey, TransTable); //Initialize Encoder + +DigitalOut rLED(LED1); +DigitalOut gLED(LED2); +DigitalOut bLED(LED3); + +DigitalIn sw1(SW1); //Trigger for sending data +DigitalOut Enable(P5_2); //Enable Transmitter + +char DEVICETYPE = 'T'; //Set Device Type +char DEVICEID = 0x01; //Set the Device ID + +//****************************************************************************** -// Virtual serial port over USB -USBSerial microUSB; -DigitalOut rLED(LED1); -DigitalOut gLED(LED2); -DigitalOut bLED(LED3); +/** +* @brief Record and read temperature from MAX30208 +* @param TempSensor - Refrence to MAX30208 temp sensor object +* @param &value[OUT]- Address to store read temperature at +* @return 0 on success, 1 on failure due to improper data record or read +*/ +int ReadData(MAX30208 TempSensor, uint16_t &value){ + if (TempSensor.takeDataMeasurment() != 0){ + printf("Error Taking data Meaurment\r\n"); + return(1); + } + wait_ms(50); //max temp record time is 50ms + if (TempSensor.readData(value) !=0){ + printf("Error reading temperature Data\r\n"); + return(1); + } + return(0); +} + +//****************************************************************************** -// main() runs in its own thread in the OS -// (note the calls to Thread::wait below for delays) +/* +* @brief Begin Communication with warm up bytes and device type/id +*/ +void comInit(Translator trans){ + uart.putc(0xFF); //Initializer bytes to "warm-up" the Peak Detector cicuitry of MAX1473 Receiver + uart.putc(0xFF); + uart.putc(0x00); + uart.putc('b'); //Packet start character + uart.putc(DEVICETYPE); //Send Device Type + uart.putc(DEVICEID); //Send Device ID +} + +//****************************************************************************** + +/** +* @brief Send data and end transmission +* @param EncryptedData[IN] - 8 bytes of encryted data to send via UART connection +*/ +void comData(char *EncryptedData){ + for(int i=0;i<8;i++){ + uart.putc(EncryptedData[i]); //Send all of the encrypted data + } + uart.putc('c'); //End of packet character + uart.send_break(); +} + +//****************************************************************************** + int main() { - int c; - - daplink.printf("daplink serial port\r\n"); - microUSB.printf("micro USB serial port\r\n"); + wait(1); + uart.baud(9600); + printf("Starting Transmitter Program\r\n\r\n"); + rLED = LED_ON; gLED = LED_ON; bLED = LED_OFF; rLED = LED_OFF; + + //Start MAX30208 temperature sensor in factor default + TempSensor.resetDevice(); + + //Turn off Transmitter + Enable = 0; while(1) { -// c = microUSB.getc(); -// microUSB.putc(c); -// daplink.putc(c); - daplink.printf("daplink serial port\r\n"); - microUSB.printf("micro USB serial port\r\n"); - bLED = !bLED; - wait(2); - } -} + + //Record a temperature and send the encrypted data each time the on-board button is pressed + if(sw1==0){ + + //Enable Transmitter + Enable = 1; + + //Read a new temperature + uint16_t tempData; + if(ReadData(TempSensor,tempData) !=0){ + printf("Error reading data!\r\n"); + } + + //Encrypt Temperature Data + char EncryptedData[8]; + printf("Original Data: %i\r\n", tempData); + transTx.Encrypt(tempData,EncryptedData); + printf("Encrypted Data:\r\n"); + for(int i=0;i<8;i++){ + printf("%c ",EncryptedData[i]); + } + printf("\r\n\r\n"); + + //Initialize Communication + comInit(transTx); + + //Send Encrypted Data + comData(EncryptedData); + + //Turn off Transmitter + Enable = 0; + wait_ms(500); //button debounce + }//if + }//while +}//main +