| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC2222_interrupt_driven_read.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC2222AB Demonstration Board.
3 LTC2508: 32-Bit Over-Sampling ADC with Configurable Digital Filter
4
5 @verbatim
6
7 NOTES
8
9 This code is used in the case where DRDY triggers a hardware interrupt on Linduino,
10 and then the data is read. This makes data acquisition faster.
11 Set the terminal baud rate to 115200 and select the newline terminator.
12 Provide an external voltage supply of +/-9V or 10 V.
13 Drive MCLK with an external CLK source. Connect DRDY to INT1 pin. Connect
14 QUIKEVAL_GPIO pin to the SYNC pin.
15 16 bits of configuration data: 1 0 0 0 0 0 0 0 0 SEL0 SEL1 0 0 0 0 0
16
17 In the Linduino code, data is continuously captured in the interrupt service
18 routine and printed out to the serial console as hex values. Converting the data
19 to voltage can be done later. The serially printed out data is logged into a
20 file using TeraTerm. The data is read out, converted to voltage and plotted
21 using a Python script.
22
23 USER INPUT DATA FORMAT:
24 decimal : 1024
25 hex : 0x400
26 octal : 02000 (leading 0 "zero")
27 binary : B10000000000
28 float : 1024.0
29
30 @endverbatim
31
32 http://www.linear.com/product/LTC2508
33
34 http://www.linear.com/product/LTC2508#demoboards
35
36
37 Copyright 2018(c) Analog Devices, Inc.
38
39 All rights reserved.
40
41 Redistribution and use in source and binary forms, with or without
42 modification, are permitted provided that the following conditions are met:
43 - Redistributions of source code must retain the above copyright
44 notice, this list of conditions and the following disclaimer.
45 - Redistributions in binary form must reproduce the above copyright
46 notice, this list of conditions and the following disclaimer in
47 the documentation and/or other materials provided with the
48 distribution.
49 - Neither the name of Analog Devices, Inc. nor the names of its
50 contributors may be used to endorse or promote products derived
51 from this software without specific prior written permission.
52 - The use of this software may or may not infringe the patent rights
53 of one or more patent holders. This license does not release you
54 from the requirement that you obtain separate licenses from these
55 patent holders to use this software.
56 - Use of the software either in source or binary form, must be run
57 on or directly connected to an Analog Devices Inc. component.
58
59 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
60 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
61 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
63 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
64 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
65 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
66 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
67 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
68 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 */
70
71 /*! @file
72 @ingroup LTC2508
73 */
74
75
76 #include <Arduino.h>
77 #include "LT_I2C.h"
78 #include "LT_SPI.h"
79 #include "UserInterface.h"
80 #include "QuikEval_EEPROM.h"
81 #include "Linduino.h"
82 #include <Wire.h>
83 #include <stdint.h>
84 #include <SPI.h>
85 #include "LTC2508.h"
86
87 float VREF = 5.0;
88 uint16_t global_config_data = CONFIG_DF_256;
89
90 // Function Declarations
91 void sneaker_port_init();
92 void initialise_i2c_data(uint16_t value, uint8_t i2c_data[48]);
93
94 const byte interruptPin = 0;
95
96 // Setup function
97 void setup()
98 {
99 Serial.begin(115200); // Initialize the serial port to the PC
100 TIMSK0 &= ~(1<<TOIE0); // Timer Interrupt Overflow Enable = 0
101 sneaker_port_init(); // Send configuration data through sneaker port and a SYNC pulse
102 attachInterrupt(interruptPin, read_data_ISR, FALLING);
103 }
104
105
106 // Loop function
107 void loop()
108 {
109
110 }
111
112 void read_data_ISR()
113 {
114 uint8_t data;
115 output_low(QUIKEVAL_CS); //! 1) Pull CS low
116
117 data = SPI.transfer(0);
118 if (data < 16)
119 Serial.print("0");
120 Serial.print(data, HEX); //! 2) Read and send byte array
121
122 data = SPI.transfer(0);
123 if (data < 16)
124 Serial.print("0");
125 Serial.print(data, HEX); //! 2) Read and send byte array
126
127 data = SPI.transfer(0);
128 if (data < 16)
129 Serial.print("0");
130 Serial.print(data, HEX); //! 2) Read and send byte array
131
132 data = SPI.transfer(0);
133 if (data < 16)
134 Serial.print("0");
135 Serial.print(data, HEX); //! 2) Read and send byte array
136
137 data = SPI.transfer(0);
138 if (data < 16)
139 Serial.print("0");
140 Serial.print(data, HEX); //! 2) Read and send byte array
141
142 /*Serial.print(SPI.transfer(0), HEX); //! 2) Read and send byte array
143 Serial.print(SPI.transfer(0), HEX); //! 2) Read and send byte array
144 Serial.print(SPI.transfer(0), HEX); //! 2) Read and send byte array
145 Serial.print(SPI.transfer(0), HEX); //! 2) Read and send byte array
146 Serial.print(SPI.transfer(0), HEX); //! 2) Read and send byte array
147 */
148 Serial.print("\n");
149
150 output_high(QUIKEVAL_CS); //! 3) Pull CS high
151 }
152
153
154 //! Send configuration data through sneaker port
155 // Send I2C data to sneaker port to bit bang WRIN_I2C(CS) at P2,
156 // SCK at P5 and SDI at P6.
157 //! Send a SYNC pulse after configuration.
158 void sneaker_port_init()
159 {
160 uint8_t i;
161 uint16_t config_value = global_config_data;
162 uint8_t i2c_data[48]; // 48 bytes of data: 3 bytes each for 16 bits
163
164 quikeval_I2C_init(); // I2C Mode at 100kHz
165 quikeval_I2C_connect(); // Connect I2C to main data port
166 initialise_i2c_data(config_value, i2c_data); // Populate i2c_data array with values to bit bang P3, P5, P6
167
168 i2c_write_byte(SNEAKER_PORT_ADDRESS, CS_LOW); // P3 = 0 pulls WRIN_CS low
169
170 for (i = 0; i < 48; ++i)
171 {
172 i2c_write_byte(SNEAKER_PORT_ADDRESS, i2c_data[i]); // Sending configuration data
173 }
174 i2c_write_byte(SNEAKER_PORT_ADDRESS, CS_HIGH); // P3 = 1 pulls WRIN_CS high
175
176 // Send a SYNC pulse and leave it low
177 pinMode(QUIKEVAL_GPIO, OUTPUT); // Make SYNC pin on output mode
178 digitalWrite(QUIKEVAL_GPIO, LOW); // SYNC is connected to GPIO pin of the QuikEval connector
179 digitalWrite(QUIKEVAL_GPIO, HIGH);
180 digitalWrite(QUIKEVAL_GPIO, LOW);
181
182 //quikeval_SPI_init(); // SPI Mode for QuikEval connector - default is 1 MHz
183 spi_enable(SPI_CLOCK_DIV2); //! 1) Configure the spi port for 8MHz SCK
184 quikeval_SPI_connect();
185 }
186
187 // Create the array of 3 bytes each for 16 bits sneaker port data
188 void initialise_i2c_data(uint16_t value, uint8_t i2c_data[48])
189 {
190 uint8_t i;
191 uint8_t set_bit;
192 uint8_t *p = i2c_data;
193 for (i = 0; i < 16; ++i)
194 {
195 set_bit = (value >> i) & 0x01;
196 if (set_bit)
197 {
198 *p++ = 0x40;
199 *p++ = 0x60;
200 *p++ = 0x40;
201 }
202 else
203 {
204 *p++ = 0x00;
205 *p++ = 0x20;
206 *p++ = 0x00;
207 }
208 }
209
210 Serial.print("\n");
211 }
212
213
sneaker_port_init
static void sneaker_port_init()
Send configuration data through sneaker port.
Definition: DC2222_interrupt_driven_read.ino:158
read_data_ISR
static void read_data_ISR()
Definition: DC2222_interrupt_driven_read.ino:112
i2c_write_byte
int8_t i2c_write_byte(uint8_t address, uint8_t value)
Write "value" byte to device at "address".
Definition: LT_I2C.cpp:109
CS_HIGH
#define CS_HIGH
Definition: LTC2508.h:70
initialise_i2c_data
static void initialise_i2c_data(uint16_t value, uint8_t i2c_data[48])
Definition: DC2222_interrupt_driven_read.ino:188
output_high
#define output_high(pin)
Set "pin" high.
Definition: Linduino.h:75
Linduino.h
Header File for Linduino Libraries and Demo Code.
spi_enable
void spi_enable(uint8_t spi_clock_divider)
Setup the processor for hardware SPI communication.
Definition: LT_SPI.cpp:160
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
loop
static void loop()
Definition: DC2222_interrupt_driven_read.ino:107
setup
static void setup()
Definition: DC2222_interrupt_driven_read.ino:97
LTC2508.h
LTC2508: 32-Bit Over-Sampling ADC with Configurable Digital Filter.
QUIKEVAL_GPIO
#define QUIKEVAL_GPIO
Linduino QuikEval GPIO pin (QuikEval connector pin 14) connects to Arduino pin 9. ...
Definition: Linduino.h:56
output_low
#define output_low(pin)
Set "pin" low.
Definition: Linduino.h:72
QuikEval_EEPROM.h
QuikEval EEPROM Library.
interruptPin
const byte interruptPin
Definition: DC2222_interrupt_driven_read.ino:94
global_config_data
static uint16_t global_config_data
Definition: DC2222_interrupt_driven_read.ino:88
CS_LOW
#define CS_LOW
Definition: LTC2508.h:69
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
CONFIG_DF_256
#define CONFIG_DF_256
Definition: LTC2508.h:64
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
quikeval_SPI_connect
void quikeval_SPI_connect()
Connect SPI pins to QuikEval connector through the Linduino MUX. This will disconnect I2C...
Definition: LT_SPI.cpp:138
UserInterface.h
VREF
static float VREF
Definition: DC2222_interrupt_driven_read.ino:87
quikeval_I2C_init
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
quikeval_I2C_connect
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2C.cpp:401
i
static int i
Definition: DC2430A.ino:184
QUIKEVAL_CS
#define QUIKEVAL_CS
QuikEval CS pin (SPI chip select on QuikEval connector pin 6) connects to Arduino SS pin...
Definition: Linduino.h:57
SNEAKER_PORT_ADDRESS
#define SNEAKER_PORT_ADDRESS
Definition: LTC2508.h:62