├── Arduino Uno R3 ├── README - Copy.md ├── examples │ ├── ADE9153A_examples │ │ └── ADE9153AAPI_Test │ │ │ └── ADE9153AAPI_Test.ino │ ├── ADXL362_example │ │ ├── ADXL362.cpp │ │ ├── ADXL362.h │ │ ├── ADXL362_example.ino │ │ ├── Communication.cpp │ │ ├── Communication.h │ │ ├── Lcd.cpp │ │ └── Lcd.h │ ├── ADXL372_example │ │ ├── ADXL372_example.ino │ │ ├── Communication.cpp │ │ ├── Communication.h │ │ ├── adxl372.cpp │ │ └── adxl372.h │ ├── CN0216_example │ │ ├── AD7791.cpp │ │ ├── AD7791.h │ │ └── CN0216_example.ino │ ├── CN0357_example │ │ ├── AD5270.cpp │ │ ├── AD5270.h │ │ ├── AD7790.cpp │ │ ├── AD7790.h │ │ └── CN0357_example.ino │ ├── CN0391_example │ │ ├── AD7124.cpp │ │ ├── AD7124.h │ │ ├── CN0391.cpp │ │ ├── CN0391.h │ │ ├── CN0391_example.ino │ │ ├── Communication.cpp │ │ ├── Communication.h │ │ ├── PROGMEM_readAnything.h │ │ ├── RTD.h │ │ └── Thermocouple.h │ ├── CN0395_example │ │ ├── AD7988.cpp │ │ ├── AD7988.h │ │ ├── ADN8810.cpp │ │ ├── ADN8810.h │ │ ├── CN0395.cpp │ │ ├── CN0395.h │ │ ├── CN0395_example.ino │ │ ├── Communication.cpp │ │ ├── Communication.h │ │ ├── SHT30.cpp │ │ └── SHT30.h │ ├── CN0396_example │ │ ├── AD5270.cpp │ │ ├── AD5270.h │ │ ├── AD7798.cpp │ │ ├── AD7798.h │ │ ├── ADT7310.cpp │ │ ├── ADT7310.h │ │ ├── CN0396.cpp │ │ ├── CN0396.h │ │ ├── CN0396_example.ino │ │ ├── Communication.cpp │ │ └── Communication.h │ ├── CN0397_example │ │ ├── AD7798.cpp │ │ ├── AD7798.h │ │ ├── CN0397.cpp │ │ ├── CN0397.h │ │ ├── CN0397_example.ino │ │ ├── Communication.cpp │ │ └── Communication.h │ ├── CN0410_example │ │ ├── CN0410_example.ino │ │ ├── adi_cn0410.cpp │ │ └── adi_cn0410.h │ └── CN0411_example │ │ ├── AD5683.cpp │ │ ├── AD5683.h │ │ ├── AD7124.cpp │ │ ├── AD7124.h │ │ ├── AD7124_regs.cpp │ │ ├── AD7124_regs.h │ │ ├── CN0411.cpp │ │ ├── CN0411.h │ │ ├── CN0411_example_uno.ino │ │ ├── Communication.cpp │ │ ├── Communication.h │ │ ├── Timer.cpp │ │ └── Timer.h └── libraries │ ├── AD5270 │ ├── AD5270.cpp │ └── AD5270.h │ ├── AD7790 │ ├── AD7790.cpp │ └── AD7790.h │ ├── AD7791 │ ├── AD7791.cpp │ └── AD7791.h │ ├── ADE9153A │ ├── ADE9153A.h │ ├── ADE9153AAPI.cpp │ ├── ADE9153AAPI.h │ ├── README.md │ └── keywords.txt │ ├── ADXL362-ADRZ │ ├── ADXL362-ARDZ.cpp │ └── ADXL362-ARDZ.h │ └── ST7565_LCD │ ├── ST7565R_LCD.cpp │ └── ST7565R_LCD.h ├── LICENSE.txt ├── README.md ├── azure-pipelines.yml └── ci ├── lib.sh └── run_build.sh /Arduino Uno R3/README - Copy.md: -------------------------------------------------------------------------------- 1 | # arduino 2 | Adruino Sketches 3 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/ADXL362_example/ADXL362.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ADXL362.c 4 | * @brief Source file for ADXL362 accelerometer control. 5 | * @version V0.3 6 | * @author ADI 7 | * @date March 2016 8 | * @par Revision History: 9 | * - V0.1, September 2015: initial version. 10 | * - V0.2, October 2015: removed ACC definitions, added configuration for CSACC pin and revision history. 11 | * - V0.3, March 2016: added support for ADXL362 INT pin. 12 | * 13 | ******************************************************************************* 14 | * Copyright 2015(c) Analog Devices, Inc. 15 | * 16 | * All rights reserved. 17 | * 18 | * Redistribution and use in source and binary forms, with or without modification, 19 | * are permitted provided that the following conditions are met: 20 | * - Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * - Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in 24 | * the documentation and/or other materials provided with the 25 | * distribution. 26 | * - Neither the name of Analog Devices, Inc. nor the names of its 27 | * contributors may be used to endorse or promote products derived 28 | * from this software without specific prior written permission. 29 | * - The use of this software may or may not infringe the patent rights 30 | * of one or more patent holders. This license does not release you 31 | * from the requirement that you obtain separate licenses from these 32 | * patent holders to use this software. 33 | * - Use of the software either in source or binary form, must be run 34 | * on or directly connected to an Analog Devices Inc. component. 35 | * 36 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED 37 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY 38 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 39 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 41 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 45 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ******************************************************************************* 48 | **/ 49 | 50 | /***************************** Include Files **********************************/ 51 | #include 52 | 53 | #include "ADXL362.h" 54 | #include "Communication.h" 55 | 56 | /****************************** Global Data ***********************************/ 57 | 58 | int16_t i16SensorX; 59 | int16_t i16SensorY; 60 | int16_t i16SensorZ; 61 | int16_t i16SensorT; 62 | 63 | volatile uint32_t ui32timer_counter = 0; 64 | 65 | 66 | /*************************** Module static data *******************************/ 67 | 68 | /* Accelerometer scan counter */ 69 | static uint32_t ui32ScanSensorCounter; 70 | 71 | /************************* Global scope functions *****************************/ 72 | 73 | /** 74 | @brief Initialization the accelerometer sensor 75 | 76 | @return none 77 | 78 | **/ 79 | void Sensor_Init(void) 80 | { 81 | pinMode(CSACC_PIN, OUTPUT); /* Set CSACC pin as output */ 82 | 83 | pinMode(INTACC_PIN, INPUT); /* Set INTACC pin as input */ 84 | 85 | SPI_Write(SOFT_RESET_REG, 0x52, SPI_WRITE_REG); /* Soft reset accelerometer */ 86 | 87 | delay(100); /* Wait at least 0.5 ms */ 88 | 89 | /* Set activity threshold */ 90 | SPI_Write(THRESH_ACT_L, ACT_VALUE & 0xFF, SPI_WRITE_REG); 91 | SPI_Write(THRESH_ACT_H, ACT_VALUE >> 8, SPI_WRITE_REG); 92 | 93 | SPI_Write(TIME_ACT, (ACT_TIMER / 10), SPI_WRITE_REG); /* Set activity time at 100Hz data rate */ 94 | 95 | /* Set inactivity threshold */ 96 | SPI_Write(THRESH_INACT_L, INACT_VALUE & 0xFF, SPI_WRITE_REG); 97 | SPI_Write(THRESH_INACT_H, INACT_VALUE >> 8, SPI_WRITE_REG); 98 | 99 | /* Set inactivity time at 100Hz data rate */ 100 | SPI_Write(TIME_INACT_L, ((INACT_TIMER * 100) & 0xFF), SPI_WRITE_REG); 101 | SPI_Write(TIME_INACT_H, ((INACT_TIMER * 100) >> 8), SPI_WRITE_REG); 102 | 103 | SPI_Write(ACT_INACT_CTL, 0x3F, SPI_WRITE_REG); /* Set Loop mode, referenced mode for activity and inactivity, enable activity and inactivity functionality */ 104 | 105 | #if(ADXL_INT_SEL == INTACC_PIN_1) 106 | SPI_Write(INTMAP1, 0x40, SPI_WRITE_REG); /* Map the awake status to INT1 pin */ 107 | #elif(ADXL_INT_SEL == INTACC_PIN_2) 108 | SPI_Write(INTMAP2, 0x40, SPI_WRITE_REG); /* Map the awake status to INT2 pin */ 109 | #endif 110 | } 111 | 112 | /** 113 | @brief Turns on accelerometer measurement mode. 114 | 115 | @return none 116 | 117 | **/ 118 | void Sensor_Start(void) 119 | { 120 | uint8_t ui8temp; 121 | 122 | ui8temp = (uint8_t)SPI_Read(POWER_CTL_REG, SPI_READ_ONE_REG); /* Read POWER_CTL register, before modifying it */ 123 | 124 | ui8temp = ui8temp | 0x02; /* Set measurement bit in POWER_CTL register */ 125 | 126 | SPI_Write(POWER_CTL_REG, ui8temp, SPI_WRITE_REG); /* Write the new value to POWER_CTL register */ 127 | } 128 | 129 | 130 | /** 131 | @brief Puts the accelerometer into standby mode. 132 | 133 | @return none 134 | 135 | **/ 136 | void Sensor_Stop(void) 137 | { 138 | uint8_t ui8temp; 139 | 140 | ui8temp = (uint8_t)SPI_Read(POWER_CTL_REG, SPI_READ_ONE_REG); /*Read POWER_CTL register, before modifying it */ 141 | 142 | ui8temp = ui8temp & 0xFC; /* Clear measurement bit in POWER_CTL register */ 143 | 144 | SPI_Write(POWER_CTL_REG, ui8temp, SPI_WRITE_REG); /* Write the new value to POWER_CTL register */ 145 | 146 | } 147 | 148 | /** 149 | @brief Reads the accelerometer data. 150 | 151 | @return none 152 | 153 | **/ 154 | void Sensor_Scan(void) 155 | { 156 | i16SensorX = SPI_Read(XDATA_L_REG, SPI_READ_TWO_REG); 157 | 158 | i16SensorY = SPI_Read(YDATA_L_REG, SPI_READ_TWO_REG); 159 | 160 | i16SensorZ = SPI_Read(ZDATA_L_REG, SPI_READ_TWO_REG); 161 | 162 | i16SensorT = SPI_Read(TEMP_L_REG, SPI_READ_TWO_REG); 163 | 164 | delay(200); 165 | } 166 | 167 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/ADXL362_example/ADXL362.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ADXL362.h 4 | * @brief Header file for ADXL362 accelerometer control. 5 | * @version V0.3 6 | * @author ADI 7 | * @date March 2016 8 | * @par Revision History: 9 | * - V0.1, September 2015: initial version. 10 | * - V0.2, October 2015: moved ACC definitions and added revision history. 11 | * - V0.3, March 2016: updated temperature parameters - name and value. 12 | * 13 | ******************************************************************************* 14 | * Copyright 2015(c) Analog Devices, Inc. 15 | * 16 | * All rights reserved. 17 | * 18 | * Redistribution and use in source and binary forms, with or without modification, 19 | * are permitted provided that the following conditions are met: 20 | * - Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * - Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in 24 | * the documentation and/or other materials provided with the 25 | * distribution. 26 | * - Neither the name of Analog Devices, Inc. nor the names of its 27 | * contributors may be used to endorse or promote products derived 28 | * from this software without specific prior written permission. 29 | * - The use of this software may or may not infringe the patent rights 30 | * of one or more patent holders. This license does not release you 31 | * from the requirement that you obtain separate licenses from these 32 | * patent holders to use this software. 33 | * - Use of the software either in source or binary form, must be run 34 | * on or directly connected to an Analog Devices Inc. component. 35 | * 36 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED 37 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY 38 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 39 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 41 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 45 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ******************************************************************************* 48 | **/ 49 | #ifndef ADXL362_H_ 50 | #define ADXL362_H_ 51 | 52 | #include "Arduino.h" 53 | 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | 58 | /********************************* Definitions ********************************/ 59 | 60 | /* Accelerometer registers addresses */ 61 | #define STATUS_REG 0x0B 62 | #define XDATA_L_REG 0x0E 63 | #define YDATA_L_REG 0x10 64 | #define ZDATA_L_REG 0x12 65 | #define TEMP_L_REG 0x14 66 | #define SOFT_RESET_REG 0x1F 67 | #define THRESH_ACT_L 0x20 68 | #define THRESH_ACT_H 0x21 69 | #define TIME_ACT 0x22 70 | #define THRESH_INACT_L 0x23 71 | #define THRESH_INACT_H 0x24 72 | #define TIME_INACT_L 0x25 73 | #define TIME_INACT_H 0x26 74 | #define ACT_INACT_CTL 0x27 75 | #define INTMAP1 0x2A 76 | #define INTMAP2 0x2B 77 | #define POWER_CTL_REG 0x2D 78 | 79 | 80 | /**************************** Configuration parameters **********************/ 81 | 82 | #define TEMP_ADC 0 /* Temperature display units: 1 for ADC, 0 for degrees Celsius */ 83 | 84 | /* Temperature parameters */ 85 | #define ACC_TEMP_BIAS (float)350 /* Accelerometer temperature bias(in ADC codes) at 25 Deg C */ 86 | #define ACC_TEMP_SENSITIVITY (float)0.065 /* Accelerometer temperature sensitivity from datasheet (DegC per Code) */ 87 | 88 | #define SCAN_SENSOR_TIME 500 /* Accelerometer scan interval in ms */ 89 | 90 | #define ACT_VALUE 50 /* Activity threshold value */ 91 | 92 | #define INACT_VALUE 50 /* Inactivity threshold value */ 93 | 94 | #define ACT_TIMER 100 /* Activity timer value in ms */ 95 | 96 | #define INACT_TIMER 10 /* Inactivity timer value in seconds */ 97 | 98 | 99 | /****************************** Global Data ***********************************/ 100 | 101 | extern int16_t i16SensorX; 102 | extern int16_t i16SensorY; 103 | extern int16_t i16SensorZ; 104 | extern int16_t i16SensorT; 105 | 106 | extern volatile uint32_t ui32timer_counter; 107 | 108 | 109 | /*************************** Functions prototypes *****************************/ 110 | 111 | void Sensor_Init(void); 112 | void Sensor_Start(void); 113 | void Sensor_Stop(void); 114 | void Sensor_Scan(void); 115 | uint8_t Sensor_Delay(uint8_t ui8StartFlag, uint32_t *pu32EndTm, uint32_t ui32Delay); 116 | 117 | #ifdef __cplusplus 118 | } // extern "C" 119 | #endif 120 | 121 | #endif /* ADXL362_H_ */ 122 | 123 | /* End Of File */ 124 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/ADXL362_example/ADXL362_example.ino: -------------------------------------------------------------------------------- 1 | #include "ADXL362.h" 2 | #include "Lcd.h" 3 | #include "Communication.h" 4 | #include 5 | 6 | byte ADXL_CS_PIN = 10; 7 | byte LCD_CS_PIN = 11; 8 | 9 | uint8_t ui8s[22]; 10 | uint8_t ui8xu; 11 | uint8_t ui8xd; 12 | uint8_t ui8yu; 13 | uint8_t ui8yd; 14 | uint8_t ui8all; 15 | uint8_t ui8awake; 16 | 17 | char temp[10]; 18 | 19 | #if TEMP_ADC == 0 20 | float f32temp; 21 | #endif 22 | 23 | 24 | void setup() { 25 | Serial.begin(9600); 26 | SPI.begin(); 27 | SPI.setDataMode(SPI_MODE3); //CPHA = CPOL = 1 MODE = 3 28 | delay(1000); 29 | 30 | /* Initialize LCD */ 31 | Lcd_Init(); 32 | 33 | /* Initialize accelerometer */ 34 | Sensor_Init(); 35 | 36 | /* Start accelerometer measurement mode */ 37 | Sensor_Start(); 38 | 39 | } 40 | 41 | void loop() { 42 | if (digitalRead(INTACC_PIN)) { 43 | if (ui8awake == 0) { 44 | ui8awake = 1; 45 | 46 | /* Set BLLCD pin - turn on LCD backlight */ 47 | digitalWrite(BLLCD_PIN,HIGH); 48 | 49 | Lcd_DisplayString(0, 60, (int8_t *)"[mG]"); 50 | Lcd_DisplayString(1, 60, (int8_t *)"[mG]"); 51 | Lcd_DisplayString(2, 60, (int8_t *)"[mG]"); 52 | 53 | #if TEMP_ADC == 1 54 | Lcd_DisplayString(3, 60, (int8_t *)"[ADC]"); 55 | #else 56 | Lcd_DisplayString(3, 60, (int8_t *)" [C]"); 57 | #endif 58 | ui8xu = 0; 59 | ui8xd = 0; 60 | ui8yu = 0; 61 | ui8yd = 0; 62 | ui8all = 0; 63 | 64 | Lcd_DisplaySymbol(0, UP_X, 8, pui8RecInv8x8); 65 | Lcd_DisplaySymbol(1, LEFT_X, 8, pui8RecInv8x8); 66 | Lcd_DisplaySymbol(1, RIGHT_X, 8, pui8RecInv8x8); 67 | Lcd_DisplaySymbol(2, DOWN_X, 8, pui8RecInv8x8); 68 | Lcd_DisplaySymbol(1, CENTER_X, 8, pui8RecInv8x8); 69 | } 70 | 71 | } else { 72 | if (ui8awake == 1) { 73 | ui8awake = 0; 74 | 75 | /* Clear BLLCD pin - turn off LCD backlight */ 76 | digitalWrite(BLLCD_PIN,LOW); 77 | 78 | /* Clear screen */ 79 | Lcd_FillPages(0, 4, 0x00); 80 | } 81 | } 82 | 83 | if (ui8awake == 1) { 84 | Sensor_Scan(); 85 | 86 | sprintf((char *)ui8s, "x = % 5d", i16SensorX); 87 | Lcd_DisplayString(0, 0, (int8_t *)ui8s); 88 | 89 | sprintf((char *)ui8s, "y = % 5d", i16SensorY); 90 | Lcd_DisplayString(1, 0, (int8_t *)ui8s); 91 | 92 | sprintf((char *)ui8s, "z = % 5d", i16SensorZ); 93 | Lcd_DisplayString(2, 0, (int8_t *)ui8s); 94 | 95 | #if TEMP_ADC == 1 96 | sprintf((char *)ui8s, "t = % 5d", i16SensorT); 97 | Lcd_DisplayString(3, 0, (int8_t *)ui8s); 98 | #else 99 | f32temp = ((float)i16SensorT + ACC_TEMP_BIAS) / (1 / ACC_TEMP_SENSITIVITY); 100 | Lcd_DisplayString(3, 60, (int8_t *)" [C]"); 101 | dtostrf(f32temp, 2, 2, temp); 102 | sprintf((char *)ui8s, "t = %s ", temp); 103 | Lcd_DisplayString(3, 0, (int8_t *)ui8s); 104 | #endif 105 | 106 | if (i16SensorY > ACC_LIMIT) { 107 | if (ui8xu == 0) { 108 | ui8xu = 1; 109 | Lcd_DisplaySymbol(0, UP_X, 8, pui8Rec8x8); 110 | } 111 | 112 | } else { 113 | if (ui8xu == 1) { 114 | ui8xu = 0; 115 | Lcd_DisplaySymbol(0, UP_X, 8, pui8RecInv8x8); 116 | } 117 | } 118 | 119 | if (i16SensorY < -ACC_LIMIT) { 120 | if (ui8xd == 0) { 121 | ui8xd = 1; 122 | Lcd_DisplaySymbol(2, DOWN_X, 8, pui8Rec8x8); 123 | } 124 | 125 | } else { 126 | if (ui8xd == 1) { 127 | ui8xd = 0; 128 | Lcd_DisplaySymbol(2, DOWN_X, 8, pui8RecInv8x8); 129 | } 130 | } 131 | 132 | if (i16SensorX > ACC_LIMIT) { 133 | if (ui8yu == 0) { 134 | ui8yu = 1; 135 | Lcd_DisplaySymbol(1, RIGHT_X, 8, pui8Rec8x8); 136 | } 137 | 138 | } else { 139 | if (ui8yu == 1) { 140 | ui8yu = 0; 141 | Lcd_DisplaySymbol(1, RIGHT_X, 8, pui8RecInv8x8); 142 | } 143 | } 144 | 145 | if (i16SensorX < -ACC_LIMIT) { 146 | if (ui8yd == 0) { 147 | ui8yd = 1; 148 | Lcd_DisplaySymbol(1, LEFT_X, 8, pui8Rec8x8); 149 | } 150 | 151 | } else { 152 | if (ui8yd == 1) { 153 | ui8yd = 0; 154 | Lcd_DisplaySymbol(1, LEFT_X, 8, pui8RecInv8x8); 155 | } 156 | } 157 | 158 | if ((ui8xu == 0) && (ui8xd == 0) && (ui8yu == 0) && (ui8yd == 0)) { 159 | if (ui8all == 0) { 160 | ui8all = 1; 161 | Lcd_DisplaySymbol(1, CENTER_X, 8, pui8Rec8x8); 162 | } 163 | 164 | } else { 165 | if (ui8all == 1) { 166 | ui8all = 0; 167 | Lcd_DisplaySymbol(1, CENTER_X, 8, pui8RecInv8x8); 168 | } 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/ADXL362_example/Communication.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Communication.c 4 | * @brief Source file for communication part. 5 | * @version V0.3 6 | * @author ADI 7 | * @date March 2016 8 | * @par Revision History: 9 | * - V0.1, September 2015: initial version. 10 | * - V0.2, October 2015: changed used SPI channel to SPI1 and added revision history. 11 | * - V0.3, March 2016: changed SPI pins initialization. 12 | * 13 | ******************************************************************************* 14 | * Copyright 2015(c) Analog Devices, Inc. 15 | * 16 | * All rights reserved. 17 | * 18 | * Redistribution and use in source and binary forms, with or without modification, 19 | * are permitted provided that the following conditions are met: 20 | * - Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * - Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in 24 | * the documentation and/or other materials provided with the 25 | * distribution. 26 | * - Neither the name of Analog Devices, Inc. nor the names of its 27 | * contributors may be used to endorse or promote products derived 28 | * from this software without specific prior written permission. 29 | * - The use of this software may or may not infringe the patent rights 30 | * of one or more patent holders. This license does not release you 31 | * from the requirement that you obtain separate licenses from these 32 | * patent holders to use this software. 33 | * - Use of the software either in source or binary form, must be run 34 | * on or directly connected to an Analog Devices Inc. component. 35 | * 36 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED 37 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY 38 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 39 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 41 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 45 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ******************************************************************************* 48 | **/ 49 | 50 | 51 | /***************************** Include Files **********************************/ 52 | #include 53 | #include 54 | 55 | #include "Communication.h" 56 | 57 | /************************* Functions Definitions ******************************/ 58 | 59 | /** 60 | @brief Writes a data, a command or a register to the LCD or to ACC via SPI. 61 | 62 | @param ui8address - ACC register address 63 | @param ui8Data - value to be written 64 | @enMode ui8Data - write mode 65 | 66 | @return none 67 | 68 | **/ 69 | void SPI_Write(uint8_t ui8address, uint8_t ui8Data, enWriteData enMode) 70 | { 71 | if(enMode != SPI_WRITE_REG) { 72 | 73 | digitalWrite(CSLCD_PIN,LOW); /* Select LCD */ 74 | 75 | if(enMode == SPI_WRITE_DATA) { 76 | 77 | digitalWrite(A0LCD_PIN,HIGH); /* Select to send data */ 78 | 79 | } else if(enMode == SPI_WRITE_COMMAND) { 80 | 81 | digitalWrite(A0LCD_PIN,LOW); /* Select to send command */ 82 | } 83 | 84 | SPI.transfer(ui8Data); 85 | 86 | digitalWrite(CSLCD_PIN,HIGH); /* Deselect LCD */ 87 | 88 | } else { 89 | 90 | digitalWrite(CSACC_PIN,LOW); /* Select accelerometer */ 91 | 92 | SPI.transfer(COMM_WRITE); /* Send write command */ 93 | 94 | SPI.transfer(ui8address); /* Send register address */ 95 | 96 | SPI.transfer(ui8Data); /* Send value to be written */ 97 | 98 | digitalWrite(CSACC_PIN,HIGH); /* Deselect accelerometer */ 99 | } 100 | 101 | } 102 | 103 | /** 104 | @brief Reads a specified register or two registers address in the accelerometer via SPI. 105 | 106 | @param ui8address - register address 107 | @param enRegs - register number 108 | 109 | @return reading result 110 | 111 | **/ 112 | uint16_t SPI_Read(uint8_t ui8address, enRegsNum enRegs) 113 | { 114 | 115 | uint16_t ui16Result = 0; 116 | 117 | uint8_t ui8value; 118 | uint16_t ui16valueL; 119 | uint16_t ui16valueH; 120 | 121 | digitalWrite(CSACC_PIN,LOW); /* Select accelerometer */ 122 | 123 | SPI.transfer(COMM_READ); /* Send read command */ 124 | 125 | SPI.transfer(ui8address); /* Send register address */ 126 | 127 | if (enRegs == SPI_READ_ONE_REG) { 128 | 129 | /* Read the register value */ 130 | ui8value = SPI.transfer(0xAA); 131 | 132 | ui16Result = (uint16_t)ui8value; /* Set read result*/ 133 | 134 | } else { 135 | 136 | /* Read the two register values */ 137 | ui16valueL = SPI.transfer(0xAA); 138 | ui16valueH = SPI.transfer(0xAA); 139 | 140 | ui16Result = (uint16_t)((ui16valueH << 8) | ui16valueL); /* Set read result*/ 141 | } 142 | 143 | /* Deselect accelerometer */ 144 | digitalWrite(CSACC_PIN,HIGH); 145 | 146 | return ui16Result; 147 | } 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/ADXL362_example/Lcd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Lcd.c 4 | * @brief Header file for LCD control. 5 | * @version V0.2 6 | * @author ADI 7 | * @date October 2015 8 | * @par Revision History: 9 | * - V0.1, September 2015: initial version. 10 | * - V0.2, October 2015: removed "ST7565R" references and added revision history. 11 | * 12 | ******************************************************************************* 13 | * Copyright 2015(c) Analog Devices, Inc. 14 | * 15 | * All rights reserved. 16 | * 17 | * Redistribution and use in source and binary forms, with or without modification, 18 | * are permitted provided that the following conditions are met: 19 | * - Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * - Redistributions in binary form must reproduce the above copyright 22 | * notice, this list of conditions and the following disclaimer in 23 | * the documentation and/or other materials provided with the 24 | * distribution. 25 | * - Neither the name of Analog Devices, Inc. nor the names of its 26 | * contributors may be used to endorse or promote products derived 27 | * from this software without specific prior written permission. 28 | * - The use of this software may or may not infringe the patent rights 29 | * of one or more patent holders. This license does not release you 30 | * from the requirement that you obtain separate licenses from these 31 | * patent holders to use this software. 32 | * - Use of the software either in source or binary form, must be run 33 | * on or directly connected to an Analog Devices Inc. component. 34 | * 35 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED 36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY 37 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 38 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 39 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 40 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 41 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 42 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 43 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 44 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | * 46 | ******************************************************************************* 47 | **/ 48 | 49 | #ifndef LCD_H_ 50 | #define LCD_H_ 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | /********************************* Definitions ********************************/ 57 | 58 | #define LCD_COLUMNS 128u 59 | #define LCD_PAGES 4u 60 | #define LCD_LINES 64u 61 | 62 | #define UP_X 112 63 | #define LEFT_X 104 64 | #define RIGHT_X 120 65 | #define DOWN_X 112 66 | #define CENTER_X 112 67 | 68 | #define ACC_LIMIT 50 69 | 70 | /* Font size for Y */ 71 | #define FONT_Y_SIZE 8 72 | 73 | /* ASCII offset */ 74 | #define OFFS_ASCII 32 75 | 76 | /* ST7565R LCD commands */ 77 | #define CMD_DISPLAY_OFF 0xAE 78 | #define CMD_DISPLAY_ON 0xAF 79 | #define CMD_SET_DISP_START_LINE 0x40 80 | #define CMD_SET_PAGE 0xB0 81 | #define CMD_SET_COLUMN_UPPER 0x10 82 | #define CMD_SET_COLUMN_LOWER 0x00 83 | #define CMD_SET_ADC_NORMAL 0xA0 84 | #define CMD_SET_ADC_REVERSE 0xA1 85 | #define CMD_SET_DISP_NORMAL 0xA6 86 | #define CMD_SET_DISP_REVERSE 0xA7 87 | #define CMD_SET_ALLPTS_NORMAL 0xA4 88 | #define CMD_SET_ALLPTS_ON 0xA5 89 | #define CMD_SET_BIAS_9 0xA2 90 | #define CMD_SET_BIAS_7 0xA3 91 | #define CMD_RMW 0xE0 92 | #define CMD_RMW_CLEAR 0xEE 93 | #define CMD_INTERNAL_RESET 0xE2 94 | #define CMD_SET_COM_NORMAL 0xC0 95 | #define CMD_SET_COM_REVERSE 0xC8 96 | #define CMD_SET_POWER_CONTROL 0x28 97 | #define CMD_SET_RESISTOR_RATIO 0x20 98 | #define CMD_SET_VOLUME_FIRST 0x81 99 | #define CMD_SET_VOLUME_SECOND 0 100 | #define CMD_SET_STATIC_OFF 0xAC 101 | #define CMD_SET_STATIC_ON 0xAD 102 | #define CMD_SET_STATIC_REG 0x0 103 | #define CMD_SET_BOOSTER_FIRST 0xF8 104 | #define CMD_SET_BOOSTER_234 0 105 | #define CMD_SET_BOOSTER_5 1 106 | #define CMD_SET_BOOSTER_6 3 107 | #define CMD_NOP 0xE3 108 | #define CMD_TEST 0xF0 109 | 110 | 111 | /****************************** Global Data ***********************************/ 112 | 113 | extern const uint8_t pui8Rec8x8[8]; 114 | extern const uint8_t pui8RecInv8x8[8]; 115 | 116 | /************************* Global functions prototypes*************************/ 117 | 118 | void Lcd_Init(void); 119 | void Lcd_DisplayString(uint8_t ui8row, uint8_t ui8col, int8_t *pi8str); 120 | void Lcd_DisplaySymbol(uint8_t ui8row, uint8_t ui8col, uint8_t ui8width, const uint8_t *pui8symbol); 121 | void Lcd_FillPages(uint8_t ui8start, uint8_t ui8num, uint8_t ui8Data); 122 | void Lcd_SetLine(uint8_t ui8line); 123 | 124 | #ifdef __cplusplus 125 | } // extern "C" 126 | #endif 127 | 128 | #endif /* LCD_H_ */ 129 | 130 | /* End Of File */ 131 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/ADXL372_example/ADXL372_example.ino: -------------------------------------------------------------------------------- 1 | #include "SPI.h" 2 | #include "Communication.h" 3 | #include "adxl372.h" 4 | 5 | struct adxl372_device adxl372; 6 | unsigned char devId; 7 | AccelTriplet_t accel_data; 8 | 9 | typedef struct { 10 | float x; 11 | float y; 12 | float z; 13 | }acceleration_G_t; 14 | 15 | acceleration_G_t data_G; 16 | 17 | void Set_Impact_Detection(void) 18 | { 19 | adxl372_Set_Op_mode(&adxl372, STAND_BY); 20 | 21 | adxl372_Set_Autosleep(&adxl372, false); 22 | 23 | adxl372_Set_BandWidth(&adxl372, BW_3200Hz); 24 | 25 | adxl372_Set_ODR(&adxl372, ODR_6400Hz); 26 | 27 | adxl372_Set_WakeUp_Rate(&adxl372, WUR_52ms); 28 | 29 | adxl372_Set_Act_Proc_Mode(&adxl372, LOOPED); 30 | 31 | /* Set Instant On threshold */ 32 | adxl372_Set_InstaOn_Thresh(&adxl372, ADXL_INSTAON_LOW_THRESH); //Low threshold 10-15 G 33 | 34 | /*Put fifo in Peak Detect and Stream Mode */ 35 | adxl372_Configure_FIFO(&adxl372, 512, STREAMED, XYZ_PEAK_FIFO); 36 | 37 | /* Set activity/inactivity threshold */ 38 | adxl372_Set_Activity_Threshold(&adxl372, ACT_VALUE, true, true); 39 | adxl372_Set_Inactivity_Threshold(&adxl372, INACT_VALUE, true, true); 40 | 41 | /* Set activity/inactivity time settings */ 42 | adxl372_Set_Activity_Time(&adxl372, ACT_TIMER); 43 | adxl372_Set_Inactivity_Time(&adxl372, INACT_TIMER); 44 | 45 | /* Set instant-on interrupts and activity interrupts */ 46 | adxl372_Set_Interrupts(&adxl372); 47 | 48 | /* Set filter settle time */ 49 | adxl372_Set_Filter_Settle(&adxl372, FILTER_SETTLE_16); 50 | 51 | /* Set operation mode to Instant-On */ 52 | adxl372_Set_Op_mode(&adxl372, INSTANT_ON); 53 | } 54 | 55 | void setup() { 56 | Serial.begin(9600); 57 | SPI.begin(); 58 | SPI.setDataMode(SPI_MODE0); //CPHA = CPOL = 0 MODE = 0 59 | delay(1000); 60 | 61 | pinMode(CS_PIN, OUTPUT); 62 | pinMode(ADXL_INT1_PIN, INPUT); 63 | 64 | adxl372_Get_DevID(&adxl372, &devId); 65 | 66 | Serial.print("Device id: "); 67 | Serial.println(devId, HEX); 68 | 69 | adxl372_Set_Op_mode(&adxl372, FULL_BW_MEASUREMENT); 70 | Set_Impact_Detection(); 71 | } 72 | 73 | void loop() { 74 | 75 | if (digitalRead(ADXL_INT1_PIN)) { 76 | delay(500); 77 | adxl372_Get_Highest_Peak_Accel_data(&adxl372, &accel_data); 78 | 79 | /*Transform in G values*/ 80 | data_G.x = (float)accel_data.x * 100 / 1000; 81 | data_G.y = (float)accel_data.y * 100 / 1000; 82 | data_G.z = (float)accel_data.z * 100 / 1000; 83 | 84 | Serial.print("X accel = "); Serial.print(data_G.x); Serial.println(" G"); 85 | Serial.print("Y accel = "); Serial.print(data_G.y); Serial.println(" G"); 86 | Serial.print("Z accel = "); Serial.print(data_G.z); Serial.println(" G"); 87 | Serial.println(""); 88 | 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/ADXL372_example/Communication.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Communication.c 4 | * @brief Source file for communication part. 5 | * @version V0.3 6 | * @author ADI 7 | * @date March 2016 8 | * @par Revision History: 9 | * - V0.1, September 2015: initial version. 10 | * - V0.2, October 2015: changed used SPI channel to SPI1 and added revision history. 11 | * - V0.3, March 2016: changed SPI pins initialization. 12 | * 13 | ******************************************************************************* 14 | * Copyright 2015(c) Analog Devices, Inc. 15 | * 16 | * All rights reserved. 17 | * 18 | * Redistribution and use in source and binary forms, with or without modification, 19 | * are permitted provided that the following conditions are met: 20 | * - Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * - Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in 24 | * the documentation and/or other materials provided with the 25 | * distribution. 26 | * - Neither the name of Analog Devices, Inc. nor the names of its 27 | * contributors may be used to endorse or promote products derived 28 | * from this software without specific prior written permission. 29 | * - The use of this software may or may not infringe the patent rights 30 | * of one or more patent holders. This license does not release you 31 | * from the requirement that you obtain separate licenses from these 32 | * patent holders to use this software. 33 | * - Use of the software either in source or binary form, must be run 34 | * on or directly connected to an Analog Devices Inc. component. 35 | * 36 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED 37 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY 38 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 39 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 41 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 45 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ******************************************************************************* 48 | **/ 49 | 50 | 51 | /***************************** Include Files **********************************/ 52 | #include 53 | #include 54 | 55 | #include "Communication.h" 56 | 57 | /************************* Functions Definitions ******************************/ 58 | 59 | /** 60 | @brief Write & Reads a specified register or two registers address in the accelerometer via SPI. 61 | 62 | @param ui8address - register address 63 | @param enRegs - register number 64 | 65 | @return reading result 66 | 67 | **/ 68 | int spi_write_then_read(adxl_spi_handle *spiTransfer, 69 | unsigned char *txbuf, 70 | unsigned n_tx, 71 | unsigned char *rxbuf, 72 | unsigned n_rx) 73 | { 74 | unsigned char count; 75 | int err = 0; 76 | 77 | 78 | digitalWrite(CS_PIN,LOW); 79 | 80 | for(count = 0; count < n_tx; count++) 81 | { 82 | SPI.transfer((unsigned char)txbuf[count]); 83 | } 84 | 85 | for(count = 0; count < n_rx; count++) 86 | { 87 | rxbuf[count] = SPI.transfer(0xAA); 88 | } 89 | 90 | digitalWrite(CS_PIN,HIGH); 91 | 92 | return err; 93 | } 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/ADXL372_example/Communication.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Communication.h 4 | * @brief Header file for communication part 5 | * @version V0.3 6 | * @author ADI 7 | * @date March 2016 8 | * @par Revision History: 9 | * - V0.1, September 2015: initial version. 10 | * - V0.2, October 2015: added missing comments and revision history. 11 | * - V0.3, March 2016: added pin configuration based on pin selection. 12 | * 13 | ******************************************************************************* 14 | * Copyright 2015(c) Analog Devices, Inc. 15 | * 16 | * All rights reserved. 17 | * 18 | * Redistribution and use in source and binary forms, with or without modification, 19 | * are permitted provided that the following conditions are met: 20 | * - Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * - Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in 24 | * the documentation and/or other materials provided with the 25 | * distribution. 26 | * - Neither the name of Analog Devices, Inc. nor the names of its 27 | * contributors may be used to endorse or promote products derived 28 | * from this software without specific prior written permission. 29 | * - The use of this software may or may not infringe the patent rights 30 | * of one or more patent holders. This license does not release you 31 | * from the requirement that you obtain separate licenses from these 32 | * patent holders to use this software. 33 | * - Use of the software either in source or binary form, must be run 34 | * on or directly connected to an Analog Devices Inc. component. 35 | * 36 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED 37 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY 38 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 39 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 41 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 45 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ******************************************************************************* 48 | **/ 49 | #ifndef _COMMUNICATION_H_ 50 | #define _COMMUNICATION_H_ 51 | 52 | #include "Arduino.h" 53 | #include "SPI.h" 54 | #include "adxl372.h" 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | /******************************************************************************* 61 | **************************** Internal types ************************************ 62 | ********************************************************************************/ 63 | 64 | /* Write data mode */ 65 | typedef enum { 66 | SPI_WRITE_DATA = 1, /* Write data to LCD */ 67 | SPI_WRITE_COMMAND, /* Write command to LCD */ 68 | SPI_WRITE_REG /* Write ACC register */ 69 | 70 | } enWriteData; 71 | 72 | typedef enum { 73 | SPI_READ_ONE_REG = 1, /* Read one ACC register */ 74 | SPI_READ_TWO_REG /* Read two ACC registers */ 75 | 76 | } enRegsNum; 77 | 78 | 79 | /******************************************************************************* 80 | **************************** Internal definitions ****************************** 81 | ********************************************************************************/ 82 | 83 | /* Accelerometer write command */ 84 | #define COMM_WRITE 0x0A 85 | 86 | /* Accelerometer read command */ 87 | #define COMM_READ 0x0B 88 | 89 | /* Unused address */ 90 | #define ADDR_NOT_USE 0x00 91 | 92 | /* ADXL_CS_SEL pins */ 93 | #define ACC_PIN_CS1 1 /* Select pin 10 */ 94 | #define ACC_PIN_CS2 2 /* Select pin 8 */ 95 | 96 | /* ADXL_INT1_SEL pins */ 97 | #define INT1_ACC_PIN_A 3 /* Select INT1 */ 98 | #define INT1_ACC_PIN_B 4 /* Select INT1 */ 99 | 100 | /* ADXL_INT2_SEL pins */ 101 | #define INT2_ACC_PIN_A 5 /* Select INT1 */ 102 | #define INT2_ACC_PIN_B 6 /* Select INT1 */ 103 | 104 | 105 | 106 | /******************************************************************************* 107 | **************************** Functions declarations ***************************** 108 | ********************************************************************************/ 109 | int spi_write_then_read(adxl_spi_handle *spiTransfer, 110 | unsigned char *txbuf, 111 | unsigned n_tx, 112 | unsigned char *rxbuf, 113 | unsigned n_rx); 114 | 115 | 116 | /******************************************************************************* 117 | ******************Configuration parameters(set by the user)********************* 118 | ********************************************************************************/ 119 | /* Select ADXL372 CS pin based on jumper P10 setting. 120 | * Available values: 121 | * ACC_PIN_CS1 122 | * ACC_PIN_CS2 */ 123 | #define ADXL_CS_SEL ACC_PIN_CS1 124 | 125 | /* Select ADXL372 INT1 pin based on jumper P11 setting. 126 | * Available values: 127 | * INT1_ACC_PIN_A 128 | * INT1_ACC_PIN_B */ 129 | #define ADXL_INT1_SEL INT1_ACC_PIN_A 130 | 131 | /* Select ADXL372 INT2 pin based on jumper P12 setting. 132 | * Available values: 133 | * INT2_ACC_PIN_A 134 | * INT2_ACC_PIN_B */ 135 | #define ADXL_INT2_SEL INT2_ACC_PIN_A 136 | 137 | /*********************Pins configuration (not set by the user)*******************/ 138 | /*** ACC CS pin configuration ***/ 139 | #if(ADXL_CS_SEL == ACC_PIN_CS1) 140 | #define CS_PIN 10 141 | #elif(ADXL_CS_SEL == ACC_PIN_CS2) 142 | #define CS_PIN 8 143 | #endif 144 | 145 | /*** ACC INT pin configuration */ 146 | #if(ADXL_INT1_SEL == INT1_ACC_PIN_A) 147 | #define INT1_ACC_PIN 7 148 | #elif(ADXL_INT1_SEL == INT1_ACC_PIN_B) 149 | #define INT1_ACC_PIN 6 150 | #endif 151 | 152 | #if(ADXL_INT2_SEL == INT2_ACC_PIN_A) 153 | #define INT2_ACC_PIN 5 154 | #elif(ADXL_INT2_SEL == INT2_ACC_PIN_B) 155 | #define INT2_ACC_PIN 4 156 | #endif 157 | 158 | 159 | #ifdef __cplusplus 160 | } // extern "C" 161 | #endif 162 | 163 | #endif /* _COMMUNICATION_H_ */ 164 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0216_example/AD7791.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | AD7791.cpp - 3 | */ 4 | 5 | #include 6 | #include 7 | #include "AD7791.h" 8 | 9 | AD7791class AD7791; 10 | 11 | void AD7791class::AD7791_SPI_Configuration(void) 12 | { 13 | SPI.setBitOrder(MSBFIRST); // MSB to be sent first 14 | SPI.setDataMode(SPI_MODE3); // Set for clock rising edge, clock idles low 15 | SPI.setClockDivider(SPI_CLOCK_DIV128); // Set clock divider (optional) 16 | delay(100); 17 | } 18 | 19 | uint32_t AD7791class::readAd7791 (uint8_t ui8address) 20 | { 21 | uint8_t ui8AdcUpperCodes = 0; // Data register bits 23-16 22 | uint8_t ui8AdcMiddleCodes = 0; // Data register bits 15-8 23 | uint8_t ui8AdcLowerCodes = 0; // Data register bits 7-0 24 | uint32_t ui32AdcCodes = 0; 25 | 26 | if (ui8address == DATA_READ) 27 | { 28 | digitalWrite(AD7791_SS,LOW); 29 | SPI.transfer(ui8address); 30 | ui8AdcUpperCodes = SPI.transfer(0x00); // Data register bits 23-16 31 | ui8AdcMiddleCodes = SPI.transfer(0x00); // Data register bits 15-8 32 | ui8AdcLowerCodes = SPI.transfer(0x00); // Data register bits 7-0 33 | digitalWrite(AD7791_SS,HIGH); 34 | ui32AdcCodes = ((long)ui8AdcUpperCodes << 16) | ((long)ui8AdcMiddleCodes << 8) | ui8AdcLowerCodes; 35 | 36 | /*Serial.print("ADC Data Register Read : "); //Debug serial prints 37 | Serial.println(ui32AdcCodes,2); 38 | Serial.print("ADC Bits 23-16 : "); 39 | Serial.println(ui8AdcUpperCodes,2); 40 | Serial.print("ADC Bits 15-8 : "); 41 | Serial.println(ui8AdcMiddleCodes,2); 42 | Serial.print("ADC Bits 7-0 : "); 43 | Serial.println(ui8AdcLowerCodes,2);*/ 44 | } 45 | else 46 | { 47 | digitalWrite(AD7791_SS,LOW); 48 | SPI.transfer(ui8address); 49 | ui8AdcLowerCodes = SPI.transfer(0x00); // register read 50 | digitalWrite(AD7791_SS,HIGH); 51 | ui32AdcCodes = ((long)ui8AdcUpperCodes << 16) | ((long)ui8AdcMiddleCodes << 8) | ui8AdcLowerCodes; 52 | 53 | /*Serial.print("ADC Register Being Read:"); //Debug serial prints 54 | Serial.println(ui8address); 55 | Serial.print(" Reading Register Value :"); 56 | Serial.println(ui32AdcCodes);*/ 57 | } 58 | 59 | return ui32AdcCodes; 60 | } 61 | 62 | void AD7791class::writeAd7791 (uint8_t ui8address, uint8_t ui8value) 63 | { 64 | 65 | if (ui8address != RESET) 66 | { 67 | digitalWrite(AD7791_SS,LOW); 68 | SPI.transfer(ui8address); 69 | SPI.transfer(ui8value); 70 | digitalWrite(AD7791_SS,HIGH); 71 | //Serial.println("Write Command"); //Debug serial prints 72 | } 73 | else 74 | { 75 | digitalWrite(AD7791_SS,LOW); 76 | SPI.transfer(ui8value); 77 | SPI.transfer(ui8value); 78 | SPI.transfer(ui8value); 79 | SPI.transfer(ui8value); 80 | digitalWrite(AD7791_SS,HIGH); 81 | //Serial.println("Reset Command"); //Debug serial prints 82 | } 83 | 84 | /*Serial.print("ADC Register "); //Debug serial prints 85 | Serial.print(ui8address); 86 | Serial.println("Written"); 87 | Serial.print("With Register Value "); 88 | Serial.println(ui8value);*/ 89 | } -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0216_example/AD7791.h: -------------------------------------------------------------------------------- 1 | /* 2 | AD7791.h - 3 | */ 4 | #ifndef AD7791_h 5 | #define AD7791_h 6 | 7 | #include 8 | 9 | /*****************************************************************************/ 10 | /************************** ADC Address Definitions **************************/ 11 | /*****************************************************************************/ 12 | 13 | //ADC Write Commands 14 | #define MODE_WRITE 0x10 // Write to the Mode Register 15 | #define FILTER_WRITE 0x20 // Write to the Filter Register 16 | 17 | //ADC Read Commands 18 | #define STATUS_READ 0x08 // Read from the Status Register 19 | #define MODE_READ 0x18 // Read from the Mode Register 20 | #define FILTER_READ 0x28 // Read from the Filter Register 21 | #define DATA_READ 0x38 // Read from the Data Register 22 | 23 | #define RESET 0xFF // Resets the chip to default 24 | 25 | //Pins 26 | #define AD7791_SS 8 // AD7791 SPI chip select 27 | 28 | class AD7791class 29 | { 30 | public: 31 | void writeAd7791 (uint8_t ui8address, uint8_t ui8value); 32 | uint32_t readAd7791 (uint8_t ui8address); 33 | void AD7791_SPI_Configuration(void); 34 | private: 35 | 36 | }; 37 | 38 | extern AD7791class AD7791; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0216_example/CN0216_example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | CN0216_example.ino - Example code for CN0216 - Weigh Scale 3 | Created by Analog Devices Inc. - Circuits from the Lab, June 2015. 4 | */ 5 | 6 | #include 7 | #include 8 | #include "AD7791.h" 9 | 10 | // AD7790 Pin Assignme nts 11 | #define AD7791_SS 8 // value of the CS pin assignment 12 | 13 | // Weigh Scale Variables 14 | uint16_t ui16calibrationWeight = 1000; //value is in units (grams) 15 | 16 | // AD7791 variables 17 | uint32_t ui32Adcdata = 0; 18 | 19 | // Main program variables 20 | float fgramsPerCode = 0.0; 21 | float fWeight = 0.0; 22 | float fzeroScaleCalibration = 0.0; 23 | float ffullScaleCalibration = 0.0; 24 | 25 | void setup() { 26 | 27 | // open digital communication protocols 28 | Serial.begin(9600); 29 | SPI.begin(); 30 | 31 | // initialize pins 32 | pinMode(AD7791_SS,OUTPUT); //set CS pin 33 | digitalWrite(AD7791_SS,HIGH); //brings chip select high 34 | 35 | // initialize AD7791 36 | AD7791.AD7791_SPI_Configuration(); 37 | Ad7791INIT(); 38 | 39 | // calibrating the scale 40 | Serial.println("Zero Scale Calibration in process, please wait 15 seconds "); 41 | fzeroScaleCalibration = getCalibrationData(); 42 | Serial.println("Zero Scale Calibration Complete "); 43 | delay(1000); 44 | Serial.println("Please put Calibration Weight on the Scale "); 45 | delay(8000); 46 | Serial.println("Full Scale Calibration in process, please wait 15 seconds "); 47 | ffullScaleCalibration = getCalibrationData(); 48 | Serial.println("Full Scale Calibration Complete "); 49 | Serial.println("Calibration Process Complete "); 50 | delay(3000); 51 | } 52 | 53 | void loop() { 54 | 55 | do 56 | { 57 | ui32Adcdata = AD7791.readAd7791(STATUS_READ); 58 | //Serial.print("ADC Status Reg value = "); //Debug serial prints 59 | //Serial.println(ui32Adcdata); 60 | }while (ui32Adcdata & 0x80); 61 | 62 | ui32Adcdata = AD7791.readAd7791(DATA_READ); 63 | fgramsPerCode = ui16calibrationWeight / (ffullScaleCalibration - fzeroScaleCalibration); 64 | fWeight = (float(ui32Adcdata) - fzeroScaleCalibration) * fgramsPerCode; 65 | 66 | /*Serial.print("Zero Calibration Reading = "); //Debug serial prints 67 | Serial.println(fzeroScaleCalibration); //display zero scale calibration data 68 | Serial.print("Full Calibration Reading = "); 69 | Serial.println(ffullScaleCalibration); //display full scale calibration data 70 | Serial.print("ADC Data Register Code = "); 71 | Serial.println(ui32Adcdata); //display data register value 72 | Serial.print("Grams per code = "); 73 | Serial.println(fgramsPerCode); //display weight on scale*/ 74 | 75 | 76 | Serial.print("Weigh Scale Value = "); 77 | Serial.print(fWeight,2); //display weight on scale 78 | Serial.println(" grams"); 79 | delay (1000); 80 | } 81 | 82 | void Ad7791INIT(void) 83 | { 84 | AD7791.writeAd7791 (RESET, 0xFF); //Resets the part for initial use 85 | delay(1000); 86 | AD7791.writeAd7791 (MODE_WRITE, 0x00); //Mode register value (single conversion, +/- Vref input, unbuffered mode) 87 | AD7791.writeAd7791 (FILTER_WRITE, 0x07); // Filter register value (clock not divided down, 9.5 Hz update rate) 88 | } 89 | 90 | float getCalibrationData(void) 91 | { 92 | uint32_t ui32calibrationData = 0; 93 | uint32_t ui32status = 0; 94 | uint8_t x = 0; 95 | float fcalibration = 0.0; 96 | 97 | for (x = 0; x < 100; x++) 98 | { 99 | ui32status = 0; 100 | do 101 | { 102 | ui32status = AD7791.readAd7791(STATUS_READ); 103 | //Serial.print("ADC Status Reg value = "); //Debug serial prints 104 | //Serial.println(ui32Adcdata); 105 | }while (ui32status & 0x80); 106 | 107 | ui32calibrationData += AD7791.readAd7791(DATA_READ); 108 | delay(100); 109 | } 110 | fcalibration = ui32calibrationData/100.0; 111 | return fcalibration; 112 | } 113 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0357_example/AD5270.cpp: -------------------------------------------------------------------------------- 1 | /* AD5270.c 2 | * 3 | * Created on: May 27, 2015 4 | * Author: BBUSHEY 5 | */ 6 | 7 | #include 8 | #include 9 | #include "AD5270.h" 10 | 11 | AD5270class AD5270; 12 | 13 | void AD5270class::AD5270_SPI_Configuration(void) 14 | { 15 | SPI.setBitOrder(MSBFIRST); // MSB to be sent first 16 | SPI.setDataMode(SPI_MODE3); // Set for clock rising edge, clock idles low 17 | SPI.setClockDivider(SPI_CLOCK_DIV128); // Set clock divider (optional) 18 | delay(100); 19 | } 20 | 21 | void AD5270class::writeAd5270 (uint8_t ui8command, uint16_t ui16value) 22 | { 23 | uint8_t ui8DacUpperCodes = 0; // Data register read MSB 24 | uint8_t ui8DacLowerCodes = 0; // Data register read MSB 25 | uint16_t ui16DacCodes = 0; 26 | 27 | if (ui8command == 1) 28 | { 29 | ui16DacCodes = (ui8command << 10); 30 | ui16DacCodes = (ui16DacCodes | (ui16value)); 31 | ui8DacLowerCodes = ui16DacCodes & 0xFF; 32 | ui8DacUpperCodes = (ui16DacCodes >> 8) & 0xFF; 33 | } 34 | if (ui8command == 5 || ui8command == 7 || ui8command == 9) 35 | { 36 | ui8DacLowerCodes = ui16value & 0xFF; 37 | ui8DacUpperCodes = (ui8command << 2); 38 | } 39 | if (ui8command == 0xF0) //SDO High Z prep 40 | { 41 | ui8DacLowerCodes = ui16value & 0xFF; 42 | ui8DacUpperCodes = (ui16value >> 8) & 0xFF; 43 | } 44 | if (ui8command == 0x0F) // SDO High Z 45 | { 46 | ui8DacLowerCodes = ui16value & 0xFF; 47 | ui8DacUpperCodes = (ui16value >> 8) & 0xFF; 48 | } 49 | digitalWrite(AD5270_SS,LOW); 50 | SPI.transfer(ui8DacUpperCodes); 51 | SPI.transfer(ui8DacLowerCodes); 52 | digitalWrite(AD5270_SS,HIGH); 53 | 54 | /*Serial.print("Digipot Resistor Code = "); //Debug serial prints 55 | Serial.println(ui16DacCodes); 56 | Serial.print("Digipot Upper 8 Bits = "); 57 | Serial.println(ui8DacUpperCodes); 58 | Serial.print("Digipot Lower 8 Bits = "); 59 | Serial.println(ui8DacLowerCodes);*/ 60 | } 61 | 62 | uint16_t AD5270class::readAd5270 (uint8_t ui8command) 63 | { 64 | uint8_t ui8DacUpperCodes = 0; // Data register read MSB 65 | uint8_t ui8DacLowerCodes = 0; // Data register read LSB 66 | uint8_t ui8DacReadUpper = 0; 67 | uint8_t ui8DacReadLower = 0; 68 | uint16_t ui16DacRead = 0; 69 | 70 | if ((ui8command != 1) || (ui8command != 5) || (ui8command != 7) || (ui8command != 9)) 71 | { 72 | ui8DacLowerCodes = 0; 73 | ui8DacUpperCodes = (ui8command << 2); 74 | 75 | digitalWrite(AD5270_SS,LOW); 76 | SPI.transfer(ui8DacUpperCodes); 77 | SPI.transfer(ui8DacLowerCodes); 78 | ui8DacReadUpper = SPI.transfer(0x00); //Data register read MSB 79 | ui8DacReadLower = SPI.transfer(0x00); //Data register read LSB 80 | digitalWrite(AD5270_SS,HIGH); 81 | 82 | ui16DacRead = ((ui8DacReadUpper << 8) | ui8DacReadLower) & 0x03FF; 83 | 84 | } 85 | 86 | return ui16DacRead; 87 | } -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0357_example/AD5270.h: -------------------------------------------------------------------------------- 1 | /* 2 | AD5270.h 3 | */ 4 | #ifndef AD5270_h 5 | #define AD5270_h 6 | 7 | #include 8 | 9 | /*****************************************************************************/ 10 | /******************************** Definitions *******************************/ 11 | /*****************************************************************************/ 12 | 13 | //Commands 14 | #define WRITE_RDAC 0x1 // Write to the RDAC Register 15 | #define READ_RDAC 0x2 // Read from the RDAC Register 16 | #define STORE_50TP 0x3 // Write to the RDAC to memory 17 | #define SW_RST 0x4 // Software reset to last memory location 18 | #define READ_50TP_CONTENTS 0x5 // Read the last memory contents 19 | #define READ_50TP_ADDRESS 0x6 // Read the last memory address 20 | #define WRITE_CTRL_REG 0x7 // Write to the control Register 21 | #define READ_CTRL_REG 0x8 // Read from the control Register 22 | #define SW_SHUTDOWN 0x9 // Software shutdown (0) - Normal, (1) - Shutdown 23 | 24 | #define HI_Z_PREP 0xF0 // Get the SDO line ready for High Z 25 | #define HI_Z 0x0F // Puts AD5270 into High Z mode 26 | 27 | //Pins 28 | #define AD5270_SS 6 // AD5270 SPI chip select 29 | 30 | class AD5270class 31 | { 32 | public: 33 | void writeAd5270 (uint8_t ui8command, uint16_t ui16value); 34 | uint16_t readAd5270 (uint8_t ui8address); 35 | void AD5270_SPI_Configuration(void); 36 | private: 37 | 38 | }; 39 | 40 | extern AD5270class AD5270; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0357_example/AD7790.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | AD7790.cpp - 3 | */ 4 | 5 | #include 6 | #include 7 | #include "AD7790.h" 8 | 9 | AD7790class AD7790; 10 | 11 | void AD7790class::AD7790_SPI_Configuration(void) 12 | { 13 | SPI.setBitOrder(MSBFIRST); // MSB to be sent first 14 | SPI.setDataMode(SPI_MODE3); // Set for clock rising edge, clock idles low 15 | SPI.setClockDivider(SPI_CLOCK_DIV128); // Set clock divider (optional) 16 | delay(100); 17 | } 18 | 19 | uint16_t AD7790class::readAd7790 (uint8_t ui8address) 20 | { 21 | uint8_t ui8AdcUpperCodes = 0; // Data register read MSB 22 | uint8_t ui8AdcLowerCodes = 0; // Data register read LSB 23 | uint16_t ui16AdcCodes = 0; 24 | 25 | if (ui8address == DATA_READ) 26 | { 27 | digitalWrite(AD7790_SS,LOW); 28 | SPI.transfer(ui8address); 29 | ui8AdcUpperCodes = SPI.transfer(0x00); //Data register read MSB 30 | ui8AdcLowerCodes = SPI.transfer(0x00); //Data register read LSB 31 | digitalWrite(AD7790_SS,HIGH); 32 | ui16AdcCodes = ((long)ui8AdcUpperCodes << 8) | ui8AdcLowerCodes; 33 | 34 | /*Serial.print("ADC Data Register Read : "); //Debug serial prints 35 | Serial.println(ui16AdcCodes,2);*/ 36 | 37 | /*Serial.print("ADC Upper 8 Bits : "); //Debug serial prints 38 | Serial.println(ui8AdcUpperCodes,2); 39 | Serial.print("ADC Lower 8 Bits : "); 40 | Serial.println(ui8AdcLowerCodes,2);*/ 41 | } 42 | else 43 | { 44 | digitalWrite(AD7790_SS,LOW); 45 | SPI.transfer(ui8address); 46 | ui8AdcLowerCodes = SPI.transfer(0x00); // register read 47 | digitalWrite(AD7790_SS,HIGH); 48 | ui16AdcCodes = ((long)ui8AdcUpperCodes << 8) | ui8AdcLowerCodes; 49 | 50 | /*Serial.print("ADC Register Being Read: "); //Debug serial prints 51 | Serial.println(ui8address); 52 | Serial.print(" Reading Register Value : "); 53 | Serial.println(ui16AdcCodes);*/ 54 | } 55 | 56 | return ui16AdcCodes; 57 | } 58 | 59 | void AD7790class::writeAd7790 (uint8_t ui8address, uint8_t ui8value) 60 | { 61 | 62 | if (ui8address != RESET) 63 | { 64 | digitalWrite(AD7790_SS,LOW); 65 | SPI.transfer(ui8address); 66 | SPI.transfer(ui8value); 67 | digitalWrite(AD7790_SS,HIGH); 68 | //Serial.println("Write Command"); //Debug serial prints 69 | } 70 | else 71 | { 72 | digitalWrite(AD7790_SS,LOW); 73 | SPI.transfer(ui8value); 74 | SPI.transfer(ui8value); 75 | SPI.transfer(ui8value); 76 | SPI.transfer(ui8value); 77 | digitalWrite(AD7790_SS,HIGH); 78 | //Serial.println("Reset Command"); //Debug serial prints 79 | } 80 | 81 | /*Serial.print("ADC Register "); //Debug serial prints 82 | Serial.print(ui8address); 83 | Serial.println("Written"); 84 | Serial.print("With Register Value "); 85 | Serial.println(ui8value);*/ 86 | } 87 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0357_example/AD7790.h: -------------------------------------------------------------------------------- 1 | /* 2 | AD7790.h - 3 | */ 4 | #ifndef AD7790_h 5 | #define AD7790_h 6 | 7 | #include 8 | 9 | /*****************************************************************************/ 10 | /************************** ADC Address Definitions **************************/ 11 | /*****************************************************************************/ 12 | 13 | //ADC Write Commands 14 | #define MODE_WRITE 0x10 // Write to the Mode Register 15 | #define FILTER_WRITE 0x20 // Write to the Filter Register 16 | 17 | //ADC Read Commands 18 | #define STATUS_READ 0x08 // Read from the Status Register 19 | #define MODE_READ 0x18 // Read from the Mode Register 20 | #define FILTER_READ 0x28 // Read from the Filter Register 21 | #define DATA_READ 0x38 // Read from the Data Register 22 | 23 | #define RESET 0xFF // Resets the chip to default 24 | 25 | //Pins 26 | #define AD7790_SS 8 // AD7790 SPI chip select 27 | 28 | class AD7790class 29 | { 30 | public: 31 | void writeAd7790 (uint8_t ui8address, uint8_t ui8value); 32 | uint16_t readAd7790 (uint8_t ui8address); 33 | void AD7790_SPI_Configuration(void); 34 | private: 35 | 36 | }; 37 | 38 | extern AD7790class AD7790; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0357_example/CN0357_example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | CN0357_example.ino - Example code for CN0357 - Toxic Gas Detector 3 | Created by Analog Devices Inc. - Circuits from the Lab, December 2014. 4 | */ 5 | 6 | #include 7 | #include 8 | #include "AD5270.h" 9 | #include "AD7790.h" 10 | 11 | // AD5270 Pin Assignments 12 | #define AD5270_SS 6 // value of the CS pin assignment 13 | 14 | // AD7790 Pin Assignments 15 | #define AD7790_SS 8 // value of the CS pin assignment 16 | 17 | // Gas Sensor Variables 18 | uint16_t ui16sensorRange = 2000; //value is in units (PPM) 19 | uint16_t ui16sensitivity = 65; //value is in units (nA/ppm) 20 | 21 | // AD5270 variables 22 | float fResistorValue = 0; 23 | uint16_t ui16RdacWord = 0; 24 | 25 | // AD7790 variables 26 | uint16_t ui16Adcdata = 0; 27 | 28 | // Main variables 29 | float fAdcVoltage = 0; 30 | float fConcentration = 0; 31 | 32 | void setup() { 33 | 34 | // open digital communication protocols 35 | Serial.begin(9600); 36 | SPI.begin(); 37 | 38 | // initialize pins 39 | pinMode(AD5270_SS,OUTPUT); //set CS pin for sensor 40 | digitalWrite(AD5270_SS,HIGH); //brings chip select high 41 | 42 | pinMode(AD7790_SS,OUTPUT); //set CS pin for LCD 43 | digitalWrite(AD7790_SS,HIGH); //brings chip select high 44 | 45 | // initialize AD5270 46 | AD5270.AD5270_SPI_Configuration(); 47 | Ad5270INIT(); 48 | 49 | // set digipot value 50 | fResistorValue = calculateFeedbackResistor(); 51 | ui16RdacWord = setResistorValue(fResistorValue); 52 | AD5270.writeAd5270 (WRITE_RDAC, ui16RdacWord); 53 | AD5270.writeAd5270 (HI_Z_PREP, 0x8001); // Putting Rheostat into high Z mode on SDO line 54 | AD5270.writeAd5270 (HI_Z, 0x0000); 55 | Serial.print("Calculated Digitpot Value = "); 56 | Serial.println(fResistorValue); 57 | Serial.print("Actual Digitpot Value = "); 58 | Serial.println(ui16RdacWord); 59 | 60 | // initialize AD7790 61 | AD7790.AD7790_SPI_Configuration(); 62 | Ad7790INIT(); 63 | } 64 | 65 | void loop() { 66 | 67 | do 68 | { 69 | ui16Adcdata = AD7790.readAd7790(STATUS_READ); 70 | Serial.print("ADC Status Reg value = "); 71 | Serial.println(ui16Adcdata); 72 | }while (ui16Adcdata & 0x80); 73 | 74 | ui16Adcdata = AD7790.readAd7790(DATA_READ); 75 | fAdcVoltage = ((ui16Adcdata / pow(2,15))-1)*1.2; // Formula for input voltage using bipolar configuration 76 | fConcentration = (abs(fAdcVoltage)/ (ui16RdacWord*(20000/1024))) / (ui16sensitivity*pow(10,-9)); 77 | Serial.print("ADC Data Reg value = "); 78 | Serial.println(ui16Adcdata); 79 | Serial.print("Sensor Voltage value = "); 80 | Serial.println(fAdcVoltage); 81 | 82 | Serial.print("Carbon Monoxide (CO) concentration = "); 83 | Serial.print(fConcentration,2); //display gas concentration 84 | Serial.println(" PPM"); 85 | delay (1000); 86 | } 87 | 88 | void Ad7790INIT(void) 89 | { 90 | AD7790.writeAd7790 (RESET, 0xFF); //Resets the part for initial use 91 | delay(1000); 92 | AD7790.writeAd7790 (MODE_WRITE, 0x00); //Mode register value (single conversion, +/- Vref input, unbuffered mode) 93 | AD7790.writeAd7790 (FILTER_WRITE, 0x07); // Filter register value (clock not divided down, 9.5 Hz update rate) 94 | } 95 | 96 | void Ad5270INIT(void) 97 | { 98 | AD5270.writeAd5270 (WRITE_CTRL_REG, 0x02); //Enable RDAC writes 99 | } 100 | 101 | float calculateFeedbackResistor(void) 102 | { 103 | float fFeedback = 0; 104 | fFeedback = 1.2 / (ui16sensorRange * ui16sensitivity * pow(10,-9)); //1.2 is the Vref of the circuit 105 | return fFeedback; 106 | } 107 | 108 | uint16_t setResistorValue(float resistor) 109 | { 110 | uint16_t ui16RdacCode = 0; 111 | ui16RdacCode = int(resistor / (20000/1024)); 112 | return ui16RdacCode; 113 | } 114 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0391_example/CN0391.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright 2016(c) Analog Devices, Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * - Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * - Neither the name of Analog Devices, Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * - The use of this software may or may not infringe the patent rights 18 | * of one or more patent holders. This license does not release you 19 | * from the requirement that you obtain separate licenses from these 20 | * patent holders to use this software. 21 | * - Use of the software either in source or binary form, must be run 22 | * on or directly connected to an Analog Devices Inc. component. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ********************************************************************************/ 36 | #ifndef _CN0391_H_ 37 | #define _CN0391_H_ 38 | 39 | #include "AD7124.h" 40 | #include "PROGMEM_readAnything.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | typedef enum 47 | { 48 | CHANNEL_P1 = 0, 49 | CHANNEL_P2, 50 | CHANNEL_P3, 51 | CHANNEL_P4 52 | }channel_t; 53 | 54 | typedef enum 55 | { 56 | ERR_UNDER_RANGE = 1, 57 | ERR_OVER_RANGE, 58 | NO_ERR 59 | 60 | }error_code; 61 | 62 | 63 | int32_t CN0391_read_channel(int ch); 64 | 65 | float CN0391_data_to_voltage(int32_t data, uint8_t channel); 66 | float CN0391_data_to_resistance(int32_t data); 67 | 68 | void CN0391_calc_rtd_temperature(channel_t ch, float *temp); 69 | void CN0391_calc_th_temperature(channel_t ch, float cjTemp, float *buffer); 70 | 71 | void CN0391_enable_channel(int channel); 72 | void CN0391_disable_channel(int channel); 73 | void CN0391_enable_current_source(int current_source_channel); 74 | void CN0391_start_single_conversion(); 75 | 76 | void CN0391_reset(); 77 | void CN0391_setup(); 78 | void CN0391_init(); 79 | 80 | void CN0391_calibration(uint8_t channel); 81 | void CN0391_read_reg(void); 82 | void CN0391_set_calibration_mode(uint16_t mode); 83 | void CN0391_set_power_mode(int mode); 84 | 85 | void CN0391_set_data(void); 86 | void CN0391_display_data(void); 87 | 88 | 89 | #define YES 1 90 | #define NO 0 91 | 92 | #define R5 1600.0 //ohmi 93 | #define I_EXT 0.75 //mA 94 | 95 | #define VREF_EXT (R5*I_EXT) //mV 96 | #define VREF_INT 2500.0 //mV 97 | 98 | #define _2_23 8388608.0 99 | 100 | #define RTD_CHANNEL 0 101 | 102 | #define TH_CHANNEL 1 103 | 104 | #define GAIN_RTD 1 //GAIN1 105 | #define GAIN_TH 32 //GAIN32 106 | 107 | 108 | #define POLY_CALC(retVal, inVal, coeff_array) \ 109 | { \ 110 | float expVal = 1.0f; \ 111 | const float* coeff = coeff_array; \ 112 | retVal = 0.0f; \ 113 | while(*coeff != 1.0f)\ 114 | { \ 115 | retVal += *coeff * expVal; \ 116 | expVal *= inVal; \ 117 | coeff++; \ 118 | }\ 119 | } 120 | 121 | #define USE_RTD_CALIBRATION YES // Set YES to enable calibration on RTD channel, otherwise set to NO 122 | #define USE_TH_CALIBRATION YES // Set YES to enable calibration on TC channel, otherwise set to NO 123 | 124 | #define DISPLAY_REFRESH (1000) //ms 125 | 126 | #define TC_OFFSET_VOLTAGE 0.00 // mV compensation for system offset 127 | 128 | #ifdef __cplusplus 129 | } 130 | #endif // __cplusplus 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0391_example/CN0391_example.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "CN0391.h" 3 | #include "Communication.h" 4 | 5 | void setup() { 6 | Serial.begin(9600); 7 | SPI.begin(); 8 | SPI.setDataMode(SPI_MODE3); //CPHA = CPOL = 1 MODE = 3 9 | delay(1000); 10 | 11 | pinMode(CS_PIN, OUTPUT); 12 | 13 | CN0391_init(); 14 | 15 | #if(USE_RTD_CALIBRATION == YES) 16 | CN0391_calibration(RTD_CHANNEL); 17 | Serial.println(F("RTD channel calibration completed!")); 18 | #else 19 | Serial.println(F("Calibration for RTD channel is disabled.")); 20 | #endif 21 | 22 | #if(USE_TH_CALIBRATION == YES) 23 | CN0391_calibration(TH_CHANNEL); 24 | Serial.println(F("TC channel calibration completed!")); 25 | #else 26 | Serial.println(F("Calibration for TC channel is disabled.")); 27 | #endif 28 | 29 | } 30 | 31 | void loop() { 32 | 33 | delay(DISPLAY_REFRESH); 34 | CN0391_set_data(); 35 | Serial.println("test"); 36 | CN0391_display_data(); 37 | } 38 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0391_example/Communication.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Communication.cpp 3 | * @brief Communication file 4 | * @author Analog Devices Inc. 5 | * 6 | ******************************************************************************** 7 | * Copyright 2016(c) Analog Devices, Inc. 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * - Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * - Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * - Neither the name of Analog Devices, Inc. nor the names of its 20 | * contributors may be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * - The use of this software may or may not infringe the patent rights 23 | * of one or more patent holders. This license does not release you 24 | * from the requirement that you obtain separate licenses from these 25 | * patent holders to use this software. 26 | * - Use of the software either in source or binary form, must be run 27 | * on or directly connected to an Analog Devices Inc. component. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 30 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 31 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 32 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 33 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 35 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 36 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 37 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | ********************************************************************************/ 41 | 42 | #include "Communication.h" 43 | 44 | uint8_t convFlag = 0, readConv; 45 | 46 | 47 | void SPI_Write(unsigned char slaveDeviceId, unsigned char* data, unsigned char bytesNumber) 48 | { 49 | 50 | byte count; 51 | 52 | if(slaveDeviceId == 0) 53 | digitalWrite(CS_PIN, LOW); 54 | 55 | for(count = 0;count < bytesNumber;count++) 56 | { 57 | SPI.transfer(data[count]); // write instruction 58 | } 59 | 60 | if(slaveDeviceId == 0) 61 | digitalWrite(CS_PIN, HIGH); 62 | } 63 | 64 | /***************************************************************************//** 65 | * @brief Reads data from SPI. 66 | * 67 | * @param data - As an input parameter, data represents the write buffer: 68 | * - first byte is the chip select number; 69 | * - from the second byte onwards are located data bytes to write. 70 | * As an output parameter, data represents the read buffer: 71 | * - from the first byte onwards are located the read data bytes. 72 | * @param bytesNumber - Number of bytes to write. 73 | * 74 | * @return Number of written bytes. 75 | *******************************************************************************/ 76 | void SPI_Read(unsigned char slaveDeviceId, unsigned char* data, unsigned char bytesNumber) 77 | { 78 | unsigned char writeData[4] = {0, 0, 0, 0}; 79 | unsigned char count = 0; 80 | uint16_t ui16fifo_status; 81 | 82 | ui16fifo_status = ((bytesNumber) << 8); /* Set FIFO status correct value */ 83 | 84 | for(count = 0;count < bytesNumber;count++) 85 | { 86 | if(count == 0) 87 | writeData[count] = data[count]; 88 | else 89 | writeData[count] = 0xAA; /* dummy value */ 90 | } 91 | 92 | if(slaveDeviceId == 0) 93 | digitalWrite(CS_PIN, LOW); 94 | 95 | for(count = 0;count < bytesNumber;count++) 96 | { 97 | data[count] = SPI.transfer(writeData[count]); 98 | } 99 | 100 | if(slaveDeviceId == 0) 101 | digitalWrite(CS_PIN, HIGH); 102 | } 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0391_example/Communication.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright 2016(c) Analog Devices, Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * - Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * - Neither the name of Analog Devices, Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * - The use of this software may or may not infringe the patent rights 18 | * of one or more patent holders. This license does not release you 19 | * from the requirement that you obtain separate licenses from these 20 | * patent holders to use this software. 21 | * - Use of the software either in source or binary form, must be run 22 | * on or directly connected to an Analog Devices Inc. component. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ********************************************************************************/ 36 | 37 | #ifndef _COMMUNICATION_H 38 | #define _COMMUNICATION_H 39 | 40 | #include 41 | #include "Arduino.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | /********************************* Internal defines ****************************/ 47 | //* CSAD7798 - output */ 48 | #define CS_PIN 10 49 | 50 | 51 | extern uint8_t convFlag; 52 | 53 | /****************************** Internal types *********************************/ 54 | 55 | 56 | 57 | void SPI_Write(unsigned char slaveDeviceId, unsigned char* data, unsigned char bytesNumber); 58 | void SPI_Read(unsigned char slaveDeviceId, unsigned char* data, unsigned char bytesNumber); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif // __cplusplus 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0391_example/PROGMEM_readAnything.h: -------------------------------------------------------------------------------- 1 | #include // for type definitions 2 | 3 | template void PROGMEM_readAnything (const T * sce, T& dest) 4 | { 5 | memcpy_P (&dest, sce, sizeof (T)); 6 | } 7 | 8 | template T PROGMEM_getAnything (const T * sce) 9 | { 10 | static T temp; 11 | memcpy_P (&temp, sce, sizeof (T)); 12 | return temp; 13 | } -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0391_example/RTD.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright 2016(c) Analog Devices, Inc. 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * - Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * - Neither the name of Analog Devices, Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * - The use of this software may or may not infringe the patent rights 18 | * of one or more patent holders. This license does not release you 19 | * from the requirement that you obtain separate licenses from these 20 | * patent holders to use this software. 21 | * - Use of the software either in source or binary form, must be run 22 | * on or directly connected to an Analog Devices Inc. component. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ********************************************************************************/ 36 | 37 | #ifndef RTD_H_ 38 | #define RTD_H_ 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #define R0 1000.0 45 | 46 | #define COEFF_A 3.9083e-3f 47 | #define COEFF_B -5.775e-7f 48 | #define COEFF_A_A (COEFF_A*COEFF_A) 49 | #define COEFF_4B_R0 (4*COEFF_B/R0) 50 | #define COEFF_2B (2*COEFF_B) 51 | 52 | const float cjPolyCoeff[7] = 53 | { 54 | -242.02f, 2.2228f, 0.00259f, -0.00000483f, -0.0000000282f, 0.000000000152f, 1.0f 55 | }; 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif // __cplusplus 60 | 61 | #endif /* RTD_H_ */ 62 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0395_example/AD7988.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ***************************************************************************** 3 | @file: AD7988.c 4 | @brief: 5 | @version: $Revision$ 6 | @date: $Date$ 7 | ----------------------------------------------------------------------------- 8 | 9 | Copyright (c) 2018 Analog Devices, Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | - Modified versions of the software must be conspicuously marked as such. 21 | - This software is licensed solely and exclusively for use with processors 22 | manufactured by or for Analog Devices, Inc. 23 | - This software may not be combined or merged with other code in any manner 24 | that would cause the software to become subject to terms and conditions 25 | which differ from those listed here. 26 | - Neither the name of Analog Devices, Inc. nor the names of its 27 | contributors may be used to endorse or promote products derived 28 | from this software without specific prior written permission. 29 | - The use of this software may or may not infringe the patent rights of one 30 | or more patent holders. This license does not release you from the 31 | requirement that you obtain separate licenses from these patent holders 32 | to use this software. 33 | 34 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY 35 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 36 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 37 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES 39 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL 40 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 41 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | 46 | *****************************************************************************/ 47 | 48 | /***************************** Include Files **********************************/ 49 | #include 50 | #include 51 | 52 | #include 53 | #include "AD7988.h" 54 | #include "Communication.h" 55 | 56 | /************************* Functions Definitions ******************************/ 57 | 58 | /** 59 | @brief Initializes the AD7988 60 | 61 | @param None. 62 | 63 | @return None 64 | **/ 65 | void AD7988_Init(void) 66 | { 67 | pinMode(IN1ADG884_PIN, OUTPUT); 68 | pinMode(A0ADG758_PIN, OUTPUT); 69 | pinMode(A1ADG758_PIN, OUTPUT); 70 | pinMode(A2ADG758_PIN, OUTPUT); 71 | pinMode(IO6ADG758_PIN, OUTPUT); 72 | } 73 | 74 | /** 75 | @brief Selects the desired gain resistor R1 to R5 76 | 77 | @param mode - desired mode of operation 78 | 79 | @return None 80 | **/ 81 | void AD7988_SensorRangeSelect(enAD7988OpMode mode) 82 | { 83 | uint8_t ui8A0Pin, ui8A1Pin, ui8A2Pin; 84 | 85 | ui8A0Pin = (mode & 0x1) >> 0; 86 | ui8A1Pin = (mode & 0x2) >> 1; 87 | ui8A2Pin = (mode & 0x4) >> 2; 88 | 89 | if (ui8A0Pin) 90 | digitalWrite(A0ADG758_PIN, HIGH); 91 | else 92 | digitalWrite(A0ADG758_PIN, LOW); 93 | 94 | if (ui8A1Pin) 95 | digitalWrite(A1ADG758_PIN, HIGH); 96 | else 97 | digitalWrite(A1ADG758_PIN, LOW); 98 | 99 | if (ui8A2Pin) 100 | digitalWrite(A2ADG758_PIN, HIGH); 101 | else 102 | digitalWrite(A2ADG758_PIN, LOW); 103 | } 104 | 105 | /** 106 | @brief Selects the desired mode of operation by enabling or disabling the power on the correct pins 107 | 108 | @param mode - desired mode of operation 109 | 110 | @return None 111 | **/ 112 | void AD7988_SetOperationMode(enAD7988OpMode mode) 113 | { 114 | if (mode == AD7988_RH_MODE) { 115 | digitalWrite(IN1ADG884_PIN, HIGH); // set IN1 to logic 1 116 | digitalWrite(IO6ADG758_PIN, LOW); // disable power on IO6 117 | } 118 | else { 119 | digitalWrite(IN1ADG884_PIN, LOW); // reset IN1 120 | digitalWrite(IO6ADG758_PIN, HIGH); // enable master power on IO6 121 | AD7988_SensorRangeSelect(mode); 122 | } 123 | delay(1); 124 | } 125 | 126 | /** 127 | @brief Reads AD7988 data from the SPI 128 | 129 | @param data - read data. 130 | 131 | @return None 132 | **/ 133 | void AD7988_ReadData(uint16_t *data) 134 | { 135 | *data = SPI_Read(); 136 | } 137 | 138 | /** 139 | @brief Converts the read ADC data to the corresponding voltage 140 | 141 | @param ui16Adcdata - ADC data read 142 | 143 | @return fAdcVoltage - voltage according to the input data 144 | **/ 145 | float AD7988_DataToVoltage(uint16_t ui16Adcdata) 146 | { 147 | float fAdcVoltage = 0; 148 | 149 | fAdcVoltage = ((float)ui16Adcdata / (pow(2, 16) - 1) ) * ADC_VREF; 150 | 151 | return fAdcVoltage; 152 | } 153 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0395_example/AD7988.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ***************************************************************************** 3 | @file: AD7988.h 4 | @brief: 5 | @version: $Revision$ 6 | @date: $Date$ 7 | ----------------------------------------------------------------------------- 8 | 9 | Copyright (c) 2017 Analog Devices, Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | - Modified versions of the software must be conspicuously marked as such. 21 | - This software is licensed solely and exclusively for use with processors 22 | manufactured by or for Analog Devices, Inc. 23 | - This software may not be combined or merged with other code in any manner 24 | that would cause the software to become subject to terms and conditions 25 | which differ from those listed here. 26 | - Neither the name of Analog Devices, Inc. nor the names of its 27 | contributors may be used to endorse or promote products derived 28 | from this software without specific prior written permission. 29 | - The use of this software may or may not infringe the patent rights of one 30 | or more patent holders. This license does not release you from the 31 | requirement that you obtain separate licenses from these patent holders 32 | to use this software. 33 | 34 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY 35 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 36 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 37 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES 39 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL 40 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 41 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | 46 | *****************************************************************************/ 47 | 48 | #ifndef AD7988_H_ 49 | #define AD7988_H_ 50 | 51 | #include 52 | 53 | /********************************* Global data ********************************/ 54 | #define ADC_VREF 4.096 // V 55 | #define ADC_CODE_CALIBRATION (((ADN8810_IFS * 71.5) / 1000) / ADC_VREF * 65535) 56 | 57 | /************************** Variable Definitions ******************************/ 58 | typedef enum { 59 | AD7988_DISABLE, 60 | AD7988_ENABLE 61 | } enAD7988Status; 62 | 63 | typedef enum { /* A2, A1, A0 */ 64 | AD7988_RS_RAMGE_1, /* 0, 0, 0 */ 65 | AD7988_RS_RAMGE_2, /* 0, 0, 1 */ 66 | AD7988_RS_RAMGE_3, /* 0, 1, 0 */ 67 | AD7988_RS_RAMGE_4, /* 0, 1, 1 */ 68 | AD7988_RS_RAMGE_5, /* 1, 0, 0 */ 69 | AD7988_RH_MODE 70 | } enAD7988OpMode; 71 | 72 | /******************************************************************************/ 73 | /* Functions Prototypes */ 74 | /******************************************************************************/ 75 | /* Initializes the AD7988 */ 76 | void AD7988_Init(void); 77 | /* Selects the desired gain resistor R1 to R5 */ 78 | void AD7988_SensorRangeSelect(enAD7988OpMode mode); 79 | /* Selects the desired mode of operation by enabling or disabling the power on the correct pins */ 80 | void AD7988_SetOperationMode(enAD7988OpMode mode); 81 | /* Reads AD7988 data from the SPI */ 82 | void AD7988_ReadData(uint16_t *data); 83 | /* Converts the read ADC data to the corresponding voltage */ 84 | float AD7988_DataToVoltage(uint16_t ui16Adcdata); 85 | 86 | #endif //AD7988_H_ 87 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0395_example/ADN8810.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ***************************************************************************** 3 | @file: ADN8810.h 4 | @brief: 5 | @version: $Revision$ 6 | @date: $Date$ 7 | ----------------------------------------------------------------------------- 8 | 9 | Copyright (c) 2017 Analog Devices, Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | - Modified versions of the software must be conspicuously marked as such. 21 | - This software is licensed solely and exclusively for use with processors 22 | manufactured by or for Analog Devices, Inc. 23 | - This software may not be combined or merged with other code in any manner 24 | that would cause the software to become subject to terms and conditions 25 | which differ from those listed here. 26 | - Neither the name of Analog Devices, Inc. nor the names of its 27 | contributors may be used to endorse or promote products derived 28 | from this software without specific prior written permission. 29 | - The use of this software may or may not infringe the patent rights of one 30 | or more patent holders. This license does not release you from the 31 | requirement that you obtain separate licenses from these patent holders 32 | to use this software. 33 | 34 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY 35 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 36 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 37 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES 39 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL 40 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 41 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | 46 | *****************************************************************************/ 47 | 48 | #ifndef ADN8810_H_ 49 | #define ADN8810_H_ 50 | 51 | #include 52 | #include "CN0395.h" 53 | 54 | /*****************************************************************************/ 55 | /******************************** Definitions *******************************/ 56 | /*****************************************************************************/ 57 | // Comands 58 | 59 | #define ADN8810_ADR 0x07 // Hard wired device address 60 | #define ADN8810_RSN 41.2 // Ohms 61 | #define ADN8810_CURRENT_1LSB (1 / (10 * ADN8810_RSN)) // For RSN = 41.2ohms, 1 LSB resolution = 2.4uA 62 | #define ADN8810_IFS ((ADC_VREF / ADN8810_RSN) * 100) // Full Scale current, for RSN = 41.2ohms, IFS = 9.94mA 63 | #define ADN8810_FULL_SCALE_OUT 4095 64 | #define ADN8810_HALF_SCALE_OUT 2048 65 | #define ADN8810_QUARTER_SCALE_OUT 1024 66 | 67 | typedef enum { 68 | ADN8810_DISABLE, 69 | ADN8810_ENABLE 70 | } enADN8810Status; 71 | 72 | 73 | /******************************************************************************/ 74 | /* Functions Prototypes */ 75 | /******************************************************************************/ 76 | 77 | void ADN8810_Init(void); 78 | int ADN8810_SetOutput(float fDesiredOutputCurrent, sMeasurementVariables *sMeasVar); 79 | void ADN8810_Reset(void); 80 | void ADN8810_MasterPower(enADN8810Status status); 81 | uint32_t ADN8810_FactoryCalibration(void); 82 | uint16_t ADN8810_CurrentToDataInputCalc(float fCurrent); 83 | 84 | #endif // ADN8810_H_ 85 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0395_example/CN0395.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ***************************************************************************** 3 | @file: CN0395.h 4 | @brief: 5 | @version: $Revision$ 6 | @date: $Date$ 7 | ----------------------------------------------------------------------------- 8 | 9 | Copyright (c) 2017 Analog Devices, Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | - Modified versions of the software must be conspicuously marked as such. 21 | - This software is licensed solely and exclusively for use with processors 22 | manufactured by or for Analog Devices, Inc. 23 | - This software may not be combined or merged with other code in any manner 24 | that would cause the software to become subject to terms and conditions 25 | which differ from those listed here. 26 | - Neither the name of Analog Devices, Inc. nor the names of its 27 | contributors may be used to endorse or promote products derived 28 | from this software without specific prior written permission. 29 | - The use of this software may or may not infringe the patent rights of one 30 | or more patent holders. This license does not release you from the 31 | requirement that you obtain separate licenses from these patent holders 32 | to use this software. 33 | 34 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY 35 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 36 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 37 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES 39 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL 40 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 41 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | 46 | *****************************************************************************/ 47 | 48 | #ifndef CN0395_H_ 49 | #define CN0395_H_ 50 | 51 | 52 | #include 53 | /********************************* Global data ********************************/ 54 | #define ALPHA 0.003074 55 | 56 | /****************************** Internal types *********************************/ 57 | typedef struct { 58 | float fAmbientHeaterTemp; // T_A 59 | float fAmbientHeaterHum; // HUM 60 | float fAmbientHeaterRes; // RH_A 61 | float fHeaterVoltage; // VH 62 | float fHeaterCurrent; // IH 63 | float fHeaterRes; // RH 64 | float fHeaterTemp; // TH 65 | float fHeaterPower; // PH 66 | float fSensorRes; // RS 67 | float fSensorResCleanAir; // Ro 68 | float fSensorVoltage; // VS 69 | float fPPM; // PPM 70 | uint32_t ui32GainResistance; // RG 71 | uint16_t ui16LastAdcDataRead; 72 | uint8_t OpMode; 73 | float K1; // Gain correction factor 74 | } sMeasurementVariables; 75 | 76 | typedef enum { 77 | VOLTAGE, 78 | RESISTANCE 79 | } enCN0395ErrCorrection; 80 | 81 | typedef void (*cmdFunc)(uint8_t *, sMeasurementVariables *); 82 | 83 | /******************************************************************************/ 84 | /* Functions Prototypes */ 85 | /******************************************************************************/ 86 | /* Command line process function */ 87 | void CN0395_CmdProcess(sMeasurementVariables *sMeasVar); 88 | /* Find available commands */ 89 | cmdFunc CN0395_FindCommand(char *cmd); 90 | /* Command Prompt function */ 91 | int CN0395_CmdPrompt(void); 92 | /* Function which performs the power up routine */ 93 | void CN0395_PowerOn(sMeasurementVariables *sMeas); 94 | /* Routine for measuring sensor resistance RS */ 95 | float CN0395_MeasureSensorResistance(sMeasurementVariables *sMeasVar); 96 | /* Display measured and calculation data (on UART) */ 97 | void CN0395_DisplayData(sMeasurementVariables *sMeasVar); 98 | /* Display info for command */ 99 | void CN0395_CmdHelp(uint8_t *args, sMeasurementVariables *sMeasVar); 100 | /* Run the calibration routine and display the calibration correction factor */ 101 | void CN0395_CmdCalibration(uint8_t *args, sMeasurementVariables *sMeasVar); 102 | /* Update operation mode according to operation command: RH, RS or RO */ 103 | void CN0395_CmdSetOpMode(uint8_t *args, sMeasurementVariables *sMeasVar); 104 | /* Routine for Setting Heater Current to Constant Current IH */ 105 | void CN0395_CmdSetHeaterCurrent(uint8_t *args, sMeasurementVariables *sMeasVar); 106 | /* Function for command which calls the routine for setting heater voltage */ 107 | void CN0395_CmdSetHeaterVoltage(uint8_t *args, sMeasurementVariables *sMeasVar); 108 | /* Function for command which calls the routine for setting heater resistance */ 109 | void CN0395_CmdSetHeaterRes(uint8_t *args, sMeasurementVariables *sMeasVar); 110 | /* Routine for Setting Heater Temperature to Constant Temperature TH */ 111 | void CN0395_CmdSetHeaterTemp(uint8_t *args, sMeasurementVariables *sMeasVar); 112 | /* Read ADC data */ 113 | uint16_t CN0395_ReadAdc(sMeasurementVariables *sMeasVar); 114 | /* Calculate RS value */ 115 | float CN0395_CalculateRs(uint16_t ui16Adcdata, uint32_t ui32RgValue); 116 | /* Calculate gas concentration in PPM */ 117 | float CN0395_CalculatePPM(sMeasurementVariables *sMeasVar); 118 | /* Finds the next command line argument */ 119 | uint8_t *CN0395_FindArgv(uint8_t *args); 120 | /* Separates a command line argument */ 121 | void CN0395_GetArgv(char *dst, uint8_t *args); 122 | void CN0395_ComputeHeaterRPT(sMeasurementVariables *sMeasVar); 123 | 124 | #endif 125 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0395_example/CN0395_example.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "AD7988.h" 5 | #include "CN0395.h" 6 | #include "ADN8810.h" 7 | #include "SHT30.h" 8 | #include "Communication.h" 9 | 10 | static uint8_t count = 0; 11 | sMeasurementVariables *sMeasVar; 12 | extern uint8_t ui8ContinousRsMeasurement; 13 | 14 | void setup() { 15 | Serial.begin(9600); 16 | /* Initialize SPI */ 17 | SPI.begin(); 18 | SPI.setDataMode(SPI_MODE0); //CPHA = CPOL = 0 MODE = 0 19 | 20 | pinMode(CSAD7988_PIN, OUTPUT); 21 | pinMode(CSADN8810_PIN, OUTPUT); 22 | digitalWrite(CSAD7988_PIN, HIGH); 23 | digitalWrite(CSADN8810_PIN, HIGH); 24 | 25 | /* Initialize I2C */ 26 | Wire.begin(); 27 | 28 | while (!Serial) { 29 | ; // wait for serial port to connect. Needed for native USB port only 30 | } 31 | 32 | sMeasVar = (sMeasurementVariables *)malloc(sizeof(*sMeasVar)); 33 | 34 | AD7988_Init(); // Initialize ADC 35 | 36 | CN0395_PowerOn(sMeasVar); 37 | } 38 | 39 | void loop() { 40 | unsigned short status; 41 | 42 | if (uart_cmd == UART_TRUE) { /* condition becomes true when the system receives as Carriage Return(CR) command from the UART */ 43 | if (count == 0) { // Check first is pressed after reset 44 | Serial.print("\tWelcome to CN0395 application!\n"); 45 | Serial.print("\r\nDefault at power up: \n"); 46 | Serial.print("\r\n* RS operation mode\n"); 47 | Serial.print("\r* IH = 8 mA (Constant current)\n"); 48 | Serial.print("\r* Ro = "); Serial.print(sMeasVar->fSensorResCleanAir); Serial.print(" [Ohms] (Sensor resistance in clean air)\n"); 49 | Serial.print("\r\n>>Type in to see available commands\n"); 50 | 51 | count++; 52 | } 53 | else { // At a second press, do the processing 54 | CN0395_CmdProcess(sMeasVar); 55 | } 56 | uart_cmd = UART_FALSE; 57 | CN0395_CmdPrompt(); 58 | } 59 | if (ui8ContinousRsMeasurement) { 60 | 61 | uint16_t ui16AdcData = 0; 62 | float fHeaterVoltage = 0; 63 | 64 | AD7988_SetOperationMode(AD7988_RH_MODE); 65 | ui16AdcData = CN0395_ReadAdc(sMeasVar); 66 | fHeaterVoltage = AD7988_DataToVoltage(ui16AdcData); 67 | delay(50); // delay 50ms 68 | 69 | sMeasVar->fHeaterVoltage = fHeaterVoltage; 70 | CN0395_ComputeHeaterRPT(sMeasVar); // Compute RH, PH and TH 71 | 72 | CN0395_MeasureSensorResistance(sMeasVar); 73 | delay(998); 74 | CN0395_DisplayData(sMeasVar); 75 | } 76 | } 77 | 78 | void serialEvent() { 79 | char c; 80 | 81 | while (Serial.available() > 0) { 82 | c = Serial.read(); /* Read character from UART */ 83 | switch (c) { 84 | case _BS: 85 | if (uart_rcnt) { 86 | uart_rcnt--; 87 | uart_rx_buffer[uart_rcnt] = 0; 88 | Serial.write(c); 89 | Serial.write(' '); 90 | Serial.write(c); 91 | } 92 | break; 93 | case _CR: /* Check if read character is ENTER */ 94 | uart_cmd = UART_TRUE; /* Set flag */ 95 | break; 96 | 97 | default: 98 | uart_rx_buffer[uart_rcnt++] = c; 99 | 100 | if (uart_rcnt == UART_RX_BUFFER_SIZE) { 101 | uart_rcnt--; 102 | } 103 | } 104 | 105 | uart_rx_buffer[uart_rcnt] = '\0'; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0395_example/Communication.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ***************************************************************************** 3 | @file: Communication.c 4 | @brief: 5 | @version: $Revision$ 6 | @date: $Date$ 7 | ----------------------------------------------------------------------------- 8 | 9 | Copyright (c) 2015-2018 Analog Devices, Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | - Modified versions of the software must be conspicuously marked as such. 21 | - This software is licensed solely and exclusively for use with processors 22 | manufactured by or for Analog Devices, Inc. 23 | - This software may not be combined or merged with other code in any manner 24 | that would cause the software to become subject to terms and conditions 25 | which differ from those listed here. 26 | - Neither the name of Analog Devices, Inc. nor the names of its 27 | contributors may be used to endorse or promote products derived 28 | from this software without specific prior written permission. 29 | - The use of this software may or may not infringe the patent rights of one 30 | or more patent holders. This license does not release you from the 31 | requirement that you obtain separate licenses from these patent holders 32 | to use this software. 33 | 34 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY 35 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 36 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 37 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES 39 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL 40 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 41 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | 46 | *****************************************************************************/ 47 | 48 | /***************************** Include Files **********************************/ 49 | #include "Communication.h" 50 | 51 | #include "ADN8810.h" 52 | #include "SHT30.h" 53 | /************************** Variable Definitions ******************************/ 54 | 55 | unsigned char uart_rx_buffer[UART_RX_BUFFER_SIZE]; 56 | unsigned char uart_tx_buffer[UART_TX_BUFFER_SIZE]; 57 | 58 | unsigned int uart_rpos, uart_rcnt, uart_tpos, uart_tcnt; 59 | unsigned int uart_echo, uart_cmd, uart_ctrlc, uart_tbusy; 60 | 61 | uint8_t i2c_rx_buf[6]; 62 | uint8_t i2c_rx_cnt = 0; 63 | 64 | /************************* Functions Definitions ******************************/ 65 | /** 66 | @brief Writes a register to the Converter via SPI. 67 | 68 | @param ui8address - DAC register address 69 | @param ui8Data - value to be written 70 | @enMode ui8Data - write mode 71 | 72 | @return none 73 | 74 | **/ 75 | void SPI_Write(uint8_t ui8address, uint8_t ui8data, enWriteData enMode) 76 | { 77 | 78 | if (SPI_WRITE_DAC_REG == enMode) { /* Select ADN8810 */ 79 | /* Set ADN8810 CS low */ 80 | digitalWrite(CSADN8810_PIN, LOW); 81 | 82 | /* Send first byte */ 83 | SPI.transfer(ui8address); 84 | /* Send second data byte */ 85 | SPI.transfer(ui8data); // 8 data bits 86 | 87 | /* Set ADN8810 CS high */ 88 | digitalWrite(CSADN8810_PIN, HIGH); 89 | } 90 | } 91 | 92 | /** 93 | @brief Reads a specified register or two registers address in the accelerometer via SPI. 94 | 95 | @param ui8address - register address 96 | @param enRegs - register number 97 | 98 | @return reading result 99 | 100 | **/ 101 | uint16_t SPI_Read(void) 102 | { 103 | uint8_t ui8AdcUpperCodes = 0; /* Data register read MSB */ 104 | uint8_t ui8AdcLowerCodes = 0; /* Data register read LSB */ 105 | uint16_t ui16Result = 0; 106 | 107 | /* Start conversion by briefly setting the CNV pin high*/ 108 | digitalWrite(CSAD7988_PIN, HIGH); 109 | /* Set AD7988 CS low */ 110 | digitalWrite(CSAD7988_PIN, LOW); 111 | 112 | /* Send dummy bytes in order to receive the register value */ 113 | ui8AdcUpperCodes = SPI.transfer(0x07); /* Data register read MSB */ 114 | ui8AdcLowerCodes = SPI.transfer(0xAA); /* Data register read LSB */ 115 | 116 | ui16Result = ((uint16_t)ui8AdcUpperCodes << 8) | ui8AdcLowerCodes; 117 | 118 | return ui16Result; 119 | } 120 | /** 121 | @brief Write data to I2C 122 | 123 | @param ui16Data - Data to write 124 | 125 | @return none 126 | 127 | **/ 128 | void I2C_Write(uint16_t ui16Data) 129 | { 130 | uint8_t ui8UpperByte = 0; 131 | uint8_t ui8LowerByte = 0; 132 | 133 | ui8UpperByte = (uint8_t)((ui16Data & 0xFF00) >> 8); 134 | ui8LowerByte = (uint8_t)(ui16Data & 0xFF); 135 | Wire.beginTransmission(SHT30_ADDR); 136 | Wire.write(ui8UpperByte); 137 | Wire.write(ui8LowerByte); 138 | Wire.endTransmission(); 139 | } 140 | 141 | /** 142 | @brief Read data from I2C 143 | 144 | @param none 145 | 146 | @return none 147 | 148 | **/ 149 | void I2C_Read(void) 150 | { 151 | Wire.requestFrom(SHT30_ADDR, 6); 152 | } 153 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0395_example/Communication.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ***************************************************************************** 3 | @file: Communication.h 4 | @brief: 5 | @version: $Revision$ 6 | @date: $Date$ 7 | ----------------------------------------------------------------------------- 8 | 9 | Copyright (c) 2015-2017 Analog Devices, Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | - Modified versions of the software must be conspicuously marked as such. 21 | - This software is licensed solely and exclusively for use with processors 22 | manufactured by or for Analog Devices, Inc. 23 | - This software may not be combined or merged with other code in any manner 24 | that would cause the software to become subject to terms and conditions 25 | which differ from those listed here. 26 | - Neither the name of Analog Devices, Inc. nor the names of its 27 | contributors may be used to endorse or promote products derived 28 | from this software without specific prior written permission. 29 | - The use of this software may or may not infringe the patent rights of one 30 | or more patent holders. This license does not release you from the 31 | requirement that you obtain separate licenses from these patent holders 32 | to use this software. 33 | 34 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY 35 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 36 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 37 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES 39 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL 40 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 41 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | 46 | *****************************************************************************/ 47 | 48 | #ifndef _COMMUNICATION_H_ 49 | #define _COMMUNICATION_H_ 50 | 51 | #include 52 | #include 53 | #include 54 | /*********************Pins configuration*******************/ 55 | 56 | 57 | /* IN1ADG884 - 0.3 - output */ 58 | #define IN1ADG884_PIN 10 59 | 60 | /* CSAD7988 - 0.4 - output */ 61 | #define CSAD7988_PIN 9 62 | 63 | /** ADN8810 pin configuration */ 64 | /* CSADN8810 - 0.5 - output */ 65 | #define CSADN8810_PIN 8 66 | 67 | /* IO7ADN8810 - 2.2 - output */ 68 | #define IO7ADN8810_PIN 7 69 | 70 | /* IO5ADN8810 - 1.3 - output */ 71 | #define IO5ADN8810_PIN 5 72 | 73 | /** ADG758 pin configuration */ 74 | /* A0ADG758 - 1.0 - output */ 75 | #define A0ADG758_PIN 2 76 | 77 | /* A1ADG758 - 1.1 - output */ 78 | #define A1ADG758_PIN 3 79 | 80 | /* A2ADG758 - 1.2 - output */ 81 | #define A2ADG758_PIN 4 82 | 83 | /* IO6ADG758 - 1.4 - output */ 84 | #define IO6ADG758_PIN 6 85 | 86 | /* -------------------------------------------------------------------------*/ 87 | 88 | /* Write data mode */ 89 | typedef enum { 90 | SPI_WRITE_DAC_REG = 1, /* Write data to DAC */ 91 | SPI_WRITE_DAC_FULL_SCALE, /* Write FULL SCALE to DAC */ 92 | UART_WRITE_NO_INT, /* Write data when interrupts are disabled */ 93 | UART_WRITE_IN_INT, /* Write data while in an interrupt routine */ 94 | UART_WRITE 95 | } enWriteData; 96 | 97 | /* Execution status */ 98 | #define UART_SUCCESS 0 99 | #define UART_FAILURE -1 100 | #define UART_NO_TX_SPACE -2 101 | #define UART_NO_RX_SPACE -3 102 | 103 | /* UART status */ 104 | #define UART_TRUE 1 105 | #define UART_FALSE 0 106 | 107 | #define _CR 13 /* */ 108 | #define _LF 10 /* */ 109 | #define _SPC 32 /* */ 110 | #define _BS 8 /* */ 111 | 112 | /* Buffer size for UART Tx and Rx */ 113 | #define UART_TX_BUFFER_SIZE 1024 // UART transmit buffer size 114 | #define UART_RX_BUFFER_SIZE 256 // UART receive buffer size 115 | 116 | extern unsigned int uart_rpos, uart_rcnt, uart_tpos, uart_tcnt; 117 | extern unsigned int uart_echo, uart_cmd, uart_ctrlc, uart_tbusy; 118 | 119 | extern unsigned char uart_rx_buffer[UART_RX_BUFFER_SIZE]; 120 | extern unsigned char uart_tx_buffer[UART_TX_BUFFER_SIZE]; 121 | 122 | extern uint8_t i2c_rx_buf[6]; 123 | extern uint8_t i2c_rx_cnt; 124 | 125 | /******************************************************************************/ 126 | /* Functions Prototypes */ 127 | /******************************************************************************/ 128 | 129 | /* SPI Functions */ 130 | uint16_t SPI_Read(void); 131 | void SPI_Write(uint8_t ui8address, uint8_t ui8data, enWriteData enMode); 132 | 133 | /* I2C Functions */ 134 | void I2C_Write(uint16_t ui16Data); 135 | void I2C_Read(void); 136 | 137 | #endif /* _COMMUNICATION_H_ */ 138 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0395_example/SHT30.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ***************************************************************************** 3 | @file: SHT30.c 4 | @brief: SHT30 sensor 5 | @version: $Revision$ 6 | @date: $Date$ 7 | ----------------------------------------------------------------------------- 8 | 9 | Copyright (c) 2017 Analog Devices, Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | - Modified versions of the software must be conspicuously marked as such. 21 | - This software is licensed solely and exclusively for use with processors 22 | manufactured by or for Analog Devices, Inc. 23 | - This software may not be combined or merged with other code in any manner 24 | that would cause the software to become subject to terms and conditions 25 | which differ from those listed here. 26 | - Neither the name of Analog Devices, Inc. nor the names of its 27 | contributors may be used to endorse or promote products derived 28 | from this software without specific prior written permission. 29 | - The use of this software may or may not infringe the patent rights of one 30 | or more patent holders. This license does not release you from the 31 | requirement that you obtain separate licenses from these patent holders 32 | to use this software. 33 | 34 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY 35 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 36 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 37 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES 39 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL 40 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 41 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | 46 | *****************************************************************************/ 47 | 48 | /***************************** Include Files **********************************/ 49 | #include 50 | #include 51 | #include 52 | 53 | #include "Communication.h" 54 | #include "SHT30.h" 55 | 56 | /**************************** Global functions *******************************/ 57 | 58 | void SHT30_Update(float *fTemp, float *fHum) 59 | { 60 | uint16_t ui16RawTemp; 61 | uint16_t ui16RawHum; 62 | 63 | I2C_Write(SHT30_MEAS_HIGHREP_PERIODIC); 64 | 65 | delay(5); // delay 5ms 66 | 67 | I2C_Read(); 68 | 69 | while (Wire.available()) 70 | i2c_rx_buf[i2c_rx_cnt++] = Wire.read(); 71 | 72 | i2c_rx_cnt = 0; // reload the i2c rx buffer index 73 | 74 | ui16RawTemp = ((uint16_t)i2c_rx_buf[0] << 8) | i2c_rx_buf[1]; 75 | ui16RawHum = ((uint16_t)i2c_rx_buf[3] << 8) | i2c_rx_buf[4]; 76 | 77 | *fTemp = (float)((uint32_t)ui16RawTemp * 175) / (pow(2, 16) - 1) - 45; 78 | *fHum = (float)((uint32_t)ui16RawHum * 100) / (pow(2, 16) - 1); 79 | } 80 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0395_example/SHT30.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ***************************************************************************** 3 | @file: SHT30.h 4 | @brief: SHT30 sensor handling 5 | @version: $Revision$ 6 | @date: $Date$ 7 | ----------------------------------------------------------------------------- 8 | 9 | Copyright (c) 2017 Analog Devices, Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | - Modified versions of the software must be conspicuously marked as such. 21 | - This software is licensed solely and exclusively for use with processors 22 | manufactured by or for Analog Devices, Inc. 23 | - This software may not be combined or merged with other code in any manner 24 | that would cause the software to become subject to terms and conditions 25 | which differ from those listed here. 26 | - Neither the name of Analog Devices, Inc. nor the names of its 27 | contributors may be used to endorse or promote products derived 28 | from this software without specific prior written permission. 29 | - The use of this software may or may not infringe the patent rights of one 30 | or more patent holders. This license does not release you from the 31 | requirement that you obtain separate licenses from these patent holders 32 | to use this software. 33 | 34 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY 35 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 36 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 37 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES 39 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL 40 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 41 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | 46 | *****************************************************************************/ 47 | 48 | #ifndef SHT30_H_ 49 | #define SHT30_H_ 50 | 51 | #include 52 | 53 | #define SHT30_ADDR (uint8_t)0x45 //>> 1 ADDR pin connected to VDD 54 | 55 | #define SHT30_MEAS_HIGHREP_STRETCH 0x2C06 56 | #define SHT30_MEAS_MEDREP_STRETCH 0x2C0D 57 | #define SHT30_MEAS_LOWREP_STRETCH 0x2C10 58 | #define SHT30_MEAS_HIGHREP 0x2400 59 | #define SHT30_MEAS_MEDREP 0x240B 60 | #define SHT30_MEAS_LOWREP 0x2416 61 | 62 | #define SHT30_MEAS_HIGHREP_PERIODIC 0x2737 63 | #define SHT30_FETCH_DATA 0xE000 64 | 65 | #define SHT30_SOFTRESET 0x30A2 66 | 67 | /******************************************************************************/ 68 | /* Functions Prototypes */ 69 | /******************************************************************************/ 70 | void SHT30_Update(float *fTemp, float *fHum); 71 | 72 | #endif // SHT30_H_ 73 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0396_example/AD5270.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file AD5270.h 3 | * @brief Header file for AD5270 rheostat 4 | * @author Analog Devices Inc. 5 | * 6 | ******************************************************************************** 7 | * Copyright 2016(c) Analog Devices, Inc. 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * - Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * - Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * - Neither the name of Analog Devices, Inc. nor the names of its 20 | * contributors may be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * - The use of this software may or may not infringe the patent rights 23 | * of one or more patent holders. This license does not release you 24 | * from the requirement that you obtain separate licenses from these 25 | * patent holders to use this software. 26 | * - Use of the software either in source or binary form, must be run 27 | * on or directly connected to an Analog Devices Inc. component. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 30 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 31 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 32 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 33 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 35 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 36 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 37 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | ********************************************************************************/ 41 | 42 | #ifndef AD5270_H 43 | #define AD5270_H 44 | 45 | #include 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | #define MAX_RESISTANCE 20000.0 52 | #define WRITE_OPERATION_50TP_TIMEOUT 350 53 | #define MEMORY_OPERATION_TIMEOUT 6 54 | #define REG_OPERATION_TIMEOUT 2 55 | 56 | #define SHIFT_REG // 16 bits 57 | 58 | /// AD5270 commands 59 | typedef enum { 60 | NO_OP = 0x00, ///< No data 61 | NO_OP_cmd = 0x0000, ///< 16 bit no data 62 | WRITE_RDAC = 0x04, ///< Write to the RDAC Register 63 | READ_RDAC = 0x08, ///< Read from the RDAC Register 64 | STORE_50TP = 0x0C, ///< Store RDAC setting to 50-TP 65 | SW_RST = 0x10, ///< Software reset to last memory location 66 | READ_50TP_CONTENTS = 0x14, ///< Read the last memory contents 67 | READ_50TP_ADDRESS = 0x18, ///< Read the last memory address 68 | WRITE_CTRL_REG = 0x1C, ///< Write to the control Register 69 | READ_CTRL_REG = 0x20, ///< Read from the control Register 70 | SW_SHUTDOWN = 0x24, ///< Software shutdown (0) - Normal, (1) - Shutdown 71 | HI_Zupper = 0x80, ///< Get the SDO line ready for High Z 72 | HI_Zlower = 0x01, ///< Puts AD5270 into High Z mode 73 | HI_Z_Cmd = 0x8001 ///< Puts AD5270 into High Z mode*/ 74 | } AD5270Commands_t; 75 | 76 | typedef enum { 77 | NORMAL_MODE = 0, 78 | SHUTDOWN_MODE = 1 79 | } AD5270Modes_t; 80 | 81 | typedef enum { 82 | PROGRAM_50TP_ENABLE = 1, 83 | RDAC_WRITE_PROTECT = 2, 84 | R_PERFORMANCE_ENABLE = 4, 85 | MEMORY_PROGRAM_SUCCESFUL = 8 86 | } AD5270ControlRegisterBits_t; 87 | 88 | 89 | uint16_t AD5270_CalcRDAC(float resistance); 90 | float AD5270_WriteRDAC(float resistance); 91 | float AD5270_read_RDAC(void); 92 | float AD5270_ReadRDAC(void); 93 | void AD5270_Set_SDO_HiZ(void); 94 | void AD5270_Enable_50TP_Programming(void); 95 | void AD5270_Store_50TP(void); 96 | void AD5270_Disable_50TP_Programming(void); 97 | uint8_t AD5270_Read_50TP_LastAddress(void); 98 | void AD5270_ResetRDAC(void); 99 | void AD5270_ChangeMode(AD5270Modes_t mode); 100 | uint16_t AD5270_ReadReg(uint8_t command); 101 | void AD5270_WriteReg(uint8_t command, uint16_t value); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif // __cplusplus 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0396_example/ADT7310.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************//** 2 | * @file ADT7310.c 3 | * @brief Implementation of ADT7310 Driver. 4 | * @author 5 | ******************************************************************************** 6 | * Copyright 2016(c) Analog Devices, Inc. 7 | * 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * - Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * - Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in 16 | * the documentation and/or other materials provided with the 17 | * distribution. 18 | * - Neither the name of Analog Devices, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * - The use of this software may or may not infringe the patent rights 22 | * of one or more patent holders. This license does not release you 23 | * from the requirement that you obtain separate licenses from these 24 | * patent holders to use this software. 25 | * - Use of the software either in source or binary form, must be run 26 | * on or directly connected to an Analog Devices Inc. component. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | ********************************************************************************/ 40 | 41 | #include "ADT7310.h" 42 | #include "Communication.h" 43 | 44 | 45 | /****************************************************************************** 46 | * @brief Resets ADT7310. 47 | * 48 | * @param None. 49 | * 50 | * @return None. 51 | *******************************************************************************/ 52 | void ADT7310_Reset(void) 53 | { 54 | uint8_t dataToSend[4] = {0xFF, 0xFF, 0xFF, 0xFF}; 55 | 56 | SPI_Write(dataToSend,4, ADT7310); 57 | delay(1); 58 | 59 | } 60 | 61 | /****************************************************************************** 62 | * @brief Reads ADT7310 register value. 63 | * 64 | * @param reg - which register to read. 65 | * @param size - register size. 66 | * 67 | * @return uint16_t - reading result. 68 | *******************************************************************************/ 69 | uint16_t ADT7310_ReadReg(uint8_t reg, uint8_t _size) 70 | { 71 | uint8_t data[_size]; 72 | uint16_t result = 0; 73 | 74 | data[0] = ADT7310_READ | (reg << 3); 75 | 76 | SPI_Read(data, _size, ADT7310); 77 | 78 | result = data[0]; 79 | 80 | if(_size > 1){ 81 | 82 | for(uint8_t byte = 1; byte < _size; byte++){ 83 | result = (result << (byte * 8) | data[byte]); 84 | } 85 | } 86 | 87 | return result; 88 | 89 | } 90 | 91 | /****************************************************************************** 92 | * @brief Writes an ADT7310 register. 93 | * 94 | * @param reg - in which register to write. 95 | * @param value - value to be written. 96 | * @param size - register size. 97 | * 98 | * @return None. 99 | *******************************************************************************/ 100 | void ADT7310_WriteReg(uint8_t reg, uint16_t value, uint8_t _size) 101 | { 102 | uint8_t data[_size + 1]; 103 | uint8_t byte; 104 | uint16_t mask; 105 | 106 | data[0] = ADT7310_WRITE | (reg << 3); 107 | 108 | if(_size == 1){ 109 | 110 | mask = 0x00FF; 111 | 112 | } else{ 113 | 114 | mask = 0xFF00; 115 | } 116 | 117 | for(byte = 1; byte <= _size; byte++) 118 | { 119 | data[byte] = (uint8_t)((value & mask) >> ((_size - byte) * 8)); 120 | mask = mask >> (byte * 8); 121 | } 122 | 123 | SPI_Write(data,(1 + _size), ADT7310); 124 | } 125 | 126 | /****************************************************************************** 127 | * @brief Reads TEMP register and convert it into actual temperature. 128 | * 129 | * @param None. 130 | * 131 | * @return float - Temperature value. 132 | *******************************************************************************/ 133 | float ADT7310_ReadTemp(void) 134 | { 135 | uint16_t readData; 136 | float temp; 137 | 138 | readData = ADT7310_ReadReg(ADT7310_TEMP, 2); 139 | 140 | if(readData & 0x8000) 141 | { 142 | temp = (readData - 65536) / (128.0); 143 | } 144 | else 145 | { 146 | temp = readData / (128.0); 147 | } 148 | 149 | return temp; 150 | } 151 | 152 | /****************************************************************************** 153 | * @brief Write setpoint value into setpoint registers. 154 | * 155 | * @param setpoint - which setpoint to write. 156 | * @param data - what value to write. 157 | * 158 | * @return None. 159 | *******************************************************************************/ 160 | void ADT7310_WriteSetpoint(uint8_t setpoint, uint16_t data) 161 | { 162 | ADT7310_WriteReg(setpoint, data, 2); 163 | } 164 | 165 | /****************************************************************************** 166 | * @brief Start single conversion mode. 167 | * 168 | * @param None. 169 | * 170 | * @return None. 171 | *******************************************************************************/ 172 | void ADT7310_StartSingleConversion(void) 173 | { 174 | ADT7310_WriteReg(ADT7310_CONFIG, 0x20, 1); 175 | } 176 | 177 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0396_example/ADT7310.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ADT7310.h 3 | * @brief Header file for ADT7310. 4 | * @author Analog Devices Inc. 5 | * 6 | ******************************************************************************** 7 | * Copyright 2016(c) Analog Devices, Inc. 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * - Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * - Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * - Neither the name of Analog Devices, Inc. nor the names of its 20 | * contributors may be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * - The use of this software may or may not infringe the patent rights 23 | * of one or more patent holders. This license does not release you 24 | * from the requirement that you obtain separate licenses from these 25 | * patent holders to use this software. 26 | * - Use of the software either in source or binary form, must be run 27 | * on or directly connected to an Analog Devices Inc. component. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 30 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 31 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 32 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 33 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 35 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 36 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 37 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | ********************************************************************************/ 41 | #ifndef ADT7310_H 42 | #define ADT7310_H 43 | 44 | #include 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | #define ADT7310_READ (1<<6) 51 | #define ADT7310_WRITE (0) 52 | #define ADT7310_DUMMY (0) 53 | #define ADT7310_STATUS (0) 54 | #define ADT7310_CONFIG (1) 55 | #define ADT7310_TEMP (2) 56 | #define ADT7310_ID (3) 57 | #define ADT7310_TCRIT (4) 58 | #define ADT7310_THYST (5) 59 | #define ADT7310_THIGH (6) 60 | #define ADT7310_TLOW (7) 61 | 62 | 63 | void ADT7310_Reset(void); 64 | uint16_t ADT7310_ReadReg(uint8_t reg, uint8_t _size); 65 | void ADT7310_WriteReg(uint8_t reg, uint16_t value, uint8_t _size); 66 | float ADT7310_ReadTemp(void); 67 | void ADT7310_WriteSetpoint(uint8_t setpoint, uint16_t data); 68 | void ADT7310_StartSingleConversion(void); 69 | uint8_t ADT7310_Ready(void); 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif // __cplusplus 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0396_example/CN0396.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file CN0396.h 3 | * @brief Header file for CN0396. 4 | * @author Analog Devices Inc. 5 | * 6 | ******************************************************************************** 7 | * Copyright 2016(c) Analog Devices, Inc. 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * - Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * - Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * - Neither the name of Analog Devices, Inc. nor the names of its 20 | * contributors may be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * - The use of this software may or may not infringe the patent rights 23 | * of one or more patent holders. This license does not release you 24 | * from the requirement that you obtain separate licenses from these 25 | * patent holders to use this software. 26 | * - Use of the software either in source or binary form, must be run 27 | * on or directly connected to an Analog Devices Inc. component. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 30 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 31 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 32 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 33 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 35 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 36 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 37 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | ********************************************************************************/ 41 | 42 | #ifndef CN0396_H_ 43 | #define CN0396_H_ 44 | 45 | #include 46 | #include 47 | #include "AD7798.h" 48 | 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | 53 | 54 | #define REGISTERS_VALUES 3 55 | #define CONVERSION_DATA 4 56 | 57 | #define V_REF 1.2 // [V] 58 | #define _2_16 65536.0 // 2^16 59 | #define _2_15 32768.0 // 2^15 60 | 61 | #define COMPENSATION_TABLE_SIZE 9 62 | 63 | typedef enum { 64 | CO_SENSOR, 65 | H2S_SENSOR 66 | } sensor_type_t; 67 | 68 | typedef struct { 69 | int8_t temp; 70 | float CO_percent; 71 | float H2S_percent; 72 | } ppm_compensation_t; 73 | 74 | 75 | extern void CN0396_Init(void); 76 | extern void CN0396_DisplayData(void); 77 | extern void CN0396_ConvertToVoltage(uint16_t adcValue, float *voltage); 78 | extern void CN0396_SetAppData(void); 79 | extern float CN0396_GetFeedbackResistor(float sensitivity, float range); 80 | extern float CN0396_CompensatePPM(float result, float temp, sensor_type_t sensor); 81 | extern void CN0396_ConfigureFeedbackResistors(float resistance1, float resistance2); 82 | 83 | /* Available settings: 84 | * AD7798_GAIN_1, AD7798_GAIN_2, 85 | * AD7798_GAIN_4, AD7798_GAIN_8, 86 | * AD7798_GAIN_16, AD7798_GAIN_32, 87 | * AD7798_GAIN_64, AD7798_GAIN_128 88 | */ 89 | #define ADC_GAIN AD7798_GAIN_1 90 | /* Available settings: 91 | * Check available value from datasheet 92 | */ 93 | #define ADC_SPS 0x05 //50SPS 94 | 95 | /* Available settings: 96 | * How often to display output values on terminal -> msec 97 | */ 98 | #define DISPLAY_REFRESH 500 //[msec] 99 | 100 | #define MAX_CO_SENS (100 * pow(10, -9)) 101 | #define CO_SENS (75 * pow(10, -9)) /* Sensitivity nA/ppm CO 50 to 100 */ 102 | #define CO_RANGE 1000 /* Range ppm CO limit of performance warranty 1,000 */ 103 | 104 | #define MAX_H2S_SENS (1000 * pow(10, -9)) 105 | #define H2S_SENS (800 * pow(10, -9)) /* Sensitivity nA/ppm H2S 450 to 900 */ 106 | #define H2S_RANGE 200 /* Range ppm H2S limit of performance warranty 200 */ 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif // __cplusplus 111 | 112 | #endif /* CN0396_H_ */ 113 | 114 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0396_example/CN0396_example.ino: -------------------------------------------------------------------------------- 1 | #include "SPI.h" 2 | #include "Communication.h" 3 | #include "CN0396.h" 4 | 5 | void setup() { 6 | Serial.begin(9600); 7 | delay(1000); 8 | 9 | CN0396_Init(); 10 | 11 | } 12 | 13 | void loop() { 14 | 15 | delay(DISPLAY_REFRESH); 16 | 17 | CN0396_SetAppData(); 18 | 19 | CN0396_DisplayData(); 20 | } 21 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0396_example/Communication.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Communication.h 4 | * @brief Header file for communication part 5 | * @version V0.1 6 | * @author ADI 7 | * 8 | ******************************************************************************* 9 | * Copyright 2016(c) Analog Devices, Inc. 10 | * 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * - Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * - Neither the name of Analog Devices, Inc. nor the names of its 22 | * contributors may be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * - The use of this software may or may not infringe the patent rights 25 | * of one or more patent holders. This license does not release you 26 | * from the requirement that you obtain separate licenses from these 27 | * patent holders to use this software. 28 | * - Use of the software either in source or binary form, must be run 29 | * on or directly connected to an Analog Devices Inc. component. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED 32 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY 33 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 34 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 36 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 38 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 40 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 | * 42 | ******************************************************************************* 43 | **/ 44 | #ifndef _COMMUNICATION_H_ 45 | #define _COMMUNICATION_H_ 46 | 47 | #include 48 | #include "SPI.h" 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | /********************************* Internal defines ****************************/ 54 | 55 | /****************************** Global Data ***********************************/ 56 | 57 | /****************************** Internal types *********************************/ 58 | typedef enum 59 | { 60 | AD7798 = 0, 61 | ADT7310, 62 | AD5270 63 | 64 | } enChannels; 65 | 66 | /* Write data mode */ 67 | typedef enum { 68 | UART_WRITE_NO_INT = 1, /* Write data when interrupts are disabled */ 69 | UART_WRITE_IN_INT, /* Write data while in an interrupt routine */ 70 | UART_WRITE 71 | } enWriteData; 72 | 73 | /*************************** Functions prototypes *****************************/ 74 | extern void SPI_Init(void); 75 | extern void SPI_Write(unsigned char* data, unsigned char bytesNumber, enChannels ch); 76 | extern void SPI_Read(unsigned char* data, unsigned char bytesNumber, enChannels ch); 77 | 78 | extern uint8_t convFlag, daisyCh; 79 | 80 | /**************************** Configuration parameters **********************/ 81 | /* AD7798_CS - 0.3 - output */ 82 | #define AD7798_CS_PIN 9 83 | 84 | /* ADT7310 - 1.2 - output */ 85 | #define ADT7310_CS_PIN 4 86 | 87 | /* ADT7310 - 1.4 - output */ 88 | #define AD5270_CS_PIN 6 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif // __cplusplus 93 | 94 | #endif /* _COMMUNICATION_H_ */ 95 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0397_example/CN0397.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file CN0397.h 4 | * @brief Header file for communication part 5 | * @version V0.1 6 | * @author ADI 7 | * 8 | ******************************************************************************* 9 | * Copyright 2016(c) Analog Devices, Inc. 10 | * 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * - Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * - Neither the name of Analog Devices, Inc. nor the names of its 22 | * contributors may be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * - The use of this software may or may not infringe the patent rights 25 | * of one or more patent holders. This license does not release you 26 | * from the requirement that you obtain separate licenses from these 27 | * patent holders to use this software. 28 | * - Use of the software either in source or binary form, must be run 29 | * on or directly connected to an Analog Devices Inc. component. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED 32 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY 33 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 34 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 36 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 38 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 40 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 | * 42 | ******************************************************************************* 43 | **/ 44 | #ifndef CN0397_H_ 45 | #define CN0397_H_ 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | #include "AD7798.h" 52 | #include "Arduino.h" 53 | 54 | #define REGISTERS_VALUES 3 55 | #define CONVERSION_DATA 4 56 | 57 | #define YES 1 58 | #define NO 0 59 | 60 | #define CHANNELS 3 61 | 62 | #define V_REF 3150.0 // [mV] 63 | #define _2_16 65535.0 // 2^16 64 | 65 | extern void CN0397_Init(void); 66 | extern void CN0397_DisplayData(void); 67 | extern void CN0397_ReadADCData(uint8_t adcChannel, uint16_t *adcData); 68 | extern void CN0397_ConvertToVoltage(uint16_t adcValue, float *voltage); 69 | extern void CN0397_CalcLightIntensity(uint8_t channel, uint16_t adcValue, float *intensity); 70 | extern void CN0397_CalcLightConcentration(uint8_t channel, float intensity, float *conc); 71 | extern void CN0397_SetAppData(void); 72 | extern void CN0397_Calibration(uint8_t channel); 73 | extern void CN0397_SetBar(float conc, int *line); 74 | 75 | /* Available settings: 76 | * AD7798_GAIN_1, AD7798_GAIN_2, 77 | * AD7798_GAIN_4, AD7798_GAIN_8, 78 | * AD7798_GAIN_16, AD7798_GAIN_32, 79 | * AD7798_GAIN_64, AD7798_GAIN_128 80 | */ 81 | #define ADC_GAIN AD7798_GAIN_1 82 | /* Available settings: 83 | * Check available value from datasheet 84 | */ 85 | #define ADC_SPS 0x05 //50SPS 86 | 87 | 88 | /* Available settings: 89 | * How often to display output values on terminal -> msec 90 | */ 91 | #define DISPLAY_REFRESH 500 //[msec] 92 | 93 | #define USE_CALIBRATION YES // Set YES if you want to use system zero-scale calibration before reading the system data; otherwise set NO. 94 | 95 | #ifdef __cplusplus 96 | } // extern "C" 97 | #endif 98 | 99 | #endif /* CN0397_H_ */ 100 | 101 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0397_example/CN0397_example.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "CN0397.h" 3 | #include 4 | 5 | byte CS_PIN = 10; 6 | 7 | void setup() { 8 | 9 | Serial.begin(9600); 10 | SPI.begin(); 11 | SPI.setDataMode(SPI_MODE3); //CPHA = CPOL = 1 MODE = 3 12 | delay(1000); 13 | 14 | pinMode(CS_PIN, OUTPUT); 15 | 16 | CN0397_Init(); 17 | } 18 | 19 | void loop() { 20 | 21 | delay(DISPLAY_REFRESH); 22 | 23 | CN0397_SetAppData(); 24 | 25 | CN0397_DisplayData(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0397_example/Communication.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Communication.c 4 | * @brief Source file for communication part. 5 | * @version V0.1 6 | * @author ADI 7 | * 8 | ******************************************************************************* 9 | * Copyright 2016(c) Analog Devices, Inc. 10 | * 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * - Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * - Neither the name of Analog Devices, Inc. nor the names of its 22 | * contributors may be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * - The use of this software may or may not infringe the patent rights 25 | * of one or more patent holders. This license does not release you 26 | * from the requirement that you obtain separate licenses from these 27 | * patent holders to use this software. 28 | * - Use of the software either in source or binary form, must be run 29 | * on or directly connected to an Analog Devices Inc. component. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED 32 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY 33 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 34 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 36 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 38 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 40 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 | * 42 | ******************************************************************************* 43 | **/ 44 | 45 | /***************************** Include Files **********************************/ 46 | #include "Communication.h" 47 | 48 | /********************************* Global data ********************************/ 49 | 50 | unsigned char ucWaitForUart = 0; // Used by calibration routines to wait for user input 51 | unsigned char szTemp[64] = ""; // Used to store string before printing to UART 52 | unsigned char nLen = 0; 53 | unsigned char i = 0; 54 | 55 | uint8_t convFlag; 56 | 57 | /*************************************************************************** 58 | * @brief Writes data to SPI. 59 | * 60 | * @param data - Write data buffer: 61 | * - first byte is the chip select number; 62 | * - from the second byte onwards are located data bytes to write. 63 | * @param bytesNumber - Number of bytes to write. 64 | * 65 | * @return Number of written bytes. 66 | *******************************************************************************/ 67 | void SPI_Write(unsigned char* data, unsigned char bytesNumber) 68 | { 69 | uint8_t count = 0; 70 | 71 | uint16_t ui16fifo_status = (bytesNumber << 8); /* Set FIFO status correct value */ 72 | 73 | if(convFlag == 0) 74 | digitalWrite(CS_PIN,LOW); 75 | 76 | for(count = 0;count < bytesNumber;count++) 77 | { 78 | SPI.transfer(data[count]); 79 | } 80 | 81 | if(convFlag == 0) 82 | digitalWrite(CS_PIN,HIGH); 83 | 84 | } 85 | 86 | /***************************************************************************//** 87 | * @brief Reads data from SPI. 88 | * 89 | * @param data - As an input parameter, data represents the write buffer: 90 | * - first byte is the chip select number; 91 | * - from the second byte onwards are located data bytes to write. 92 | * As an output parameter, data represents the read buffer: 93 | * - from the first byte onwards are located the read data bytes. 94 | * @param bytesNumber - Number of bytes to write. 95 | * 96 | * @return Number of written bytes. 97 | *******************************************************************************/ 98 | void SPI_Read(unsigned char* data, unsigned char bytesNumber) 99 | { 100 | 101 | unsigned char writeData[4] = {0, 0, 0, 0}; 102 | unsigned char count = 0; 103 | uint16_t ui16fifo_status = ((bytesNumber + 1) << 8); /* Set FIFO status correct value */ 104 | 105 | for(count = 0;count <= bytesNumber;count++) 106 | { 107 | if(count == 0) 108 | writeData[count] = data[count]; 109 | else 110 | writeData[count] = 0xAA; /* dummy value */ 111 | } 112 | 113 | if(convFlag == 0) 114 | digitalWrite(CS_PIN,LOW); 115 | 116 | SPI.transfer(writeData[0]); 117 | 118 | for(count = 1; count < bytesNumber + 1;count++) 119 | { 120 | data[count - 1] = SPI.transfer(writeData[count]); 121 | } 122 | 123 | if(convFlag == 0) 124 | digitalWrite(CS_PIN,HIGH); 125 | } 126 | 127 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0397_example/Communication.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Communication.h 4 | * @brief Header file for communication part 5 | * @version V0.1 6 | * @author ADI 7 | * 8 | ******************************************************************************* 9 | * Copyright 2016(c) Analog Devices, Inc. 10 | * 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * - Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * - Neither the name of Analog Devices, Inc. nor the names of its 22 | * contributors may be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * - The use of this software may or may not infringe the patent rights 25 | * of one or more patent holders. This license does not release you 26 | * from the requirement that you obtain separate licenses from these 27 | * patent holders to use this software. 28 | * - Use of the software either in source or binary form, must be run 29 | * on or directly connected to an Analog Devices Inc. component. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED 32 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY 33 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 34 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 36 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 38 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 40 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 | * 42 | ******************************************************************************* 43 | **/ 44 | #ifndef _COMMUNICATION_H_ 45 | #define _COMMUNICATION_H_ 46 | 47 | #include "Arduino.h" 48 | #include 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /********************************* Internal defines ****************************/ 55 | 56 | 57 | /****************************** Global Data ***********************************/ 58 | /****************************** Internal types *********************************/ 59 | 60 | /* Number of received bytes */ 61 | typedef enum { 62 | ONE_BYTE = 1, /* Read one byte */ 63 | TWO_BYTES /* Read two bytes */ 64 | } enReadBytes; 65 | 66 | 67 | /*************************** Functions prototypes *****************************/ 68 | 69 | extern void SPI_Write(unsigned char* data, unsigned char bytesNumber); 70 | extern void SPI_Read(unsigned char* data, unsigned char bytesNumber); 71 | 72 | extern uint8_t convFlag; 73 | 74 | /**************************** Configuration parameters **********************/ 75 | //* CSAD7798 - 0.3 - output */ 76 | #define CS_PIN 10 77 | 78 | #ifdef __cplusplus 79 | } // extern "C" 80 | #endif 81 | 82 | #endif /* _COMMUNICATION_H_ */ 83 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0410_example/CN0410_example.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "adi_cn0410.h" 5 | 6 | char Buffer[12]; 7 | 8 | uint8_t u8Index; 9 | bool boCommandReceived = false; 10 | uint8_t u8Error; 11 | char u8Channel; 12 | uint16_t u16DacValue, u16ChannelValue; 13 | 14 | CN0410 cn0410; 15 | 16 | void setup() { 17 | 18 | Serial.begin(9600); 19 | 20 | cn0410.Init(); //init spi and pins 21 | 22 | cn0410.SendCommand(AD5686_ITERNAL_REFERENCE, 23 | AD5686_DAC_NONE, 0x00); /*enable internal reference*/ 24 | cn0410.SendCommand(AD5686_POWER, 25 | AD5686_DAC_NONE, 0x00); /*normal power mode for all ch*/ 26 | 27 | delay(10); //10 ms delay 28 | 29 | cn0410.SendCommand(AD5686_RESET, 30 | AD5686_DAC_NONE, 0x00); /*soft reset to zero scale*/ 31 | 32 | Serial.print(F("\n\n\rCN0410 Demo Software\n\r")); 33 | Serial.print(F("Enter command in the following format set_x value,\n\r \ 34 | where x is the channel (a,b,c) and hit enter \n\r \ 35 | To reset channels input command set_zero \n\r> ")); 36 | } 37 | 38 | void loop() { 39 | 40 | if (boCommandReceived) { 41 | boCommandReceived = false; /*reset command received*/ 42 | 43 | u8Error = ProcessCommand(&u8Channel, &u16DacValue); 44 | 45 | if ( u8Error == 0 ) { 46 | Serial.print("Command received.\n\r"); 47 | 48 | switch ((char)u8Channel) { 49 | case 'a': 50 | cn0410.SendCommand(AD5686_WRITE_UPDATE, 51 | AD5686_DAC_A, u16DacValue); 52 | u16ChannelValue = cn0410.ReadBack(AD5686_DAC_A); 53 | Serial.print("Channel A set to: "); Serial.println(u16ChannelValue); 54 | break; 55 | case 'b': 56 | cn0410.SendCommand(AD5686_WRITE_UPDATE, 57 | AD5686_DAC_B, u16DacValue); 58 | u16ChannelValue = cn0410.ReadBack(AD5686_DAC_B); 59 | Serial.print("Channel B set to: "); Serial.println(u16ChannelValue); 60 | break; 61 | case 'c': 62 | cn0410.SendCommand(AD5686_WRITE_UPDATE, 63 | AD5686_DAC_C, u16DacValue); 64 | u16ChannelValue = cn0410.ReadBack(AD5686_DAC_C); 65 | Serial.print("Channel C set to: "); Serial.println(u16ChannelValue); 66 | break; 67 | case '0': 68 | cn0410.Reset(); 69 | Serial.print("All channels reset to 0\n\r"); 70 | break; 71 | default: 72 | Serial.print("Invalid value\n\r"); 73 | break; 74 | } 75 | } else { 76 | Serial.print("Invalid command\n\r"); 77 | } 78 | 79 | u16ChannelValue = cn0410.ReadBack(AD5686_DAC_A); 80 | Serial.print("\n\rChannel A set to: "); Serial.println(u16ChannelValue); 81 | u16ChannelValue = cn0410.ReadBack(AD5686_DAC_B); 82 | Serial.print("Channel B set to: "); Serial.println(u16ChannelValue); 83 | u16ChannelValue = cn0410.ReadBack(AD5686_DAC_C); 84 | Serial.print("Channel C set to: "); Serial.println(u16ChannelValue); 85 | 86 | delay(1000); //1 second sleep 87 | Serial.print("\n\n\rEnter new command\n\r> "); 88 | } 89 | } 90 | 91 | void serialEvent() { 92 | 93 | while (Serial.available() > 0) { 94 | Buffer[u8Index] = Serial.read(); 95 | u8Index++; 96 | } 97 | 98 | if ((Buffer[u8Index - 1] == '\n') | (u8Index == 12)) { 99 | boCommandReceived = true; 100 | u8Index = 0; 101 | } 102 | } 103 | 104 | uint8_t ProcessCommand(uint8_t * u8Channel, uint16_t * u16DacValue) 105 | { 106 | uint16_t u16RawValue; 107 | 108 | if ((((char)Buffer[4] != (char)'a') & ((char)Buffer[4] != (char)'b') & 109 | ((char)Buffer[4] != (char)'c') & ((char)Buffer[4] != (char)'z'))) 110 | return -1; 111 | 112 | if ((Buffer[4] != 'z')) 113 | *u8Channel = (char)Buffer[4]; /*channel letter*/ 114 | else 115 | *u8Channel = (char)'0'; 116 | 117 | u16RawValue = (uint16_t)atoi((char *)&Buffer[6]); 118 | *u16DacValue = u16RawValue; 119 | 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0410_example/adi_cn0410.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************//** 2 | @file adi_cn0410.cpp 3 | @brief Implementation of CN0410 dac interface. 4 | @author Mircea Caprioru (mircea.caprioru@analog.com) 5 | ******************************************************************************** 6 | Copyright 2018(c) Analog Devices, Inc. 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in 16 | the documentation and/or other materials provided with the 17 | distribution. 18 | - Neither the name of Analog Devices, Inc. nor the names of its 19 | contributors may be used to endorse or promote products derived 20 | from this software without specific prior written permission. 21 | - The use of this software may or may not infringe the patent rights 22 | of one or more patent holders. This license does not release you 23 | from the requirement that you obtain separate licenses from these 24 | patent holders to use this software. 25 | - Use of the software either in source or binary form, must be run 26 | on or directly connected to an Analog Devices Inc. component. 27 | 28 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 29 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 30 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 31 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | *******************************************************************************/ 39 | 40 | #include "adi_cn0410.h" 41 | 42 | CN0410::CN0410() 43 | { 44 | /* Constructor for CN0410 */ 45 | } 46 | 47 | int8_t CN0410::Init() 48 | { 49 | 50 | /* Initialize SPI driver */ 51 | SPI.begin(); 52 | SPI.setDataMode(SPI_MODE2); //CPHA = 0, CPOL = 1 MODE = 2 53 | 54 | /* Setup LDAC & Reset pins */ 55 | pinMode(LDAC_PIN, OUTPUT); 56 | digitalWrite(LDAC_PIN, LOW); 57 | pinMode(RESET_PIN, OUTPUT); 58 | digitalWrite(RESET_PIN, HIGH); 59 | pinMode(SYNC_PIN, OUTPUT); 60 | digitalWrite(SYNC_PIN, HIGH); 61 | 62 | return 0; 63 | } 64 | 65 | void CN0410::Reset() 66 | { 67 | /* Reset all led values */ 68 | this->SendCommand(AD5686_WRITE_UPDATE, AD5686_DAC_A, 0x00); 69 | this->SendCommand(AD5686_WRITE_UPDATE, AD5686_DAC_B, 0x00); 70 | this->SendCommand(AD5686_WRITE_UPDATE, AD5686_DAC_C, 0x00); 71 | this->SendCommand(AD5686_WRITE_UPDATE, AD5686_DAC_D, 0x00); 72 | } 73 | 74 | void CN0410::UpdateDAC() 75 | { 76 | /* Update the DAC register by pulsing the LDAC pin */ 77 | digitalWrite(LDAC_PIN, HIGH); 78 | digitalWrite(LDAC_PIN, LOW); 79 | digitalWrite(LDAC_PIN, HIGH); 80 | } 81 | 82 | int8_t CN0410::SendCommand(uint8_t u8Command, 83 | uint8_t u8Channel, uint16_t u16Value) 84 | { 85 | uint8_t u8Buffer[3]; 86 | 87 | u8Buffer[0] = ((u8Command & 0x0F) << 4) + (u8Channel & 0x0F); 88 | u8Buffer[1] = u16Value >> 8; 89 | u8Buffer[2] = u16Value & 0xFF; 90 | 91 | digitalWrite(SYNC_PIN, LOW); 92 | 93 | SPI.transfer(u8Buffer, 3); 94 | 95 | digitalWrite(SYNC_PIN, HIGH); 96 | 97 | return 0; 98 | } 99 | 100 | uint32_t CN0410::ReadBack(uint8_t u8DacChannelAddr) 101 | { 102 | uint32_t u32ChannelValue; 103 | uint8_t rxBuffer[3] = {0, 0, 0}; 104 | uint8_t txBuffer[3] = {0, 0, 0}; 105 | 106 | this->SendCommand(AD5686_SET_READBACK, u8DacChannelAddr, 0x00); 107 | 108 | digitalWrite(SYNC_PIN, LOW); 109 | 110 | for (int i = 0; i < 3; i++) 111 | rxBuffer[i] = SPI.transfer(txBuffer[i]); 112 | 113 | digitalWrite(SYNC_PIN, HIGH); 114 | 115 | u32ChannelValue = (rxBuffer[0] << 16) + (rxBuffer[1] << 8) + rxBuffer[2]; 116 | 117 | return u32ChannelValue; 118 | } 119 | 120 | CN0410::~CN0410() 121 | { 122 | Serial.println("CN0410 object has been destroyed"); 123 | } 124 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0410_example/adi_cn0410.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************//** 2 | @file adi_cn0410.h 3 | @brief Implementation of CN0410 header. 4 | @author Mircea Caprioru (mircea.caprioru@analog.com) 5 | ******************************************************************************** 6 | Copyright 2018(c) Analog Devices, Inc. 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in 16 | the documentation and/or other materials provided with the 17 | distribution. 18 | - Neither the name of Analog Devices, Inc. nor the names of its 19 | contributors may be used to endorse or promote products derived 20 | from this software without specific prior written permission. 21 | - The use of this software may or may not infringe the patent rights 22 | of one or more patent holders. This license does not release you 23 | from the requirement that you obtain separate licenses from these 24 | patent holders to use this software. 25 | - Use of the software either in source or binary form, must be run 26 | on or directly connected to an Analog Devices Inc. component. 27 | 28 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 29 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 30 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 31 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | *******************************************************************************/ 39 | #include 40 | #include 41 | 42 | #ifndef SENSORS_ADI_CN0410_H_ 43 | #define SENSORS_ADI_CN0410_H_ 44 | 45 | #define SYNC_PIN 10 46 | #define LDAC_PIN 7 47 | #define RESET_PIN 6 48 | 49 | enum ad5686_commands { 50 | AD5686_NO_OPERATION = 0, 51 | AD5686_WRITE_LDAC, 52 | AD5686_UPDATE, 53 | AD5686_WRITE_UPDATE, 54 | AD5686_POWER, 55 | AD5686_LDAC_MASK, 56 | AD5686_RESET, 57 | AD5686_ITERNAL_REFERENCE, 58 | AD5686_SET_DCEN = 0x08, 59 | AD5686_SET_READBACK, 60 | AD5686_DAISY_CHAIN = 0x0F 61 | }; 62 | 63 | enum ad5686_dac_channels { 64 | AD5686_DAC_NONE = 0x00, 65 | AD5686_DAC_A = 0x01, 66 | AD5686_DAC_B = 0x02, 67 | AD5686_DAC_C = 0x04, 68 | AD5686_DAC_D = 0x08 69 | }; 70 | 71 | class CN0410 72 | { 73 | public: 74 | CN0410(); 75 | 76 | int8_t Init(); 77 | void Reset(); 78 | void UpdateDAC(); 79 | int8_t SendCommand(uint8_t u8Command, uint8_t u8Channel, 80 | uint16_t u16Value); 81 | uint32_t ReadBack(uint8_t u8DacChannelAddr); 82 | ~CN0410(); 83 | 84 | }; 85 | 86 | #endif /* SENSORS_ADI_CN0410_H_ */ 87 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0411_example/AD5683.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************//** 2 | * @file AD5683.c 3 | * @brief AD5683 Driver implementation file. 4 | * @author Antoniu Miclaus (antoniu.miclaus@analog.com) 5 | ******************************************************************************** 6 | * Copyright 2018(c) Analog Devices, Inc. 7 | * 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * - Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * - Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in 16 | * the documentation and/or other materials provided with the 17 | * distribution. 18 | * - Neither the name of Analog Devices, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * - The use of this software may or may not infringe the patent rights 22 | * of one or more patent holders. This license does not release you 23 | * from the requirement that you obtain separate licenses from these 24 | * patent holders to use this software. 25 | * - Use of the software either in source or binary form, must be run 26 | * on or directly connected to an Analog Devices Inc. component. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | *******************************************************************************/ 39 | 40 | 41 | /******************************************************************************/ 42 | /***************************** Include Files **********************************/ 43 | /******************************************************************************/ 44 | #include "AD5683.h" 45 | #include "Communication.h" 46 | #include 47 | 48 | /******************************************************************************/ 49 | /************************** Functions Implementation **************************/ 50 | /******************************************************************************/ 51 | 52 | /** 53 | * Write commands to DAC 54 | * 55 | * @param device - device structure 56 | * @param cmd - command value 57 | * @param data - data to be written 58 | * @return 0 in case of success, negative error code otherwise. 59 | */ 60 | int32_t AD5683_write_cmd(struct ad5683_device *device, uint8_t cmd, 61 | uint16_t data) 62 | { 63 | uint8_t buf[3]; 64 | 65 | buf[2] = ((data << 4) & 0xF0); 66 | buf[1] = (data >> 4); 67 | buf[0] = (data >> 12) | (cmd << 4); 68 | 69 | return SPI_Write(device->slave_select_id, buf, 3); 70 | } 71 | 72 | /** 73 | * Readback the contents of the input register. 74 | * 75 | * @param device - device structure 76 | * @param data - read data to be stored 77 | * @return 0 in case of success, negative error code otherwise. 78 | */ 79 | int32_t AD5683_readback_register(struct ad5683_device *device, uint32_t *data) 80 | { 81 | 82 | int32_t ret; 83 | uint8_t buf[3] = {0, 0, 0}; 84 | 85 | AD5683_write_cmd(device, AD5683_CMD_RB_IN_REG, 0x0000); 86 | ret = SPI_Read(device->slave_select_id, buf, 3); 87 | *data = (((buf[0] << 16) | (buf[1] << 8) | (buf[2])) & 0x0FFFF0) >> 4; 88 | 89 | return ret; 90 | } 91 | 92 | /** 93 | * Write value to DAC 94 | * 95 | * @param device - device structure 96 | * @param data - data to be written 97 | * @return 0 in case of success, negative error code otherwise. 98 | */ 99 | int32_t AD5683_write_dac_value(struct ad5683_device *ad5683_device, 100 | uint16_t data) 101 | { 102 | return AD5683_write_cmd(ad5683_device, AD5683_CMD_WR_DAC_IN_REG, data); 103 | } 104 | 105 | /** 106 | * Perform DAC Soft Reset 107 | * 108 | * @param device - device structure 109 | * @return 0 in case of success, negative error code otherwise. 110 | */ 111 | int32_t AD5683_soft_reset(struct ad5683_device *ad5683_device) 112 | { 113 | return AD5683_write_cmd(ad5683_device, AD5683_CMD_WR_CTRL_REG, 114 | AD5683_SW_RESET(AD5683_RESET_ENABLE)); 115 | } 116 | 117 | /** 118 | * Write command to DAC 119 | * 120 | * @param device - device structure 121 | * @param slave_select_id - chip select value corresponding to DAC 122 | * @return 0 in case of success, negative error code otherwise. 123 | */ 124 | int32_t AD5683_setup(struct ad5683_device *ad5683_device, int slave_select_id) 125 | { 126 | ad5683_device->slave_select_id = slave_select_id; 127 | ad5683_device->dac_reg_value = 0; 128 | 129 | if(AD5683_soft_reset(ad5683_device) == AD5683_FAILURE) 130 | return AD5683_FAILURE; 131 | else 132 | return AD5683_write_cmd(ad5683_device, AD5683_CMD_WR_CTRL_REG, 133 | AD5683_DCEN(AD5683_DC_DISABLE) 134 | | AD5683_CFG_GAIN(AD5683_AMP_GAIN_1) 135 | | AD5683_REF_EN(AD5683_INT_REF_ON) 136 | | AD5683_OP_MOD(AD5683_PWR_NORMAL) 137 | | AD5683_SW_RESET(AD5683_RESET_DISABLE)); 138 | } 139 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0411_example/AD5683.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************//** 2 | * @file ad5683.h 3 | * @brief AD4110 Driver header file. 4 | * @author Antoniu Miclaus (antoniu.miclaus@analog.com) 5 | ******************************************************************************** 6 | * Copyright 2018(c) Analog Devices, Inc. 7 | * 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * - Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * - Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in 16 | * the documentation and/or other materials provided with the 17 | * distribution. 18 | * - Neither the name of Analog Devices, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * - The use of this software may or may not infringe the patent rights 22 | * of one or more patent holders. This license does not release you 23 | * from the requirement that you obtain separate licenses from these 24 | * patent holders to use this software. 25 | * - Use of the software either in source or binary form, must be run 26 | * on or directly connected to an Analog Devices Inc. component. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | *******************************************************************************/ 39 | 40 | #ifndef _AD5683_H_ 41 | #define _AD5683_H_ 42 | 43 | /******************************************************************************/ 44 | /***************************** Include Files **********************************/ 45 | /******************************************************************************/ 46 | #include 47 | 48 | /******************************************************************************/ 49 | /********************** Macros and Constants Definitions **********************/ 50 | /******************************************************************************/ 51 | 52 | #define AD5683_FAILURE -1 53 | #define AD5683_CMD_NOP 0x0 // No operation. 54 | #define AD5683_CMD_WR_IN_REG 0x1 // Write Input Register. 55 | #define AD5683_CMD_WR_DAC_REG 0x2 // Update DAC Register. 56 | #define AD5683_CMD_WR_DAC_IN_REG 0x3 // Write DAC and Input Register. 57 | #define AD5683_CMD_WR_CTRL_REG 0x4 // Write Control Register. 58 | #define AD5683_CMD_RB_IN_REG 0x5 // Readback input register. 59 | 60 | /*************************** Write Control Register Bits **********************/ 61 | 62 | #define AD5683_DCEN(x) (((((x) & 0x1) << 0) << 10) & 0xFC00) 63 | #define AD5683_CFG_GAIN(x) (((((x) & 0x1) << 1) << 10) & 0xFC00) 64 | #define AD5683_REF_EN(x) (((((x) & 0x1) << 2) << 10) & 0xFC00) 65 | #define AD5683_OP_MOD(x) (((((x) & 0x3) << 3) << 10) & 0xFC00) 66 | #define AD5683_SW_RESET(x) (((((x) & 0x1) << 5) << 10) & 0xFC00) 67 | 68 | /******************************************************************************/ 69 | /**************************** Variable Declarations ***************************/ 70 | /******************************************************************************/ 71 | struct ad5683_device { 72 | int slave_select_id; 73 | uint32_t dac_reg_value; 74 | }; 75 | 76 | enum ad5683_state { 77 | AD5683_DC_DISABLE, 78 | AD5683_DC_ENABLE 79 | }; 80 | 81 | enum ad5683_voltage_ref { 82 | AD5683_INT_REF_ON, 83 | AD5683_INT_REF_OFF 84 | }; 85 | 86 | enum ad5683_amp_gain { 87 | AD5683_AMP_GAIN_1, 88 | AD5683_AMP_GAIN_2 89 | }; 90 | 91 | enum ad5683_power_mode { 92 | AD5683_PWR_NORMAL, 93 | AD5683_PD_1K, 94 | AD5683_PD_100K, 95 | AD5683_PD_3STATE 96 | }; 97 | 98 | enum ad5683_reset { 99 | AD5683_RESET_DISABLE, 100 | AD5683_RESET_ENABLE 101 | }; 102 | 103 | /******************************************************************************/ 104 | /**************************** Function Declarations ***************************/ 105 | /******************************************************************************/ 106 | 107 | int32_t AD5683_write_cmd(struct ad5683_device *device, uint8_t cmd, 108 | uint16_t data); 109 | 110 | int32_t AD5683_readback_register(struct ad5683_device *device, uint32_t *data); 111 | 112 | int32_t AD5683_write_dac_value(struct ad5683_device *device, uint16_t data); 113 | 114 | int32_t AD5683_soft_reset(struct ad5683_device *device); 115 | 116 | int32_t AD5683_setup(struct ad5683_device *device, int slave_select_id); 117 | 118 | #endif /* _AD5683_H_ */ 119 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0411_example/AD7124_regs.cpp: -------------------------------------------------------------------------------- 1 | #include "AD7124_regs.h" 2 | 3 | struct ad7124_st_reg ad7124_regs[AD7124_REG_NO] = { 4 | {0x00, 0x00, 1, 2}, /* AD7124_Status */ 5 | {0x01, 0x0000, 2, 1}, /* AD7124_ADC_Control */ 6 | {0x02, 0x0000, 3, 2}, /* AD7124_Data */ 7 | {0x03, 0x0000, 3, 1}, /* AD7124_IOCon1 */ 8 | {0x04, 0x0000, 2, 1}, /* AD7124_IOCon2 */ 9 | {0x05, 0x02, 1, 2}, /* AD7124_ID */ 10 | {0x06, 0x0000, 3, 2}, /* AD7124_Error */ 11 | {0x07, 0x0040, 3, 1}, /* AD7124_Error_En */ 12 | {0x08, 0x00, 1, 2}, /* AD7124_Mclk_Count */ 13 | {0x09, 0x8001, 2, 1}, /* AD7124_Channel_0 */ 14 | {0x0A, 0x0001, 2, 1}, /* AD7124_Channel_1 */ 15 | {0x0B, 0x0001, 2, 1}, /* AD7124_Channel_2 */ 16 | {0x0C, 0x0001, 2, 1}, /* AD7124_Channel_3 */ 17 | {0x0D, 0x0001, 2, 1}, /* AD7124_Channel_4 */ 18 | {0x0E, 0x0001, 2, 1}, /* AD7124_Channel_5 */ 19 | {0x0F, 0x0001, 2, 1}, /* AD7124_Channel_6 */ 20 | {0x10, 0x0001, 2, 1}, /* AD7124_Channel_7 */ 21 | {0x11, 0x0001, 2, 1}, /* AD7124_Channel_8 */ 22 | {0x12, 0x0001, 2, 1}, /* AD7124_Channel_9 */ 23 | {0x13, 0x0001, 2, 1}, /* AD7124_Channel_10 */ 24 | {0x14, 0x0001, 2, 1}, /* AD7124_Channel_11 */ 25 | {0x15, 0x0001, 2, 1}, /* AD7124_Channel_12 */ 26 | {0x16, 0x0001, 2, 1}, /* AD7124_Channel_13 */ 27 | {0x17, 0x0001, 2, 1}, /* AD7124_Channel_14 */ 28 | {0x18, 0x0001, 2, 1}, /* AD7124_Channel_15 */ 29 | {0x19, 0x0860, 2, 1}, /* AD7124_Config_0 */ 30 | {0x1A, 0x0860, 2, 1}, /* AD7124_Config_1 */ 31 | {0x1B, 0x0860, 2, 1}, /* AD7124_Config_2 */ 32 | {0x1C, 0x0860, 2, 1}, /* AD7124_Config_3 */ 33 | {0x1D, 0x0860, 2, 1}, /* AD7124_Config_4 */ 34 | {0x1E, 0x0860, 2, 1}, /* AD7124_Config_5 */ 35 | {0x1F, 0x0860, 2, 1}, /* AD7124_Config_6 */ 36 | {0x20, 0x0860, 2, 1}, /* AD7124_Config_7 */ 37 | {0x21, 0x060180, 3, 1}, /* AD7124_Filter_0 */ 38 | {0x22, 0x060180, 3, 1}, /* AD7124_Filter_1 */ 39 | {0x23, 0x060180, 3, 1}, /* AD7124_Filter_2 */ 40 | {0x24, 0x060180, 3, 1}, /* AD7124_Filter_3 */ 41 | {0x25, 0x060180, 3, 1}, /* AD7124_Filter_4 */ 42 | {0x26, 0x060180, 3, 1}, /* AD7124_Filter_5 */ 43 | {0x27, 0x060180, 3, 1}, /* AD7124_Filter_6 */ 44 | {0x28, 0x060180, 3, 1}, /* AD7124_Filter_7 */ 45 | {0x29, 0x800000, 3, 1}, /* AD7124_Offset_0 */ 46 | {0x2A, 0x800000, 3, 1}, /* AD7124_Offset_1 */ 47 | {0x2B, 0x800000, 3, 1}, /* AD7124_Offset_2 */ 48 | {0x2C, 0x800000, 3, 1}, /* AD7124_Offset_3 */ 49 | {0x2D, 0x800000, 3, 1}, /* AD7124_Offset_4 */ 50 | {0x2E, 0x800000, 3, 1}, /* AD7124_Offset_5 */ 51 | {0x2F, 0x800000, 3, 1}, /* AD7124_Offset_6 */ 52 | {0x30, 0x800000, 3, 1}, /* AD7124_Offset_7 */ 53 | {0x31, 0x500000, 3, 1}, /* AD7124_Gain_0 */ 54 | {0x32, 0x500000, 3, 1}, /* AD7124_Gain_1 */ 55 | {0x33, 0x500000, 3, 1}, /* AD7124_Gain_2 */ 56 | {0x34, 0x500000, 3, 1}, /* AD7124_Gain_3 */ 57 | {0x35, 0x500000, 3, 1}, /* AD7124_Gain_4 */ 58 | {0x36, 0x500000, 3, 1}, /* AD7124_Gain_5 */ 59 | {0x37, 0x500000, 3, 1}, /* AD7124_Gain_6 */ 60 | {0x38, 0x500000, 3, 1}, /* AD7124_Gain_7 */ 61 | }; 62 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0411_example/AD7124_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef __AD7124_REGS_H__ 2 | #define __AD7124_REGS_H__ 3 | 4 | #include "AD7124.h" 5 | 6 | /*! Array holding the info for the ad7124 registers - address, initial value, 7 | size and access type. */ 8 | extern struct ad7124_st_reg ad7124_regs[AD7124_REG_NO]; 9 | 10 | #endif /* __AD7124_REGS_H__ */ 11 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0411_example/CN0411_example_uno.ino: -------------------------------------------------------------------------------- 1 | /***************************************************************************//** 2 | * @file CN0411_example.ino 3 | * @brief Main for the CN0411 Arduino demo. 4 | * @author Drimbarean Avram Andrei (Andrei.Drimbarean@analog.com) 5 | ******************************************************************************** 6 | * Copyright 2018(c) Analog Devices, Inc. 7 | * 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * - Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * - Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in 16 | * the documentation and/or other materials provided with the 17 | * distribution. 18 | * - Neither the name of Analog Devices, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * - The use of this software may or may not infringe the patent rights 22 | * of one or more patent holders. This license does not release you 23 | * from the requirement that you obtain separate licenses from these 24 | * patent holders to use this software. 25 | * - Use of the software either in source or binary form, must be run 26 | * on or directly connected to an Analog Devices Inc. component. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | *******************************************************************************/ 39 | 40 | 41 | #include "CN0411.h" 42 | #include 43 | #include "Timer.h" 44 | #include "Communication.h" 45 | 46 | struct cn0411_init_params cn0411_init_params= { 47 | CH_GAIN_RES_20M, 48 | ADC_SINGLE_CONV, 49 | RTD_RES_100, 50 | { 51 | GAIN_RES_20, 52 | GAIN_RES_200, 53 | GAIN_RES_2K, 54 | GAIN_RES_20K, 55 | GAIN_RES_200K, 56 | GAIN_RES_2M, 57 | GAIN_RES_20M 58 | }, 59 | OFFSET_RES_INIT, 60 | DAC_OUT_DEFAULT_VAL, 61 | EXC_DEFAULT_VAL, 62 | VR20S_DEFAULT_VAL, 63 | VR200S_DEFAULT_VAL, 64 | RDRES_DEFAULT_VAL, 65 | EXC_DEFAULT_VAL, 66 | CELL_CONST_NORMAL, 67 | TEMP_DEFAULT_VAL, 68 | VPP_DEFAULT_VAL, 69 | VINP_DEFAULT_VAL, 70 | VINN_DEFAULT_VAL, 71 | COND_DEFAULT_VAL, 72 | COMP_COND_DEFAULT_VAL, 73 | TDS_DEFAULT_VAL, 74 | { 75 | TEMP_COEFF_NACL, 76 | TDS_NACL 77 | } 78 | }; 79 | 80 | struct cn0411_device cn0411_dev; 81 | 82 | void setup() 83 | { 84 | uint32_t ret; 85 | 86 | timer_start(); /* Start the System Tick Timer. */ 87 | 88 | /* Initialize UART */ 89 | UART_Init (115200, 8); 90 | 91 | /* Initialize SPI */ 92 | SPI_Init(); 93 | if (ret == CN0411_FAILURE) 94 | return; 95 | 96 | /* Initialize CN0411 */ 97 | ret = CN0411_init(&cn0411_dev, cn0411_init_params); 98 | 99 | if (ret == CN0411_FAILURE) { 100 | Serial.print(F("CN0411 Initialization error!\n")); 101 | return; 102 | } 103 | } 104 | 105 | void loop() 106 | { 107 | CN0411_cmd_process(&cn0411_dev); /* Command line process */ 108 | } 109 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0411_example/Communication.h: -------------------------------------------------------------------------------- 1 | /* 2 | ***************************************************************************** 3 | * @file: Communication.h 4 | * @brief: 5 | * @version: $Revision$ 6 | * @date: $Date$ 7 | *----------------------------------------------------------------------------- 8 | * 9 | Copyright (c) 2015-2017 Analog Devices, Inc. 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | - Modified versions of the software must be conspicuously marked as such. 21 | - This software is licensed solely and exclusively for use with processors 22 | manufactured by or for Analog Devices, Inc. 23 | - This software may not be combined or merged with other code in any manner 24 | that would cause the software to become subject to terms and conditions 25 | which differ from those listed here. 26 | - Neither the name of Analog Devices, Inc. nor the names of its 27 | contributors may be used to endorse or promote products derived 28 | from this software without specific prior written permission. 29 | - The use of this software may or may not infringe the patent rights of one 30 | or more patent holders. This license does not release you from the 31 | requirement that you obtain separate licenses from these patent holders 32 | to use this software. 33 | 34 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY 35 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 36 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 37 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES 39 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL 40 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 41 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | * 46 | *****************************************************************************/ 47 | #ifndef _COMMUNICATION_H_ 48 | #define _COMMUNICATION_H_ 49 | 50 | #include 51 | 52 | /********************************* Internal defines ****************************/ 53 | #define UART_TX_BUFFER_SIZE 50 /* UART transmit buffer size */ 54 | #define UART_RX_BUFFER_SIZE 50 /* UART receive buffer size */ 55 | 56 | /* Execution status */ 57 | #define UART_SUCCESS 0 58 | #define UART_FAILURE -1 59 | #define UART_NO_TX_SPACE -2 60 | #define UART_NO_RX_SPACE -3 61 | 62 | /* UART status */ 63 | #define UART_TRUE 1 64 | #define UART_FALSE 0 65 | 66 | #define _CR 13 /* */ 67 | #define _LF 10 /* */ 68 | #define _SPC 32 /* */ 69 | #define _BS 8 /* */ 70 | 71 | #define READ_DATA_REG 0x58 72 | /****************************** Global Data ***********************************/ 73 | 74 | extern uint8_t uart_rcnt, uart_tpos, uart_tcnt; 75 | extern uint8_t uart_cmd, uart_tbusy; 76 | 77 | extern uint8_t uart_rx_buffer[UART_RX_BUFFER_SIZE]; 78 | extern uint8_t uart_tx_buffer[UART_TX_BUFFER_SIZE]; 79 | 80 | /****************************** Internal types *********************************/ 81 | 82 | /* Number of received bytes */ 83 | typedef enum { 84 | ONE_BYTE = 1, /* Read one byte */ 85 | TWO_BYTES /* Read two bytes */ 86 | } enReadBytes; 87 | 88 | 89 | /* Write data mode */ 90 | typedef enum { 91 | UART_WRITE_NO_INT = 1, /* Write data when interrupts are disabled */ 92 | UART_WRITE_IN_INT, /* Write data while in an interrupt routine */ 93 | UART_WRITE 94 | } enWriteData; 95 | 96 | /* SPI Definitions */ 97 | 98 | /* SPI Pins */ 99 | 100 | #define SPI1_PORT pADI_GP0 101 | 102 | /* SPI Pins SCLCK/MISO/MOSI */ 103 | 104 | #define SPI1_SCLK_PIN 0x02 105 | #define SPI1_SCLK_PIN_NUMBER PIN1 106 | #define SPI1_MISO_PIN 0x01 107 | #define SPI1_MISO_PIN_NUMBER PIN0 108 | #define SPI1_MOSI_PIN 0x04 109 | #define SPI1_MOSI_PIN_NUMBER PIN2 110 | 111 | /* CS_AD7124 - 0.4 - output */ 112 | 113 | #define CS_AD7124_PIN 9 114 | #define CS_AD7124_PIN_NUMBER PIN4 115 | 116 | /* CS_AD5683 - 0.3 - output */ 117 | 118 | #define CS_AD5683_PIN 10 119 | #define CS_AD5683_PIN_NUMBER PIN3 120 | 121 | /* SPI Functions */ 122 | 123 | void SPI_Init(); 124 | int32_t SPI_Write(uint8_t ui8_slave_id, uint8_t ui8_buffer[], 125 | uint8_t ui8_nr_bytes); 126 | int32_t SPI_Read(uint8_t ui8_slave_id, uint8_t ui8_buffer[], 127 | uint8_t ui8_nr_bytes); 128 | void UART_Init(long lBaudrate, int iBits); 129 | void UART_ReadChar(char *data); 130 | void UART_WriteChar(char data, enWriteData mode); 131 | void UART_WriteString(char *string); 132 | void AppPrintf(const char *fmt, ...); 133 | 134 | #endif /* INCLUDE_COMMUNICATION_H_ */ 135 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0411_example/Timer.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ******************************************************************************* 3 | * @file: Timer.c 4 | * @brief: 5 | * @version: $Revision$ 6 | * @date: $Date$ 7 | *------------------------------------------------------------------------------ 8 | * 9 | Copyright (c) 2014 Liviu Ionescu. 10 | 11 | Portions Copyright (c) 2017 Analog Devices, Inc. 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 27 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 28 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 29 | OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | 32 | #include "CN0411.h" 33 | #include "Timer.h" 34 | #include 35 | 36 | // ----------------------------------------------------------------------------- 37 | 38 | void 39 | timer_start (void) 40 | { 41 | cli(); /* stop interrupts */ 42 | 43 | /* set timer0 interrupt at 2kHz */ 44 | TCCR2A = 0; /* set entire TCCR0A register to 0 */ 45 | TCCR2B = 0; /* same for TCCR0B */ 46 | TCNT2 = 0; /* initialize counter value to 0 */ 47 | /* set compare match register for 2khz increments */ 48 | OCR2A = 20; /* = (16*10^6) / (2000*64) - 1 (must be <256) */ 49 | /* turn on CTC mode */ 50 | TCCR2A |= (1 << WGM01); 51 | /* Set CS01 and CS00 bits for 64 prescaler */ 52 | TCCR2B |= (1 << CS01) | (0 << CS00); 53 | /* enable timer compare interrupt */ 54 | TIMSK2 |= (1 << OCIE0A); 55 | 56 | sei(); /* start interrupts */ 57 | } 58 | 59 | void 60 | timer_sleep (timer_ticks_t ticks) 61 | { 62 | delay(ticks); 63 | } 64 | 65 | void timer_sleep_5uS(timer_ticks_t ticks) 66 | { 67 | timer_ticks_t i; 68 | 69 | if(ticks > (ARDUINO_MAX_MICROSECONDS_DELAY / 5)) 70 | return; 71 | 72 | for(i = 0; i < ticks; i++) { 73 | CN0411_pwm_gen(); 74 | delayMicroseconds(5); 75 | } 76 | } 77 | 78 | // ----- Timer2 Interrupt Handler ---------------------------------------------- 79 | 80 | ISR(TIMER2_COMPA_vect) 81 | { 82 | CN0411_pwm_gen(); 83 | } 84 | 85 | -------------------------------------------------------------------------------- /Arduino Uno R3/examples/CN0411_example/Timer.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ***************************************************************************** 3 | * @file: Timer.h 4 | * @brief: 5 | * @version: $Revision$ 6 | * @date: $Date$ 7 | *----------------------------------------------------------------------------- 8 | * 9 | Copyright (c) 2014 Liviu Ionescu. 10 | 11 | Portions Copyright (c) 2017 Analog Devices, Inc. 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 27 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 28 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 29 | OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | 32 | #ifndef TIMER_H_ 33 | #define TIMER_H_ 34 | 35 | // ---------------------------------------------------------------------------- 36 | 37 | #define ARDUINO_MAX_MICROSECONDS_DELAY 16383 38 | 39 | typedef uint32_t timer_ticks_t; 40 | 41 | extern void 42 | timer_start (void); 43 | 44 | extern void 45 | timer_sleep (timer_ticks_t ticks); 46 | 47 | void timer_sleep_5uS(timer_ticks_t ticks); 48 | 49 | // ---------------------------------------------------------------------------- 50 | 51 | #endif // TIMER_H_ 52 | -------------------------------------------------------------------------------- /Arduino Uno R3/libraries/AD5270/AD5270.cpp: -------------------------------------------------------------------------------- 1 | /* AD5270.c 2 | * 3 | * Created on: May 27, 2015 4 | * Author: BBUSHEY 5 | */ 6 | 7 | #include 8 | #include 9 | #include "AD5270.h" 10 | 11 | AD5270class AD5270; 12 | 13 | void AD5270class::AD5270_SPI_Configuration(void) 14 | { 15 | SPI.setBitOrder(MSBFIRST); // MSB to be sent first 16 | SPI.setDataMode(SPI_MODE3); // Set for clock rising edge, clock idles low 17 | SPI.setClockDivider(SPI_CLOCK_DIV128); // Set clock divider (optional) 18 | delay(100); 19 | } 20 | 21 | void AD5270class::writeAd5270 (uint8_t ui8command, uint16_t ui16value) 22 | { 23 | uint8_t ui8DacUpperCodes = 0; // Data register read MSB 24 | uint8_t ui8DacLowerCodes = 0; // Data register read MSB 25 | uint16_t ui16DacCodes = 0; 26 | 27 | if (ui8command == 1) 28 | { 29 | ui16DacCodes = (ui8command << 10); 30 | ui16DacCodes = (ui16DacCodes | (ui16value)); 31 | ui8DacLowerCodes = ui16DacCodes & 0xFF; 32 | ui8DacUpperCodes = (ui16DacCodes >> 8) & 0xFF; 33 | } 34 | if (ui8command == 5 || ui8command == 7 || ui8command == 9) 35 | { 36 | ui8DacLowerCodes = ui16value & 0xFF; 37 | ui8DacUpperCodes = (ui8command << 2); 38 | } 39 | if (ui8command == 0xF0) //SDO High Z prep 40 | { 41 | ui8DacLowerCodes = ui16value & 0xFF; 42 | ui8DacUpperCodes = (ui16value >> 8) & 0xFF; 43 | } 44 | if (ui8command == 0x0F) // SDO High Z 45 | { 46 | ui8DacLowerCodes = ui16value & 0xFF; 47 | ui8DacUpperCodes = (ui16value >> 8) & 0xFF; 48 | } 49 | digitalWrite(AD5270_SS,LOW); 50 | SPI.transfer(ui8DacUpperCodes); 51 | SPI.transfer(ui8DacLowerCodes); 52 | digitalWrite(AD5270_SS,HIGH); 53 | 54 | /*Serial.print("Digipot Resistor Code = "); //Debug serial prints 55 | Serial.println(ui16DacCodes); 56 | Serial.print("Digipot Upper 8 Bits = "); 57 | Serial.println(ui8DacUpperCodes); 58 | Serial.print("Digipot Lower 8 Bits = "); 59 | Serial.println(ui8DacLowerCodes);*/ 60 | } 61 | 62 | uint16_t AD5270class::readAd5270 (uint8_t ui8command) 63 | { 64 | uint8_t ui8DacUpperCodes = 0; // Data register read MSB 65 | uint8_t ui8DacLowerCodes = 0; // Data register read LSB 66 | uint8_t ui8DacReadUpper = 0; 67 | uint8_t ui8DacReadLower = 0; 68 | uint16_t ui16DacRead = 0; 69 | 70 | if ((ui8command != 1) || (ui8command != 5) || (ui8command != 7) || (ui8command != 9)) 71 | { 72 | ui8DacLowerCodes = 0; 73 | ui8DacUpperCodes = (ui8command << 2); 74 | 75 | digitalWrite(AD5270_SS,LOW); 76 | SPI.transfer(ui8DacUpperCodes); 77 | SPI.transfer(ui8DacLowerCodes); 78 | ui8DacReadUpper = SPI.transfer(0x00); //Data register read MSB 79 | ui8DacReadLower = SPI.transfer(0x00); //Data register read LSB 80 | digitalWrite(AD5270_SS,HIGH); 81 | 82 | ui16DacRead = ((ui8DacReadUpper << 8) | ui8DacReadLower) & 0x03FF; 83 | 84 | } 85 | 86 | return ui16DacRead; 87 | } -------------------------------------------------------------------------------- /Arduino Uno R3/libraries/AD5270/AD5270.h: -------------------------------------------------------------------------------- 1 | /* 2 | AD5270.h 3 | */ 4 | #ifndef AD5270_h 5 | #define AD5270_h 6 | 7 | #include 8 | 9 | /*****************************************************************************/ 10 | /******************************** Definitions *******************************/ 11 | /*****************************************************************************/ 12 | 13 | //Commands 14 | #define WRITE_RDAC 0x1 // Write to the RDAC Register 15 | #define READ_RDAC 0x2 // Read from the RDAC Register 16 | #define STORE_50TP 0x3 // Write to the RDAC to memory 17 | #define SW_RST 0x4 // Software reset to last memory location 18 | #define READ_50TP_CONTENTS 0x5 // Read the last memory contents 19 | #define READ_50TP_ADDRESS 0x6 // Read the last memory address 20 | #define WRITE_CTRL_REG 0x7 // Write to the control Register 21 | #define READ_CTRL_REG 0x8 // Read from the control Register 22 | #define SW_SHUTDOWN 0x9 // Software shutdown (0) - Normal, (1) - Shutdown 23 | 24 | #define HI_Z_PREP 0xF0 // Get the SDO line ready for High Z 25 | #define HI_Z 0x0F // Puts AD5270 into High Z mode 26 | 27 | //Pins 28 | #define AD5270_SS 6 // AD5270 SPI chip select 29 | 30 | class AD5270class 31 | { 32 | public: 33 | void writeAd5270 (uint8_t ui8command, uint16_t ui16value); 34 | uint16_t readAd5270 (uint8_t ui8address); 35 | void AD5270_SPI_Configuration(void); 36 | private: 37 | 38 | }; 39 | 40 | extern AD5270class AD5270; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Arduino Uno R3/libraries/AD7790/AD7790.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | AD7790.cpp - 3 | */ 4 | 5 | #include 6 | #include 7 | #include "AD7790.h" 8 | 9 | AD7790class AD7790; 10 | 11 | void AD7790class::AD7790_SPI_Configuration(void) 12 | { 13 | SPI.setBitOrder(MSBFIRST); // MSB to be sent first 14 | SPI.setDataMode(SPI_MODE3); // Set for clock rising edge, clock idles low 15 | SPI.setClockDivider(SPI_CLOCK_DIV128); // Set clock divider (optional) 16 | delay(100); 17 | } 18 | 19 | uint16_t AD7790class::readAd7790 (uint8_t ui8address) 20 | { 21 | uint8_t ui8AdcUpperCodes = 0; // Data register read MSB 22 | uint8_t ui8AdcLowerCodes = 0; // Data register read LSB 23 | uint16_t ui16AdcCodes = 0; 24 | 25 | if (ui8address == DATA_READ) 26 | { 27 | digitalWrite(AD7790_SS,LOW); 28 | SPI.transfer(ui8address); 29 | ui8AdcUpperCodes = SPI.transfer(0x00); //Data register read MSB 30 | ui8AdcLowerCodes = SPI.transfer(0x00); //Data register read LSB 31 | digitalWrite(AD7790_SS,HIGH); 32 | ui16AdcCodes = ((long)ui8AdcUpperCodes << 8) | ui8AdcLowerCodes; 33 | 34 | /*Serial.print("ADC Data Register Read : "); //Debug serial prints 35 | Serial.println(ui16AdcCodes,2);*/ 36 | 37 | /*Serial.print("ADC Upper 8 Bits : "); //Debug serial prints 38 | Serial.println(ui8AdcUpperCodes,2); 39 | Serial.print("ADC Lower 8 Bits : "); 40 | Serial.println(ui8AdcLowerCodes,2);*/ 41 | } 42 | else 43 | { 44 | digitalWrite(AD7790_SS,LOW); 45 | SPI.transfer(ui8address); 46 | ui8AdcLowerCodes = SPI.transfer(0x00); // register read 47 | digitalWrite(AD7790_SS,HIGH); 48 | ui16AdcCodes = ((long)ui8AdcUpperCodes << 8) | ui8AdcLowerCodes; 49 | 50 | /*Serial.print("ADC Register Being Read: "); //Debug serial prints 51 | Serial.println(ui8address); 52 | Serial.print(" Reading Register Value : "); 53 | Serial.println(ui16AdcCodes);*/ 54 | } 55 | 56 | return ui16AdcCodes; 57 | } 58 | 59 | void AD7790class::writeAd7790 (uint8_t ui8address, uint8_t ui8value) 60 | { 61 | 62 | if (ui8address != RESET) 63 | { 64 | digitalWrite(AD7790_SS,LOW); 65 | SPI.transfer(ui8address); 66 | SPI.transfer(ui8value); 67 | digitalWrite(AD7790_SS,HIGH); 68 | //Serial.println("Write Command"); //Debug serial prints 69 | } 70 | else 71 | { 72 | digitalWrite(AD7790_SS,LOW); 73 | SPI.transfer(ui8value); 74 | SPI.transfer(ui8value); 75 | SPI.transfer(ui8value); 76 | SPI.transfer(ui8value); 77 | digitalWrite(AD7790_SS,HIGH); 78 | //Serial.println("Reset Command"); //Debug serial prints 79 | } 80 | 81 | /*Serial.print("ADC Register "); //Debug serial prints 82 | Serial.print(ui8address); 83 | Serial.println("Written"); 84 | Serial.print("With Register Value "); 85 | Serial.println(ui8value);*/ 86 | } 87 | -------------------------------------------------------------------------------- /Arduino Uno R3/libraries/AD7790/AD7790.h: -------------------------------------------------------------------------------- 1 | /* 2 | AD7790.h - 3 | */ 4 | #ifndef AD7790_h 5 | #define AD7790_h 6 | 7 | #include 8 | 9 | /*****************************************************************************/ 10 | /************************** ADC Address Definitions **************************/ 11 | /*****************************************************************************/ 12 | 13 | //ADC Write Commands 14 | #define MODE_WRITE 0x10 // Write to the Mode Register 15 | #define FILTER_WRITE 0x20 // Write to the Filter Register 16 | 17 | //ADC Read Commands 18 | #define STATUS_READ 0x08 // Read from the Status Register 19 | #define MODE_READ 0x18 // Read from the Mode Register 20 | #define FILTER_READ 0x28 // Read from the Filter Register 21 | #define DATA_READ 0x38 // Read from the Data Register 22 | 23 | #define RESET 0xFF // Resets the chip to default 24 | 25 | //Pins 26 | #define AD7790_SS 8 // AD7790 SPI chip select 27 | 28 | class AD7790class 29 | { 30 | public: 31 | void writeAd7790 (uint8_t ui8address, uint8_t ui8value); 32 | uint16_t readAd7790 (uint8_t ui8address); 33 | void AD7790_SPI_Configuration(void); 34 | private: 35 | 36 | }; 37 | 38 | extern AD7790class AD7790; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /Arduino Uno R3/libraries/AD7791/AD7791.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | AD7791.cpp - 3 | */ 4 | 5 | #include 6 | #include 7 | #include "AD7791.h" 8 | 9 | AD7791class AD7791; 10 | 11 | void AD7791class::AD7791_SPI_Configuration(void) 12 | { 13 | SPI.setBitOrder(MSBFIRST); // MSB to be sent first 14 | SPI.setDataMode(SPI_MODE3); // Set for clock rising edge, clock idles low 15 | SPI.setClockDivider(SPI_CLOCK_DIV128); // Set clock divider (optional) 16 | delay(100); 17 | } 18 | 19 | uint32_t AD7791class::readAd7791 (uint8_t ui8address) 20 | { 21 | uint8_t ui8AdcUpperCodes = 0; // Data register bits 23-16 22 | uint8_t ui8AdcMiddleCodes = 0; // Data register bits 15-8 23 | uint8_t ui8AdcLowerCodes = 0; // Data register bits 7-0 24 | uint32_t ui32AdcCodes = 0; 25 | 26 | if (ui8address == DATA_READ) 27 | { 28 | digitalWrite(AD7791_SS,LOW); 29 | SPI.transfer(ui8address); 30 | ui8AdcUpperCodes = SPI.transfer(0x00); // Data register bits 23-16 31 | ui8AdcMiddleCodes = SPI.transfer(0x00); // Data register bits 15-8 32 | ui8AdcLowerCodes = SPI.transfer(0x00); // Data register bits 7-0 33 | digitalWrite(AD7791_SS,HIGH); 34 | ui32AdcCodes = ((long)ui8AdcUpperCodes << 16) | ((long)ui8AdcMiddleCodes << 8) | ui8AdcLowerCodes; 35 | 36 | /*Serial.print("ADC Data Register Read : "); //Debug serial prints 37 | Serial.println(ui32AdcCodes,2); 38 | Serial.print("ADC Bits 23-16 : "); 39 | Serial.println(ui8AdcUpperCodes,2); 40 | Serial.print("ADC Bits 15-8 : "); 41 | Serial.println(ui8AdcMiddleCodes,2); 42 | Serial.print("ADC Bits 7-0 : "); 43 | Serial.println(ui8AdcLowerCodes,2);*/ 44 | } 45 | else 46 | { 47 | digitalWrite(AD7791_SS,LOW); 48 | SPI.transfer(ui8address); 49 | ui8AdcLowerCodes = SPI.transfer(0x00); // register read 50 | digitalWrite(AD7791_SS,HIGH); 51 | ui32AdcCodes = ((long)ui8AdcUpperCodes << 16) | ((long)ui8AdcMiddleCodes << 8) | ui8AdcLowerCodes; 52 | 53 | /*Serial.print("ADC Register Being Read:"); //Debug serial prints 54 | Serial.println(ui8address); 55 | Serial.print(" Reading Register Value :"); 56 | Serial.println(ui32AdcCodes);*/ 57 | } 58 | 59 | return ui32AdcCodes; 60 | } 61 | 62 | void AD7791class::writeAd7791 (uint8_t ui8address, uint8_t ui8value) 63 | { 64 | 65 | if (ui8address != RESET) 66 | { 67 | digitalWrite(AD7791_SS,LOW); 68 | SPI.transfer(ui8address); 69 | SPI.transfer(ui8value); 70 | digitalWrite(AD7791_SS,HIGH); 71 | //Serial.println("Write Command"); //Debug serial prints 72 | } 73 | else 74 | { 75 | digitalWrite(AD7791_SS,LOW); 76 | SPI.transfer(ui8value); 77 | SPI.transfer(ui8value); 78 | SPI.transfer(ui8value); 79 | SPI.transfer(ui8value); 80 | digitalWrite(AD7791_SS,HIGH); 81 | //Serial.println("Reset Command"); //Debug serial prints 82 | } 83 | 84 | /*Serial.print("ADC Register "); //Debug serial prints 85 | Serial.print(ui8address); 86 | Serial.println("Written"); 87 | Serial.print("With Register Value "); 88 | Serial.println(ui8value);*/ 89 | } -------------------------------------------------------------------------------- /Arduino Uno R3/libraries/AD7791/AD7791.h: -------------------------------------------------------------------------------- 1 | /* 2 | AD7791.h - 3 | */ 4 | #ifndef AD7791_h 5 | #define AD7791_h 6 | 7 | #include 8 | 9 | /*****************************************************************************/ 10 | /************************** ADC Address Definitions **************************/ 11 | /*****************************************************************************/ 12 | 13 | //ADC Write Commands 14 | #define MODE_WRITE 0x10 // Write to the Mode Register 15 | #define FILTER_WRITE 0x20 // Write to the Filter Register 16 | 17 | //ADC Read Commands 18 | #define STATUS_READ 0x08 // Read from the Status Register 19 | #define MODE_READ 0x18 // Read from the Mode Register 20 | #define FILTER_READ 0x28 // Read from the Filter Register 21 | #define DATA_READ 0x38 // Read from the Data Register 22 | 23 | #define RESET 0xFF // Resets the chip to default 24 | 25 | //Pins 26 | #define AD7791_SS 8 // AD7791 SPI chip select 27 | 28 | class AD7791class 29 | { 30 | public: 31 | void writeAd7791 (uint8_t ui8address, uint8_t ui8value); 32 | uint32_t readAd7791 (uint8_t ui8address); 33 | void AD7791_SPI_Configuration(void); 34 | private: 35 | 36 | }; 37 | 38 | extern AD7791class AD7791; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /Arduino Uno R3/libraries/ADE9153A/README.md: -------------------------------------------------------------------------------- 1 | # ADE9153A Library 2 | 3 | [ADE9153A](https://www.analog.com/en/products/ade9153a.html) is the latest single phase energy measurement IC with mSure self-calibration. This library specifically targets the [EV-ADE9153ASHIELDZ](https://www.analog.com/en/design-center/evaluation-hardware-and-software/evaluation-boards-kits/EVAL-ADE9153A.html) shield evaluation board. 4 | 5 | There is example code available in the [examples](https://github.com/analogdevicesinc/arduino/tree/master/Arduino%20Uno%20R3/examples) section. 6 | 7 | ## Read Before Use 8 | To make the evaluation board easy to use, the library has some registers defined with non-default values. 9 | 10 | When using this ADE9153A library be sure to include both ADE9153A.h and ADE9153AAPI.h. 11 | 12 | ### Defaults 13 | Register definitions are found in the ADE9153AAPI.h. Be sure that these definitions are set up correctly for the applications, especially ADE9153A_ACCMODE which must be setup for 50Hz or 60Hz systems. 14 | 15 | ### Hardware 16 | The hardware has flexibility to use both 3.3V and 5V with the proper modifications as described in the [EV-ADE9153ASHIELDZ User Guide](https://www.analog.com/media/en/technical-documentation/user-guides/ev-ade9153ashieldz-ug-1253.pdf). 17 | 18 | For the simplest layout the IAN and IAP were reversed compared to the test circuit in the [ADE9153A Data Sheet](https://www.analog.com/media/en/technical-documentation/data-sheets/ade9153a.pdf). This means that a negative gain must be applied to AIGAIN, which can be seen in the [example code](https://github.com/analogdevicesinc/arduino/tree/master/Arduino%20Uno%20R3/examples). 19 | 20 | ## Support 21 | Feelfree to ask any questions on [EngineerZone](https://ez.analog.com/energy-metering) 22 | -------------------------------------------------------------------------------- /Arduino Uno R3/libraries/ADE9153A/keywords.txt: -------------------------------------------------------------------------------- 1 | ADE9153A KEYWORD1 2 | SPI_Init KEYWORD2 3 | SPI_Write_16 KEYWORD2 4 | SPI_Write_32 KEYWORD2 5 | SPI_Read_16 KEYWORD2 6 | SPI_Read_32 KEYWORD2 -------------------------------------------------------------------------------- /Arduino Uno R3/libraries/ADXL362-ADRZ/ADXL362-ARDZ.h: -------------------------------------------------------------------------------- 1 | /* 2 | ADXL362.h - Library for ADXL362 - Accelerometer 3 | Created by Analog Devices Inc. - Circuits from the Lab, May 2015. 4 | */ 5 | #ifndef ADXL362-ARDZ_h 6 | #define ADXL362-ARDZ_h 7 | 8 | #include "Arduino.h" 9 | 10 | #define SCAN_SENSOR_TIME 100 //used as a scan delay 11 | #define XDATA_L_REG 0x0E 12 | #define YDATA_L_REG 0x10 13 | #define ZDATA_L_REG 0x12 14 | #define TEMP_L_REG 0x14 15 | #define ADXL362_SS 7 // value of the CS pin assignment 16 | 17 | extern int16_t i16SensorX; 18 | extern int16_t i16SensorY; 19 | extern int16_t i16SensorZ; 20 | extern int16_t i16SensorT; 21 | 22 | class ADXL362class 23 | { 24 | public: 25 | void ADXL362_SPI_Configuration(void); 26 | void SensorINIT(void); 27 | void SensorWriteOneReg(byte address, byte value); 28 | unsigned int SensorReadOneReg(byte address); 29 | unsigned int SensorReadTwoReg(byte address); 30 | void ScanSensor(void); 31 | void StopSensor(void); 32 | void StartSensor(void); 33 | 34 | private: 35 | 36 | }; 37 | 38 | extern ADXL362class ADXL362; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /Arduino Uno R3/libraries/ST7565_LCD/ST7565R_LCD.h: -------------------------------------------------------------------------------- 1 | /* 2 | ST7565R.h - Library for ST7565R LCD - Graphical LCD Display 3 | Created by Analog Devices Inc. - Circuits from the Lab, May 2015. 4 | */ 5 | #ifndef ST7565R_h 6 | #define ST7565R_h 7 | 8 | #include "Arduino.h" 9 | 10 | //EVAL-ADXL362-ARDZ 11 | #define ST7565R_SS 8 // value of the CS pin assignment 12 | #define ST7565R_A0 3 // value of the A0 pin assignment 13 | //#define ST7565R_RST 10 // value of the RST pin assignment 14 | //#define ST7565R_BL 2 // value of the Backlight pin assignment 15 | 16 | // WiFi demo pins ONLY!! 17 | #define ST7565R_RST 6 // value of the RST pin assignment 18 | #define ST7565R_BL 4 // value of the Backlight pin assignment 19 | 20 | 21 | #define LCD_COLUMNS 128u 22 | #define LCD_PAGES 4u 23 | #define LCD_LINES 64u 24 | 25 | //#define UP_X 112 26 | //#define LEFT_X 104 27 | //#define RIGHT_X 120 28 | //#define DOWN_X 112 29 | //#define CENTER_X 112 30 | 31 | #define ACC_LIMIT 50 32 | 33 | 34 | class ST7565Rclass 35 | { 36 | public: 37 | void ST7565R_SPI_Configuration(void); 38 | void LcdINIT(void); 39 | void OutString(int ui8row, int ui8col, int *pi8str); 40 | void OutSymbol(int ui8row, int ui8col, int ui8width, const int *pui8symbol); 41 | void LcdFillPages(int ui8start, int ui8num, int ui8Data); 42 | void LcdSetLine(int ui8line); 43 | void writeCommand(int uicommand); 44 | void writeData(int uidata); 45 | void setLcdCursor(int uipage, int uicolumn); 46 | private: 47 | 48 | }; 49 | 50 | extern ST7565Rclass ST7565R; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Copyright 2015-2018(c) Analog Devices, Inc. 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the 13 | distribution. 14 | - Neither the name of Analog Devices, Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | - The use of this software may or may not infringe the patent rights 18 | of one or more patent holders. This license does not release you 19 | from the requirement that you obtain separate licenses from these 20 | patent holders to use this software. 21 | - Use of the software either in source or binary form, must be run 22 | on or directly connected to an Analog Devices Inc. component. 23 | 24 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A 26 | PARTICULAR PURPOSE ARE DISCLAIMED. 27 | 28 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY 30 | RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 31 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 33 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # arduino 2 | [![Build Status](https://dev.azure.com/AnalogDevices/OpenSource/_apis/build/status/analogdevicesinc.arduino?branchName=master)](https://dev.azure.com/AnalogDevices/OpenSource/_build/latest?definitionId=22&branchName=master) 3 | 4 | Arduino Sketches 5 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | - main 3 | - master 4 | - staging/* 5 | - dev/* 6 | 7 | pr: 8 | - main 9 | - master 10 | 11 | variables: 12 | runCondition: true 13 | targetBranch: $[ variables['System.PullRequest.TargetBranchName'] ] 14 | 15 | jobs: 16 | - job: LinuxBuilds 17 | strategy: 18 | matrix: 19 | astyle: 20 | imageName: 'ubuntu-latest' 21 | BUILD_TYPE: astyle 22 | TARGET_BRANCH: '$(targetBranch)' 23 | cppcheck: 24 | imageName: 'ubuntu-latest' 25 | BUILD_TYPE: cppcheck 26 | TARGET_BRANCH: '$(targetBranch)' 27 | 28 | pool: 29 | vmImage: $(imageName) 30 | steps: 31 | - checkout: self 32 | condition: eq(variables.runCondition, true) 33 | fetchDepth: 50 34 | clean: true 35 | persistCredentials: false 36 | - script: ./ci/run_build.sh 37 | condition: eq(variables.runCondition, true) 38 | displayName: 'Run $(BUILD_TYPE)' 39 | -------------------------------------------------------------------------------- /ci/lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TOP_DIR=${TOP_DIR:-'./'} 4 | 5 | command_exists() { 6 | local cmd=$1 7 | [ -n "$cmd" ] || return 1 8 | type "$cmd" >/dev/null 2>&1 9 | } 10 | 11 | ensure_command_exists() { 12 | local cmd="$1" 13 | local package="$2" 14 | [ -n "$cmd" ] || return 1 15 | [ -n "$package" ] || package="$cmd" 16 | ! command_exists "$cmd" || return 0 17 | # go through known package managers 18 | for pacman in apt-get brew yum ; do 19 | command_exists $pacman || continue 20 | $pacman install -y $package || { 21 | # Try an update if install doesn't work the first time 22 | $pacman -y update && \ 23 | $pacman install -y $package 24 | } 25 | return $? 26 | done 27 | return 1 28 | } 29 | 30 | ensure_command_exists wget 31 | ensure_command_exists sudo 32 | 33 | # Get the common stuff from no-OS 34 | [ -f ${TOP_DIR}/build/lib.sh ] || { 35 | mkdir -p ${TOP_DIR}/build 36 | wget https://raw.githubusercontent.com/analogdevicesinc/no-OS/master/ci/lib.sh \ 37 | -O ${TOP_DIR}/build/lib.sh 38 | } 39 | 40 | . ${TOP_DIR}/build/lib.sh 41 | 42 | # Call function from ${TOP_DIR}/build/lib.sh to download common scripts 43 | download_common_scripts 44 | -------------------------------------------------------------------------------- /ci/run_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | TOP_DIR="$(pwd)" 5 | 6 | sudo apt-get update 7 | 8 | . ./ci/lib.sh 9 | 10 | build_cppcheck() { 11 | . ./build/cppcheck.sh 12 | } 13 | 14 | build_astyle() { 15 | export ASTYLE_EXT_LIST=".cpp .hpp .ino" 16 | . ./build/astyle.sh 17 | } 18 | 19 | build_${BUILD_TYPE} 20 | --------------------------------------------------------------------------------