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:
3:b0579a51fd46
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
tlyp 2:33b3b46a9c0d 33 This is code for the MAX1472 RF Transmitter EV-Kit. This program will record a
tlyp 2:33b3b46a9c0d 34 temperature fom the MAX30208 EV-Kit, encrypt the data using the user-generated
tlyp 2:33b3b46a9c0d 35 Symmetric key, apply forward error correction (FEC) encoding, and then send the
tlyp 2:33b3b46a9c0d 36 message via the MAX1472 transmitter. When the MAX1472 is not sending data, it will
tlyp 2:33b3b46a9c0d 37 go into a power saving sleep mode.
tlyp 2:33b3b46a9c0d 38
tlyp 2:33b3b46a9c0d 39 Hardware Setup and connections:
tlyp 2:33b3b46a9c0d 40
tlyp 2:33b3b46a9c0d 41 MAX32630FTHR-> MAX1472 Ev-Kit
tlyp 2:33b3b46a9c0d 42
tlyp 2:33b3b46a9c0d 43 3.3V -> VDD
tlyp 2:33b3b46a9c0d 44 GND -> VSS
tlyp 2:33b3b46a9c0d 45 P3_1 -> Data_In
tlyp 2:33b3b46a9c0d 46 P5_1 -> ENABLE
tlyp 2:33b3b46a9c0d 47
tlyp 2:33b3b46a9c0d 48 *******************************************************************************
tlyp 2:33b3b46a9c0d 49 MAX32630FTHR-> MAX30208 Ev-Kit
tlyp 2:33b3b46a9c0d 50
tlyp 2:33b3b46a9c0d 51 1.8V -> VIN
tlyp 2:33b3b46a9c0d 52 GND -> GND
tlyp 2:33b3b46a9c0d 53 P3_4 -> SDA
tlyp 2:33b3b46a9c0d 54 P3_5 -> SCL
tlyp 2:33b3b46a9c0d 55
tlyp 2:33b3b46a9c0d 56 *******************************************************************************
tlyp 2:33b3b46a9c0d 57 */
tlyp 2:33b3b46a9c0d 58
MI 0:41ed595f83f5 59 #include "mbed.h"
MI 0:41ed595f83f5 60 #include "max32630fthr.h"
MI 0:41ed595f83f5 61 #include "mxc_config.h"
MI 0:41ed595f83f5 62 #include "lp.h"
MI 0:41ed595f83f5 63 #include "gpio.h"
MI 1:8834bc22c2e7 64 #include "rtc.h"
MI 1:8834bc22c2e7 65 #include "MAX14690.h"
tlyp 2:33b3b46a9c0d 66 #include "USBSerial.h"
tlyp 2:33b3b46a9c0d 67 #include "MAX30208.h"
tlyp 2:33b3b46a9c0d 68 #include "ForwardErrCorr.h"
tlyp 2:33b3b46a9c0d 69
tlyp 4:2e3db197b7e2 70 /*User Defined Paramaters*/
tlyp 2:33b3b46a9c0d 71 #define SymmetricKey "RfIsCoOl" //Set Private Key here -- Make sure it is identical to receiver
tlyp 2:33b3b46a9c0d 72 #define SendDelay 5 //Number of seconds between sending data
tlyp 4:2e3db197b7e2 73 #define TransmissionLength 1000 //How long to continuosuly send the message (ms)
tlyp 3:b0579a51fd46 74
tlyp 2:33b3b46a9c0d 75 char DEVICETYPE = 'T'; //'T' for Temperature Sensor
tlyp 2:33b3b46a9c0d 76 char DEVICEID = 0x01; //Set the Device ID
tlyp 2:33b3b46a9c0d 77
tlyp 4:2e3db197b7e2 78 /*End of User Defined Variables */
tlyp 4:2e3db197b7e2 79
tlyp 4:2e3db197b7e2 80
tlyp 4:2e3db197b7e2 81 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
tlyp 4:2e3db197b7e2 82 I2C i2c(P3_4, P3_5); //sda,scl
tlyp 4:2e3db197b7e2 83 RawSerial uart(P3_1,P3_0);//tx,rx
tlyp 4:2e3db197b7e2 84 MAX30208 TempSensor(i2c, 0x50); //Constructor takes 7-bit slave adrs
tlyp 4:2e3db197b7e2 85
tlyp 4:2e3db197b7e2 86 char TransTable[] = {0x1F,0x18,0x06,0x01}; //Used to translate data for FEC -- Make sure it is identical to receiver
tlyp 4:2e3db197b7e2 87 Translator transTx(SymmetricKey, TransTable); //Initialize Encoder
MI 0:41ed595f83f5 88
MI 0:41ed595f83f5 89 DigitalOut rLED(LED1);
MI 0:41ed595f83f5 90 DigitalOut gLED(LED2);
MI 0:41ed595f83f5 91 DigitalOut bLED(LED3);
MI 0:41ed595f83f5 92
tlyp 4:2e3db197b7e2 93 DigitalIn sw2(SW1); //Used on start-up to stay in active mode for re-programming
tlyp 2:33b3b46a9c0d 94 DigitalOut TXEnable(P5_1); //Used to Enable Transmitter
MI 0:41ed595f83f5 95
MI 0:41ed595f83f5 96 // *****************************************************************************
tlyp 2:33b3b46a9c0d 97 /*
tlyp 2:33b3b46a9c0d 98 * @brief Configures the RTC to tick every second so it can be compared to during sleep intterupt
tlyp 2:33b3b46a9c0d 99 */
MI 1:8834bc22c2e7 100 void RTC_Setup()
MI 0:41ed595f83f5 101 {
MI 1:8834bc22c2e7 102 rtc_cfg_t RTCconfig;
tlyp 2:33b3b46a9c0d 103 RTCconfig.prescaler = RTC_PRESCALE_DIV_2_12; //Set tick frequency to 1 second
tlyp 2:33b3b46a9c0d 104 RTCconfig.prescalerMask = RTC_PRESCALE_DIV_2_12; //1 second frequency
MI 1:8834bc22c2e7 105 RTCconfig.snoozeCount = 0;
MI 1:8834bc22c2e7 106 RTCconfig.snoozeMode = RTC_SNOOZE_DISABLE;
MI 1:8834bc22c2e7 107 RTC_Init(&RTCconfig);
MI 1:8834bc22c2e7 108 RTC_Start();
MI 0:41ed595f83f5 109 }
MI 0:41ed595f83f5 110
tlyp 2:33b3b46a9c0d 111 //****************************************************************************
tlyp 2:33b3b46a9c0d 112 /**
tlyp 2:33b3b46a9c0d 113 * @brief Record and read temperature from MAX30208
tlyp 2:33b3b46a9c0d 114 * @param TempSensor - Refrence to MAX30208 temp sensor object
tlyp 2:33b3b46a9c0d 115 * @param &value[OUT]- Address to store read temperature at
tlyp 2:33b3b46a9c0d 116 * @return 0 on success, 1 on failure due to improper data record or read
tlyp 2:33b3b46a9c0d 117 */
tlyp 2:33b3b46a9c0d 118 uint16_t ReadData(MAX30208 TempSensor, uint16_t &value){
tlyp 2:33b3b46a9c0d 119 if (TempSensor.takeDataMeasurment() != 0){
tlyp 4:2e3db197b7e2 120 printf("Error Taking data Meaurment\r\n");
tlyp 2:33b3b46a9c0d 121 return(1);
tlyp 2:33b3b46a9c0d 122 }
tlyp 2:33b3b46a9c0d 123 wait_ms(50); //max temp read is 50ms
tlyp 2:33b3b46a9c0d 124 if (TempSensor.readData(value) !=0){
tlyp 4:2e3db197b7e2 125 printf("Error reading temperature Data\r\n");
tlyp 2:33b3b46a9c0d 126 return(1);
tlyp 2:33b3b46a9c0d 127 }
tlyp 2:33b3b46a9c0d 128 return(0);
tlyp 2:33b3b46a9c0d 129 }
tlyp 2:33b3b46a9c0d 130
tlyp 2:33b3b46a9c0d 131 //*****************************************************************************
tlyp 2:33b3b46a9c0d 132 /*
tlyp 2:33b3b46a9c0d 133 * @brief Begin Communication with warm up bytes and device type/id
tlyp 2:33b3b46a9c0d 134 */
tlyp 2:33b3b46a9c0d 135 void comInit(){
tlyp 2:33b3b46a9c0d 136 uart.putc(0xFF);
tlyp 2:33b3b46a9c0d 137 uart.putc(0xFF);
tlyp 2:33b3b46a9c0d 138 uart.putc(0x00);
tlyp 2:33b3b46a9c0d 139 uart.putc('b');
tlyp 2:33b3b46a9c0d 140 uart.putc(DEVICETYPE);
tlyp 2:33b3b46a9c0d 141 uart.putc(DEVICEID);
tlyp 2:33b3b46a9c0d 142 }
tlyp 2:33b3b46a9c0d 143
tlyp 2:33b3b46a9c0d 144 //*****************************************************************************
tlyp 2:33b3b46a9c0d 145 /**
tlyp 2:33b3b46a9c0d 146 * @brief Send data and end transmission
tlyp 2:33b3b46a9c0d 147 * @param EncryptedData[IN] - 8 bytes of encryted data to send via UART connection
tlyp 2:33b3b46a9c0d 148 */
tlyp 2:33b3b46a9c0d 149 void comData(char *EncryptedData){
tlyp 2:33b3b46a9c0d 150 for(int i=0;i<8;i++){
tlyp 2:33b3b46a9c0d 151 uart.putc(EncryptedData[i]); //Send all of the encrypted data
tlyp 2:33b3b46a9c0d 152 }
tlyp 2:33b3b46a9c0d 153 uart.putc('c'); //End of packet character
tlyp 2:33b3b46a9c0d 154 uart.send_break();
tlyp 2:33b3b46a9c0d 155 }
tlyp 2:33b3b46a9c0d 156
tlyp 2:33b3b46a9c0d 157 //*****************************************************************************
tlyp 2:33b3b46a9c0d 158
MI 0:41ed595f83f5 159 int main(void)
MI 0:41ed595f83f5 160 {
tlyp 2:33b3b46a9c0d 161 //initialize PMIC
MI 1:8834bc22c2e7 162 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
tlyp 2:33b3b46a9c0d 163 uart.baud(9600); //Set baud rate for 9600
MI 1:8834bc22c2e7 164
MI 0:41ed595f83f5 165 //check if starting at main because of LP0 wake-up
MI 1:8834bc22c2e7 166 if(LP_IsLP0WakeUp()) {
tlyp 2:33b3b46a9c0d 167 //empty
MI 1:8834bc22c2e7 168 }
tlyp 2:33b3b46a9c0d 169
MI 0:41ed595f83f5 170 else {
MI 0:41ed595f83f5 171 //We did not wake up from sleep and this is first power-on
MI 1:8834bc22c2e7 172 //Only configure RTC the first time around
MI 1:8834bc22c2e7 173 RTC_Setup();
MI 0:41ed595f83f5 174 }
tlyp 2:33b3b46a9c0d 175
tlyp 2:33b3b46a9c0d 176 //Set LEDs on to show device is awake
MI 0:41ed595f83f5 177 gLED = LED_ON;
MI 1:8834bc22c2e7 178 rLED = LED_ON;
MI 1:8834bc22c2e7 179 bLED = LED_ON;
tlyp 2:33b3b46a9c0d 180
tlyp 2:33b3b46a9c0d 181 //Main loop
MI 0:41ed595f83f5 182 while(1) {
tlyp 3:b0579a51fd46 183
MI 1:8834bc22c2e7 184 //hold down switch 1 to prevent the microcontroller from going into LP0
tlyp 4:2e3db197b7e2 185 while(sw2 == 0);
MI 1:8834bc22c2e7 186
tlyp 2:33b3b46a9c0d 187 uint16_t tempData;
tlyp 2:33b3b46a9c0d 188 if(ReadData(TempSensor,tempData) !=0){
tlyp 2:33b3b46a9c0d 189 printf("Error reading data!\r\n");
tlyp 2:33b3b46a9c0d 190 }
tlyp 2:33b3b46a9c0d 191
tlyp 2:33b3b46a9c0d 192 //Encrypt Temperature Data
tlyp 2:33b3b46a9c0d 193 char EncryptedData[8];
tlyp 2:33b3b46a9c0d 194 transTx.Encrypt(tempData,EncryptedData);
tlyp 2:33b3b46a9c0d 195
tlyp 2:33b3b46a9c0d 196 TXEnable = 1; //Turn on Transmitter
tlyp 4:2e3db197b7e2 197 wait_us(450); //Minimum Wake-up time for transmitter per data sheet -- Do not lower
MI 1:8834bc22c2e7 198
tlyp 2:33b3b46a9c0d 199 //Start a timer for sending data
tlyp 2:33b3b46a9c0d 200 Timer timer;
tlyp 2:33b3b46a9c0d 201 timer.start();
tlyp 2:33b3b46a9c0d 202
tlyp 2:33b3b46a9c0d 203 //Send the data for 1 sec
tlyp 4:2e3db197b7e2 204 while(timer.read_ms() < TransmissionLength) {
tlyp 2:33b3b46a9c0d 205
tlyp 2:33b3b46a9c0d 206 //Send Data continuously
tlyp 2:33b3b46a9c0d 207 comInit();
tlyp 2:33b3b46a9c0d 208 comData(EncryptedData);
tlyp 2:33b3b46a9c0d 209 }//while
tlyp 2:33b3b46a9c0d 210
tlyp 2:33b3b46a9c0d 211 TXEnable = 0; //Turn off Transmitter
tlyp 2:33b3b46a9c0d 212 timer.stop(); //Stop send timer
tlyp 2:33b3b46a9c0d 213
MI 1:8834bc22c2e7 214 //Clear existing wake-up config
MI 1:8834bc22c2e7 215 LP_ClearWakeUpConfig();
MI 0:41ed595f83f5 216
MI 1:8834bc22c2e7 217 //Clear any event flags
MI 1:8834bc22c2e7 218 LP_ClearWakeUpFlags();
MI 0:41ed595f83f5 219
MI 1:8834bc22c2e7 220 //configure wake-up on RTC compare 0
tlyp 2:33b3b46a9c0d 221 //LP_ConfigRTCWakeUp(enable compare0, enable compare1, set prescale, set rollover)
MI 1:8834bc22c2e7 222 LP_ConfigRTCWakeUp(1, 0, 0, 0);
MI 1:8834bc22c2e7 223
tlyp 2:33b3b46a9c0d 224 //disable unused PMIC rails to minimize power consumption
tlyp 2:33b3b46a9c0d 225 pegasus.max14690.ldo2SetMode(MAX14690::LDO_DISABLED);
tlyp 2:33b3b46a9c0d 226 pegasus.max14690.ldo3SetMode(MAX14690::LDO_DISABLED);
MI 1:8834bc22c2e7 227
tlyp 2:33b3b46a9c0d 228 //Turn off LEDs to show low power mode
tlyp 2:33b3b46a9c0d 229 gLED = LED_OFF;
tlyp 2:33b3b46a9c0d 230 rLED = LED_OFF;
tlyp 2:33b3b46a9c0d 231 bLED = LED_OFF;
tlyp 2:33b3b46a9c0d 232
tlyp 2:33b3b46a9c0d 233 //Reset the RTC back to 0 ticks
tlyp 2:33b3b46a9c0d 234 RTC_SetCount(0);
tlyp 2:33b3b46a9c0d 235
tlyp 2:33b3b46a9c0d 236 //set RTC to generate an interrupt every SendDelay seconds (User defined value at top of program)
tlyp 2:33b3b46a9c0d 237 RTC_SetCompare(0,SendDelay); //(Compare index, Compare Value in ticks)
MI 1:8834bc22c2e7 238
MI 1:8834bc22c2e7 239 //clear comparison flag in the RTC registers
MI 1:8834bc22c2e7 240 RTC_ClearFlags(MXC_F_RTC_FLAGS_COMP0);
MI 0:41ed595f83f5 241
tlyp 2:33b3b46a9c0d 242 //Enter Deep Sleep Mode
MI 1:8834bc22c2e7 243 LP_EnterLP0();
MI 1:8834bc22c2e7 244
MI 1:8834bc22c2e7 245 //firmware will reset with no prior knowledge on wake-up
MI 0:41ed595f83f5 246 }
MI 0:41ed595f83f5 247 }