![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Control Code with I/O and ADC working
Diff: LTC2487/LTC2487.cpp
- Revision:
- 12:1cada1fe4743
- Parent:
- 7:8a5e65e63e2a
- Child:
- 13:604e6933366f
--- a/LTC2487/LTC2487.cpp Wed Mar 28 01:25:07 2018 +0000 +++ b/LTC2487/LTC2487.cpp Mon May 07 03:38:15 2018 +0000 @@ -2,17 +2,26 @@ #include "LTC2487.h" #include "MODSERIAL.h" -MODSERIAL pc3(USBTX, USBRX); namespace { const uint8_t I2C_WRITE = 0x00; const uint8_t I2C_READ = 0x01; - //Channel addresses - //0b10110000 ch0 --> 0xb0 - //0b10111000 ch1 --> 0xb8 - //0b10110001 ch2 --> 0xb1 - //0b10111001 ch3 --> 0xb9 + //Channel addresses (first two bits are fixed) + //0b10 EN SGL ODD A2 A1 A0 + //0b10 1 1 0 0 0 0 ch0 --> 0xb0 + //0b10 1 1 1 0 0 0 ch1 --> 0xb8 + //0b10 1 1 0 0 0 1 ch2 --> 0xb1 + //0b10 1 1 1 0 0 1 ch3 --> 0xb9 + + + //Config Section + // EN2 IM FA FB SPD GS2 GS1 GS0 + // 1 0 0 0 0 0 1 0 //Initial + // 1 0 0 0 1 0 1 1 //New Attempt with same gain (8x) + // 1 0 0 0 1 0 0 0 //New Attempt with unity gain (1x) + + const uint8_t CHNL_0 = 0xb0; const uint8_t CHNL_1 = 0xb8; const uint8_t CHNL_2 = 0xb1; @@ -32,7 +41,7 @@ char ADC_channel[1]; char ADC_data_rx[3]; char ADC_config[1]; - ADC_config[0] = 0x82; + ADC_config[0] = 0b10001000;//0x82; //0b10000010 //select channel to read switch (chnl){ @@ -60,6 +69,7 @@ wait(0.08); //Read data from selected channel --> 24bits --> 23bit=SIGN 22bit=MSB 21-7bits=DATA 5-0bits=JUNK i2c.read((addrI2C<<1)|(I2C_READ), ADC_data_rx, 3); + //must wait, otherwise breaks... wait(0.08); //Stitch together the bytes into a 24bit value unsigned long data = (ADC_data_rx[0] << 16) | (ADC_data_rx[1] << 8)| ADC_data_rx[2];