diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-01-12 14:54:41 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-01-12 14:54:41 +0000 |
| commit | fe92239d966f0219e8b7caf6335a776938b4e0e3 (patch) | |
| tree | 20acea40d77c5aff45e0f114302781f72ac4a67b /ESS1995i2c | |
| parent | 8bd4916d2b73c73f417f8f7034d8a0fa86aae6ac (diff) | |
tinkering
Diffstat (limited to 'ESS1995i2c')
| -rw-r--r-- | ESS1995i2c/ESS1995i2c.depend | 8 | ||||
| -rw-r--r-- | ESS1995i2c/ESS1995i2c.layout | 4 | ||||
| -rw-r--r-- | ESS1995i2c/electic.h | 10 | ||||
| -rw-r--r-- | ESS1995i2c/main.cpp | 112 |
4 files changed, 26 insertions, 108 deletions
diff --git a/ESS1995i2c/ESS1995i2c.depend b/ESS1995i2c/ESS1995i2c.depend index 29f5419..ac4554b 100644 --- a/ESS1995i2c/ESS1995i2c.depend +++ b/ESS1995i2c/ESS1995i2c.depend @@ -173,12 +173,13 @@ <stdio.h> "WString.h" -1322661310 source:/home/tim/workspace/electic/ESS1995i2c/main.cpp +1326379728 source:/home/tim/workspace/electic/ESS1995i2c/main.cpp "electic.h" -1322661364 /home/tim/workspace/electic/ESS1995i2c/electic.h +1326379810 /home/tim/workspace/electic/ESS1995i2c/electic.h <WProgram.h> "adapticsBT.h" + <Wire.h> 1319029257 source:/home/tim/workspace/electic/arduinoSrc0022/HardwareSerial.cpp <stdlib.h> @@ -257,3 +258,6 @@ 1319029257 source:/home/tim/workspace/electic/arduinoSrc0022/wiring_shift.c "wiring_private.h" +1293228745 /home/tim/workspace/electic/arduino_libs/Wire/Wire.h + <inttypes.h> + diff --git a/ESS1995i2c/ESS1995i2c.layout b/ESS1995i2c/ESS1995i2c.layout index fcf2550..73883f4 100644 --- a/ESS1995i2c/ESS1995i2c.layout +++ b/ESS1995i2c/ESS1995i2c.layout @@ -5,10 +5,10 @@ <Cursor position="1609" topLine="11" /> </File> <File name="electic.h" open="1" top="0" tabpos="2"> - <Cursor position="540" topLine="27" /> + <Cursor position="1320" topLine="0" /> </File> <File name="main.cpp" open="1" top="1" tabpos="1"> - <Cursor position="185" topLine="0" /> + <Cursor position="634" topLine="26" /> </File> <File name="../arduinoSrc0022/HardwareSerial.h" open="0" top="0" tabpos="0"> <Cursor position="0" topLine="40" /> diff --git a/ESS1995i2c/electic.h b/ESS1995i2c/electic.h index a04220f..bf31728 100644 --- a/ESS1995i2c/electic.h +++ b/ESS1995i2c/electic.h @@ -62,14 +62,4 @@ uint8_t CB_FREQinprest = 0b0; uint8_t CB_ADPext = 0b0; uint8_t CB_DCfs = 0b0; - -void SCLKcycle_W(); -void SCLKcycle_R(); -void startRead(); -void startWrite(); -void writeByte(uint8_t data); -void writeStartBit(); -void writeStopBit(); -uint8_t readByte(); -void writeDMM(); int main(); diff --git a/ESS1995i2c/main.cpp b/ESS1995i2c/main.cpp index 54aa879..efb8e65 100644 --- a/ESS1995i2c/main.cpp +++ b/ESS1995i2c/main.cpp @@ -7,6 +7,7 @@ http://arduino.cc/playground/Code/ATMELTWI i2c library seems to require a 'register address' - -ESS1995 doesn't need this? + it certainly doesn't define a register in control byte 1 of write message */ #include "electic.h" @@ -41,9 +42,20 @@ int main(){ */ digitalWrite(CS,HIGH); //select DMM - - - Wire.beginTransmission(ESS1995_ADDR); + uint8_t WB1,WB2,WB3,WB4; +/* + uint8_t WB1 = (CB_SHBP << 7) | (CB_function << 3) | (CB_VARCrange); + uint8_t WB2 = (CB_BUZfreq << 5) | (CB_ADCrate << 3) | (CB_FREQrange); + uint8_t WB3 = (CB_ACmode << 7) | (CB_EXTdiode << 4) | (CB_DCfs << 3) | (CB_LPFbw << 1) | (CB_FREQinprest); + uint8_t WB4 = (CB_PEAKmode << 7) | (CB_PCALmode << 6) | (CB_OPconf << 2) | (CB_ADPext); +*/ + Wire.beginTransmission(WRITE_ID); + Wire.send(WB1); + Wire.send(WB2); + Wire.send(WB3); + Wire.send(WB4); + //default reads + Wire.endTransmission(); uint16_t delayMillis=250; @@ -97,20 +109,12 @@ writeDMM(); while(1) { if (digitalRead(DATA_NEW)==HIGH){ //DMM is ready to send data - digitalWrite(OUTPUT1,HIGH); - digitalWrite(OUTPUT2,LOW); - startWrite(); - writeStartBit(); - writeByte(READ_ID); + Wire.beginTransmission(READ_ID); if (digitalRead(DATA_NEW)==LOW){ //ID confirmed - digitalWrite(OUTPUT2,HIGH); - startRead(); for (int i=0;i<10;i++) { - data[i] = readByte(); + data[i] = Wire.receive(); } - //stop bit comes from the MPU? does seem to be necessary. - startWrite(); - writeStopBit(); + Wire.endTransmission(); //parse data DB_STATUS=data[0]; @@ -177,85 +181,5 @@ writeDMM(); //delay(delayMillis); } } -void startWrite() { - pinMode(SDATA,OUTPUT); - digitalWrite(SCLK, HIGH); -} -void startRead() { - pinMode(SDATA,INPUT); - digitalWrite(SCLK, HIGH); -} -void SCLKcycle_W() { - //insert a high clock cycle, normally LOW - delayMicroseconds(START_DELAY); - digitalWrite(SCLK, HIGH); - delayMicroseconds(CLOCK_DELAY); - digitalWrite(SCLK, LOW); - delayMicroseconds(START_DELAY); -} -void SCLKcycle_R() { - //insert a low clock cycle, normally HIGH - delayMicroseconds(START_DELAY); - digitalWrite(SCLK, LOW); - delayMicroseconds(CLOCK_DELAY); - digitalWrite(SCLK, HIGH); - delayMicroseconds(START_DELAY); -} -void writeByte(uint8_t data){ - - for (uint8_t i=0,bit=7;i<8;i++,bit--) { - digitalWrite(SDATA,(data>>bit)&0b01); - SCLKcycle_W(); - } - digitalWrite(SDATA,HIGH); //ACK/ stopbit should be HIGH? - SCLKcycle_W(); //ACK INTERVAL -} -void writeStopBit(){ - digitalWrite(SDATA,LOW); //prepare SDATA - delayMicroseconds(START_DELAY); - digitalWrite(SCLK,HIGH); - delayMicroseconds(START_DELAY); - digitalWrite(SDATA,HIGH); //stop bit -} -void writeStartBit(){ - digitalWrite(SDATA, HIGH); //should be anyway - digitalWrite(SCLK, HIGH); - delayMicroseconds(START_DELAY); - digitalWrite(SDATA,LOW); //start bit - delayMicroseconds(START_DELAY); - digitalWrite(SCLK, LOW); - delayMicroseconds(START_DELAY); -} -uint8_t readByte(){ - uint8_t data=0; - uint8_t thisdata; - //delayMicroseconds(START_DELAY); - //digitalWrite(SCLK, HIGH); //load first bit - delayMicroseconds(START_DELAY); - for (uint8_t i=0,bit=7;i<8;i++,bit--) { - thisdata=digitalRead(SDATA); - data = data | (thisdata<<bit); - digitalWrite(OUTPUT1,thisdata); - SCLKcycle_R(); - } - SCLKcycle_R(); //ACK - return data; -} -void writeDMM(){ - uint8_t WB1 = (CB_SHBP << 7) | (CB_function << 3) | (CB_VARCrange); - uint8_t WB2 = (CB_BUZfreq << 5) | (CB_ADCrate << 3) | (CB_FREQrange); - uint8_t WB3 = (CB_ACmode << 7) | (CB_EXTdiode << 4) | (CB_DCfs << 3) | (CB_LPFbw << 1) | (CB_FREQinprest); - uint8_t WB4 = (CB_PEAKmode << 7) | (CB_PCALmode << 6) | (CB_OPconf << 2) | (CB_ADPext); - - startWrite(); - writeStartBit(); - writeByte(WRITE_ID); - writeByte(WB1); - writeByte(WB2); - writeByte(WB3); - writeByte(WB4); - writeStopBit(); - -} |
