summaryrefslogtreecommitdiff
path: root/ESS1995i2c/electic.h
blob: a04220f032e3852f1b272d6c910238003d2a923c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
    ESS1995 communications test

    should the bitfields be parsed in the MCU or the app?

    the device needs to be able to do the ranging itself.

    data format-

    ACK is necessary

    write per read? or is it a delay thing


*/

#include <WProgram.h> //main Arduino header file
#include "adapticsBT.h"
#include <Wire.h>

#define DATA_NEW 2
#define SCLK 3
#define SDATA 4
#define CS 5

//feedback leds
#define OUTPUT1 12
#define OUTPUT2 13

#define WRITE_ID 0b11001000
#define READ_ID 0b11001001

#define ESS1995_ADDR 0b1100100

//clock delays are doubled for 8MHZ chip - CPUSPD isnt working
//6 and 3 = 83kHz, doesn't work with ISP plugged in
//500Hz works with ISP (sometimes)

#define CLOCK_DELAY 20
#define START_DELAY 10

const uint16_t ELECTIC_ID = 0xF0;
uint8_t packetSize = 7;
bool connected=false;

uint8_t data[10];

//default write values
uint8_t CB_SHBP = 0b0;
uint8_t CB_function = 0b0000; //0b0000 voltage mode
uint8_t CB_VARCrange = 0b000; //0b001 6v
uint8_t CB_FREQrange = 0b000;
uint8_t CB_BUZfreq = 0b000;
uint8_t CB_ADCrate = 0b00; //0b11 fastest 50hz
uint8_t CB_ACmode = 0b0;
uint8_t CB_PEAKmode = 0b0;
uint8_t CB_PCALmode = 0b0;
uint8_t CB_LPFbw = 0b000;
uint8_t CB_EXTdiode = 0b0;
uint8_t CB_OPconf = 0b00;
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();