Elmaddin Guliyev
/
ADS1299
configuring and reading adc1299 using spi interface
main.cpp@0:99e31762ab2f, 2019-05-29 (annotated)
- Committer:
- eguliyev
- Date:
- Wed May 29 03:43:46 2019 +0000
- Revision:
- 0:99e31762ab2f
how to read texas instrument adc1299 using nucleo f4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eguliyev | 0:99e31762ab2f | 1 | #include "ads1299.h" |
eguliyev | 0:99e31762ab2f | 2 | #include "spi_slave.h" |
eguliyev | 0:99e31762ab2f | 3 | #include "mbed.h" |
eguliyev | 0:99e31762ab2f | 4 | |
eguliyev | 0:99e31762ab2f | 5 | DigitalOut CLKSEL(PB_0); |
eguliyev | 0:99e31762ab2f | 6 | //DigitalOut STRT(PA_3); |
eguliyev | 0:99e31762ab2f | 7 | //DigitalOut PWDN(PC_0); |
eguliyev | 0:99e31762ab2f | 8 | //DigitalOut RST(PA_0); |
eguliyev | 0:99e31762ab2f | 9 | DigitalOut LED(PC_6); |
eguliyev | 0:99e31762ab2f | 10 | Serial pc(USBTX, USBRX); |
eguliyev | 0:99e31762ab2f | 11 | |
eguliyev | 0:99e31762ab2f | 12 | int main() { |
eguliyev | 0:99e31762ab2f | 13 | |
eguliyev | 0:99e31762ab2f | 14 | SPI_INIT(); |
eguliyev | 0:99e31762ab2f | 15 | RSET(); |
eguliyev | 0:99e31762ab2f | 16 | wait_ms(1000); |
eguliyev | 0:99e31762ab2f | 17 | SDATAC(); |
eguliyev | 0:99e31762ab2f | 18 | wait_us(20); |
eguliyev | 0:99e31762ab2f | 19 | WREG(ADS129X_REG_CONFIG3,0x00); |
eguliyev | 0:99e31762ab2f | 20 | wait_us(20); |
eguliyev | 0:99e31762ab2f | 21 | WREG(ADS129X_REG_CONFIG1,0x94); |
eguliyev | 0:99e31762ab2f | 22 | wait_us(20); |
eguliyev | 0:99e31762ab2f | 23 | WREG(ADS129X_REG_CONFIG4,0x08); |
eguliyev | 0:99e31762ab2f | 24 | wait_us(20); |
eguliyev | 0:99e31762ab2f | 25 | WREG(0x14,0x80); |
eguliyev | 0:99e31762ab2f | 26 | wait_us(20); |
eguliyev | 0:99e31762ab2f | 27 | WREG(ADS129X_REG_CONFIG1,0x2); |
eguliyev | 0:99e31762ab2f | 28 | wait_us(20); |
eguliyev | 0:99e31762ab2f | 29 | for (int i = 1; i <= 9; i++) { |
eguliyev | 0:99e31762ab2f | 30 | configChannel(i, false, ADS129X_GAIN_1X, ADS129X_MUX_SHORT); |
eguliyev | 0:99e31762ab2f | 31 | } |
eguliyev | 0:99e31762ab2f | 32 | |
eguliyev | 0:99e31762ab2f | 33 | |
eguliyev | 0:99e31762ab2f | 34 | /*SLV_INIT(); |
eguliyev | 0:99e31762ab2f | 35 | wait_us(1); |
eguliyev | 0:99e31762ab2f | 36 | */ |
eguliyev | 0:99e31762ab2f | 37 | /* |
eguliyev | 0:99e31762ab2f | 38 | CLKSEL = 1; |
eguliyev | 0:99e31762ab2f | 39 | wait_us(5); |
eguliyev | 0:99e31762ab2f | 40 | |
eguliyev | 0:99e31762ab2f | 41 | STRT = 0; |
eguliyev | 0:99e31762ab2f | 42 | PWDN = 1; |
eguliyev | 0:99e31762ab2f | 43 | RST = 1; |
eguliyev | 0:99e31762ab2f | 44 | wait_ms(100); |
eguliyev | 0:99e31762ab2f | 45 | |
eguliyev | 0:99e31762ab2f | 46 | RST = 0; |
eguliyev | 0:99e31762ab2f | 47 | RST = 1; |
eguliyev | 0:99e31762ab2f | 48 | |
eguliyev | 0:99e31762ab2f | 49 | wait_ms(1); |
eguliyev | 0:99e31762ab2f | 50 | //SDATAC(); // device wakes up in RDATAC mode, so send stop signal |
eguliyev | 0:99e31762ab2f | 51 | */ |
eguliyev | 0:99e31762ab2f | 52 | //WREG(ADS129X_REG_CONFIG1, ADS129X_SAMPLERATE_512); |
eguliyev | 0:99e31762ab2f | 53 | // WREG(ADS129X_REG_CONFIG3, (1<<ADS129X_BIT_PD_REFBUF) | (1<<6)); |
eguliyev | 0:99e31762ab2f | 54 | // WREG(0x14,0x80); |
eguliyev | 0:99e31762ab2f | 55 | // WREG(ADS129X_REG_CONFIG2, (1<<ADS129X_BIT_INT_TEST) | ADS129X_TEST_FREQ_1HZ); |
eguliyev | 0:99e31762ab2f | 56 | |
eguliyev | 0:99e31762ab2f | 57 | // for (int i = 1; i <= 9; i++) { |
eguliyev | 0:99e31762ab2f | 58 | // configChannel(i, false, ADS129X_GAIN_1X, ADS129X_MUX_NORMAL); |
eguliyev | 0:99e31762ab2f | 59 | // } |
eguliyev | 0:99e31762ab2f | 60 | |
eguliyev | 0:99e31762ab2f | 61 | wait_ms(1); |
eguliyev | 0:99e31762ab2f | 62 | //STRT = 1; |
eguliyev | 0:99e31762ab2f | 63 | // RDATAC(); |
eguliyev | 0:99e31762ab2f | 64 | // START(); |
eguliyev | 0:99e31762ab2f | 65 | |
eguliyev | 0:99e31762ab2f | 66 | LED=1; |
eguliyev | 0:99e31762ab2f | 67 | |
eguliyev | 0:99e31762ab2f | 68 | while(1){ |
eguliyev | 0:99e31762ab2f | 69 | |
eguliyev | 0:99e31762ab2f | 70 | char value[3]; |
eguliyev | 0:99e31762ab2f | 71 | long buffer[9]; |
eguliyev | 0:99e31762ab2f | 72 | START(); |
eguliyev | 0:99e31762ab2f | 73 | if(getData(buffer)){ |
eguliyev | 0:99e31762ab2f | 74 | for(int channel = 1; channel < 9; channel++) { |
eguliyev | 0:99e31762ab2f | 75 | |
eguliyev | 0:99e31762ab2f | 76 | value[0] = (char) (buffer[channel]>>16); |
eguliyev | 0:99e31762ab2f | 77 | value[1] = (char) (buffer[channel]>>8); |
eguliyev | 0:99e31762ab2f | 78 | value[2] = (char) (buffer[channel]); |
eguliyev | 0:99e31762ab2f | 79 | // SLV_SEND(value[0],value[1],value[2]); |
eguliyev | 0:99e31762ab2f | 80 | |
eguliyev | 0:99e31762ab2f | 81 | } |
eguliyev | 0:99e31762ab2f | 82 | |
eguliyev | 0:99e31762ab2f | 83 | } |
eguliyev | 0:99e31762ab2f | 84 | |
eguliyev | 0:99e31762ab2f | 85 | } |
eguliyev | 0:99e31762ab2f | 86 | |
eguliyev | 0:99e31762ab2f | 87 | |
eguliyev | 0:99e31762ab2f | 88 | } |
eguliyev | 0:99e31762ab2f | 89 | |
eguliyev | 0:99e31762ab2f | 90 |