MAX1472 RF Transmitter demo code
Dependencies: max32630fthr USBDevice
main.cpp@10:d46390b7aa64, 2020-09-04 (annotated)
- Committer:
- tlyp
- Date:
- Fri Sep 04 18:04:36 2020 +0000
- Revision:
- 10:d46390b7aa64
- Parent:
- 9:02c5adb483c8
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phonemacro | 9:02c5adb483c8 | 1 | /******************************************************************************* |
tlyp | 10:d46390b7aa64 | 2 | * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. |
phonemacro | 9:02c5adb483c8 | 3 | * |
phonemacro | 9:02c5adb483c8 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
phonemacro | 9:02c5adb483c8 | 5 | * copy of this software and associated documentation files (the "Software"), |
phonemacro | 9:02c5adb483c8 | 6 | * to deal in the Software without restriction, including without limitation |
phonemacro | 9:02c5adb483c8 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
phonemacro | 9:02c5adb483c8 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
phonemacro | 9:02c5adb483c8 | 9 | * Software is furnished to do so, subject to the following conditions: |
phonemacro | 9:02c5adb483c8 | 10 | * |
phonemacro | 9:02c5adb483c8 | 11 | * The above copyright notice and this permission notice shall be included |
phonemacro | 9:02c5adb483c8 | 12 | * in all copies or substantial portions of the Software. |
phonemacro | 9:02c5adb483c8 | 13 | * |
phonemacro | 9:02c5adb483c8 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
phonemacro | 9:02c5adb483c8 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
phonemacro | 9:02c5adb483c8 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
phonemacro | 9:02c5adb483c8 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
phonemacro | 9:02c5adb483c8 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
phonemacro | 9:02c5adb483c8 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
phonemacro | 9:02c5adb483c8 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
phonemacro | 9:02c5adb483c8 | 21 | * |
phonemacro | 9:02c5adb483c8 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
phonemacro | 9:02c5adb483c8 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
phonemacro | 9:02c5adb483c8 | 24 | * Products, Inc. Branding Policy. |
phonemacro | 9:02c5adb483c8 | 25 | * |
phonemacro | 9:02c5adb483c8 | 26 | * The mere transfer of this software does not imply any licenses |
phonemacro | 9:02c5adb483c8 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
phonemacro | 9:02c5adb483c8 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
phonemacro | 9:02c5adb483c8 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
phonemacro | 9:02c5adb483c8 | 30 | * ownership rights. |
phonemacro | 9:02c5adb483c8 | 31 | ******************************************************************************* |
tlyp | 10:d46390b7aa64 | 32 | |
tlyp | 10:d46390b7aa64 | 33 | This is code for the MAX1472 RF Transmitter EV-Kit. This program will record a |
tlyp | 10:d46390b7aa64 | 34 | temperature fom the MAX30208 EV-Kit, encrypt the data using the user-generated |
tlyp | 10:d46390b7aa64 | 35 | Symmetric key, apply forward error correction (FEC) encoding, and then send the |
tlyp | 10:d46390b7aa64 | 36 | message via the MAX1472 transmitter. |
tlyp | 10:d46390b7aa64 | 37 | |
tlyp | 10:d46390b7aa64 | 38 | Hardware Setup and connections: |
tlyp | 10:d46390b7aa64 | 39 | |
tlyp | 10:d46390b7aa64 | 40 | MAX32630FTHR-> MAX1472 Ev-Kit |
tlyp | 10:d46390b7aa64 | 41 | |
tlyp | 10:d46390b7aa64 | 42 | 3.3V -> VDD |
tlyp | 10:d46390b7aa64 | 43 | GND -> VSS |
tlyp | 10:d46390b7aa64 | 44 | P3_1 -> Data_In |
tlyp | 10:d46390b7aa64 | 45 | P5_2 -> ENABLE |
tlyp | 10:d46390b7aa64 | 46 | |
tlyp | 10:d46390b7aa64 | 47 | ******************************************************************************* |
tlyp | 10:d46390b7aa64 | 48 | MAX32630FTHR-> MAX30208 Ev-Kit |
tlyp | 10:d46390b7aa64 | 49 | |
tlyp | 10:d46390b7aa64 | 50 | 1.8V -> VIN |
tlyp | 10:d46390b7aa64 | 51 | GND -> GND |
tlyp | 10:d46390b7aa64 | 52 | P3_4 -> SDA |
tlyp | 10:d46390b7aa64 | 53 | P3_5 -> SCL |
tlyp | 10:d46390b7aa64 | 54 | |
tlyp | 10:d46390b7aa64 | 55 | ******************************************************************************* |
phonemacro | 9:02c5adb483c8 | 56 | */ |
tlyp | 10:d46390b7aa64 | 57 | |
switches | 0:60a522ae2e35 | 58 | #include "mbed.h" |
switches | 2:57500e991166 | 59 | #include "max32630fthr.h" |
switches | 1:6923b075c8d7 | 60 | #include "USBSerial.h" |
tlyp | 10:d46390b7aa64 | 61 | #include "MAX30208.h" |
tlyp | 10:d46390b7aa64 | 62 | #include "ForwardErrCorr.h" |
switches | 0:60a522ae2e35 | 63 | |
switches | 6:684c51f32c1d | 64 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
switches | 0:60a522ae2e35 | 65 | |
tlyp | 10:d46390b7aa64 | 66 | //UART Port for Sending data |
tlyp | 10:d46390b7aa64 | 67 | RawSerial uart(P3_1,P3_0);//tx,rx |
tlyp | 10:d46390b7aa64 | 68 | |
tlyp | 10:d46390b7aa64 | 69 | |
tlyp | 10:d46390b7aa64 | 70 | I2C i2c(P3_4, P3_5); //sda,scl |
tlyp | 10:d46390b7aa64 | 71 | MAX30208 TempSensor(i2c, 0x50); //Temperature Sensor Object for reading temperature data |
tlyp | 10:d46390b7aa64 | 72 | |
tlyp | 10:d46390b7aa64 | 73 | #define SymmetricKey "RfIsCoOl" //Set Symmetric Key here -- Make sure it is identical to receiver |
tlyp | 10:d46390b7aa64 | 74 | char TransTable[] = {0x1F,0x18,0x06,0x01}; //Used to translate data for FEC -- Make sure it is identical to receiver |
tlyp | 10:d46390b7aa64 | 75 | Translator transTx(SymmetricKey, TransTable); //Initialize Encoder |
tlyp | 10:d46390b7aa64 | 76 | |
tlyp | 10:d46390b7aa64 | 77 | DigitalOut rLED(LED1); |
tlyp | 10:d46390b7aa64 | 78 | DigitalOut gLED(LED2); |
tlyp | 10:d46390b7aa64 | 79 | DigitalOut bLED(LED3); |
tlyp | 10:d46390b7aa64 | 80 | |
tlyp | 10:d46390b7aa64 | 81 | DigitalIn sw1(SW1); //Trigger for sending data |
tlyp | 10:d46390b7aa64 | 82 | DigitalOut Enable(P5_2); //Enable Transmitter |
tlyp | 10:d46390b7aa64 | 83 | |
tlyp | 10:d46390b7aa64 | 84 | char DEVICETYPE = 'T'; //Set Device Type |
tlyp | 10:d46390b7aa64 | 85 | char DEVICEID = 0x01; //Set the Device ID |
tlyp | 10:d46390b7aa64 | 86 | |
tlyp | 10:d46390b7aa64 | 87 | //****************************************************************************** |
switches | 1:6923b075c8d7 | 88 | |
tlyp | 10:d46390b7aa64 | 89 | /** |
tlyp | 10:d46390b7aa64 | 90 | * @brief Record and read temperature from MAX30208 |
tlyp | 10:d46390b7aa64 | 91 | * @param TempSensor - Refrence to MAX30208 temp sensor object |
tlyp | 10:d46390b7aa64 | 92 | * @param &value[OUT]- Address to store read temperature at |
tlyp | 10:d46390b7aa64 | 93 | * @return 0 on success, 1 on failure due to improper data record or read |
tlyp | 10:d46390b7aa64 | 94 | */ |
tlyp | 10:d46390b7aa64 | 95 | int ReadData(MAX30208 TempSensor, uint16_t &value){ |
tlyp | 10:d46390b7aa64 | 96 | if (TempSensor.takeDataMeasurment() != 0){ |
tlyp | 10:d46390b7aa64 | 97 | printf("Error Taking data Meaurment\r\n"); |
tlyp | 10:d46390b7aa64 | 98 | return(1); |
tlyp | 10:d46390b7aa64 | 99 | } |
tlyp | 10:d46390b7aa64 | 100 | wait_ms(50); //max temp record time is 50ms |
tlyp | 10:d46390b7aa64 | 101 | if (TempSensor.readData(value) !=0){ |
tlyp | 10:d46390b7aa64 | 102 | printf("Error reading temperature Data\r\n"); |
tlyp | 10:d46390b7aa64 | 103 | return(1); |
tlyp | 10:d46390b7aa64 | 104 | } |
tlyp | 10:d46390b7aa64 | 105 | return(0); |
tlyp | 10:d46390b7aa64 | 106 | } |
tlyp | 10:d46390b7aa64 | 107 | |
tlyp | 10:d46390b7aa64 | 108 | //****************************************************************************** |
switches | 0:60a522ae2e35 | 109 | |
tlyp | 10:d46390b7aa64 | 110 | /* |
tlyp | 10:d46390b7aa64 | 111 | * @brief Begin Communication with warm up bytes and device type/id |
tlyp | 10:d46390b7aa64 | 112 | */ |
tlyp | 10:d46390b7aa64 | 113 | void comInit(Translator trans){ |
tlyp | 10:d46390b7aa64 | 114 | uart.putc(0xFF); //Initializer bytes to "warm-up" the Peak Detector cicuitry of MAX1473 Receiver |
tlyp | 10:d46390b7aa64 | 115 | uart.putc(0xFF); |
tlyp | 10:d46390b7aa64 | 116 | uart.putc(0x00); |
tlyp | 10:d46390b7aa64 | 117 | uart.putc('b'); //Packet start character |
tlyp | 10:d46390b7aa64 | 118 | uart.putc(DEVICETYPE); //Send Device Type |
tlyp | 10:d46390b7aa64 | 119 | uart.putc(DEVICEID); //Send Device ID |
tlyp | 10:d46390b7aa64 | 120 | } |
tlyp | 10:d46390b7aa64 | 121 | |
tlyp | 10:d46390b7aa64 | 122 | //****************************************************************************** |
tlyp | 10:d46390b7aa64 | 123 | |
tlyp | 10:d46390b7aa64 | 124 | /** |
tlyp | 10:d46390b7aa64 | 125 | * @brief Send data and end transmission |
tlyp | 10:d46390b7aa64 | 126 | * @param EncryptedData[IN] - 8 bytes of encryted data to send via UART connection |
tlyp | 10:d46390b7aa64 | 127 | */ |
tlyp | 10:d46390b7aa64 | 128 | void comData(char *EncryptedData){ |
tlyp | 10:d46390b7aa64 | 129 | for(int i=0;i<8;i++){ |
tlyp | 10:d46390b7aa64 | 130 | uart.putc(EncryptedData[i]); //Send all of the encrypted data |
tlyp | 10:d46390b7aa64 | 131 | } |
tlyp | 10:d46390b7aa64 | 132 | uart.putc('c'); //End of packet character |
tlyp | 10:d46390b7aa64 | 133 | uart.send_break(); |
tlyp | 10:d46390b7aa64 | 134 | } |
tlyp | 10:d46390b7aa64 | 135 | |
tlyp | 10:d46390b7aa64 | 136 | //****************************************************************************** |
tlyp | 10:d46390b7aa64 | 137 | |
switches | 0:60a522ae2e35 | 138 | int main() |
switches | 0:60a522ae2e35 | 139 | { |
tlyp | 10:d46390b7aa64 | 140 | wait(1); |
tlyp | 10:d46390b7aa64 | 141 | uart.baud(9600); |
tlyp | 10:d46390b7aa64 | 142 | printf("Starting Transmitter Program\r\n\r\n"); |
tlyp | 10:d46390b7aa64 | 143 | |
switches | 2:57500e991166 | 144 | rLED = LED_ON; |
switches | 2:57500e991166 | 145 | gLED = LED_ON; |
switches | 2:57500e991166 | 146 | bLED = LED_OFF; |
switches | 0:60a522ae2e35 | 147 | |
switches | 2:57500e991166 | 148 | rLED = LED_OFF; |
tlyp | 10:d46390b7aa64 | 149 | |
tlyp | 10:d46390b7aa64 | 150 | //Start MAX30208 temperature sensor in factor default |
tlyp | 10:d46390b7aa64 | 151 | TempSensor.resetDevice(); |
tlyp | 10:d46390b7aa64 | 152 | |
tlyp | 10:d46390b7aa64 | 153 | //Turn off Transmitter |
tlyp | 10:d46390b7aa64 | 154 | Enable = 0; |
switches | 1:6923b075c8d7 | 155 | |
switches | 1:6923b075c8d7 | 156 | while(1) { |
tlyp | 10:d46390b7aa64 | 157 | |
tlyp | 10:d46390b7aa64 | 158 | //Record a temperature and send the encrypted data each time the on-board button is pressed |
tlyp | 10:d46390b7aa64 | 159 | if(sw1==0){ |
tlyp | 10:d46390b7aa64 | 160 | |
tlyp | 10:d46390b7aa64 | 161 | //Enable Transmitter |
tlyp | 10:d46390b7aa64 | 162 | Enable = 1; |
tlyp | 10:d46390b7aa64 | 163 | |
tlyp | 10:d46390b7aa64 | 164 | //Read a new temperature |
tlyp | 10:d46390b7aa64 | 165 | uint16_t tempData; |
tlyp | 10:d46390b7aa64 | 166 | if(ReadData(TempSensor,tempData) !=0){ |
tlyp | 10:d46390b7aa64 | 167 | printf("Error reading data!\r\n"); |
tlyp | 10:d46390b7aa64 | 168 | } |
tlyp | 10:d46390b7aa64 | 169 | |
tlyp | 10:d46390b7aa64 | 170 | //Encrypt Temperature Data |
tlyp | 10:d46390b7aa64 | 171 | char EncryptedData[8]; |
tlyp | 10:d46390b7aa64 | 172 | printf("Original Data: %i\r\n", tempData); |
tlyp | 10:d46390b7aa64 | 173 | transTx.Encrypt(tempData,EncryptedData); |
tlyp | 10:d46390b7aa64 | 174 | printf("Encrypted Data:\r\n"); |
tlyp | 10:d46390b7aa64 | 175 | for(int i=0;i<8;i++){ |
tlyp | 10:d46390b7aa64 | 176 | printf("%c ",EncryptedData[i]); |
tlyp | 10:d46390b7aa64 | 177 | } |
tlyp | 10:d46390b7aa64 | 178 | printf("\r\n\r\n"); |
tlyp | 10:d46390b7aa64 | 179 | |
tlyp | 10:d46390b7aa64 | 180 | //Initialize Communication |
tlyp | 10:d46390b7aa64 | 181 | comInit(transTx); |
tlyp | 10:d46390b7aa64 | 182 | |
tlyp | 10:d46390b7aa64 | 183 | //Send Encrypted Data |
tlyp | 10:d46390b7aa64 | 184 | comData(EncryptedData); |
tlyp | 10:d46390b7aa64 | 185 | |
tlyp | 10:d46390b7aa64 | 186 | //Turn off Transmitter |
tlyp | 10:d46390b7aa64 | 187 | Enable = 0; |
switches | 0:60a522ae2e35 | 188 | |
tlyp | 10:d46390b7aa64 | 189 | wait_ms(500); //button debounce |
tlyp | 10:d46390b7aa64 | 190 | }//if |
tlyp | 10:d46390b7aa64 | 191 | }//while |
tlyp | 10:d46390b7aa64 | 192 | }//main |
tlyp | 10:d46390b7aa64 | 193 |