808
Dependents: Chromatograph_Mobile
ads1248.cpp@0:1b92bdad27f6, 2020-08-08 (annotated)
- Committer:
- nikmaos
- Date:
- Sat Aug 08 18:29:32 2020 +0000
- Revision:
- 0:1b92bdad27f6
- Child:
- 1:54015254fc18
808
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikmaos | 0:1b92bdad27f6 | 1 | #include "ads1248.h" |
nikmaos | 0:1b92bdad27f6 | 2 | |
nikmaos | 0:1b92bdad27f6 | 3 | unsigned char ADS1248SleepCommand( void ) |
nikmaos | 0:1b92bdad27f6 | 4 | { |
nikmaos | 0:1b92bdad27f6 | 5 | DS1248_CS = 0; |
nikmaos | 0:1b92bdad27f6 | 6 | SPI1MasterTransferByte(DS1248_SLEEP_COMMAND); |
nikmaos | 0:1b92bdad27f6 | 7 | DS1248_CS=1; |
nikmaos | 0:1b92bdad27f6 | 8 | DS1248_START = 0; |
nikmaos | 0:1b92bdad27f6 | 9 | return 0; |
nikmaos | 0:1b92bdad27f6 | 10 | } |
nikmaos | 0:1b92bdad27f6 | 11 | |
nikmaos | 0:1b92bdad27f6 | 12 | unsigned char ADS1248WakeupCommand( void ) |
nikmaos | 0:1b92bdad27f6 | 13 | { |
nikmaos | 0:1b92bdad27f6 | 14 | DS1248_CS = 0; |
nikmaos | 0:1b92bdad27f6 | 15 | DS1248_START = 1; |
nikmaos | 0:1b92bdad27f6 | 16 | SPI1MasterTransferByte(DS1248_WAKEUP_COMMAND); |
nikmaos | 0:1b92bdad27f6 | 17 | DS1248_CS = 1; |
nikmaos | 0:1b92bdad27f6 | 18 | return 0; |
nikmaos | 0:1b92bdad27f6 | 19 | } |
nikmaos | 0:1b92bdad27f6 | 20 | |
nikmaos | 0:1b92bdad27f6 | 21 | unsigned char ADS1248ReadRegister( unsigned char reg, unsigned char num ) |
nikmaos | 0:1b92bdad27f6 | 22 | { |
nikmaos | 0:1b92bdad27f6 | 23 | char res[num]; |
nikmaos | 0:1b92bdad27f6 | 24 | DS1248_CS = 0; |
nikmaos | 0:1b92bdad27f6 | 25 | SPI1MasterTransferByte(DS1248_RREG_COMMAND | ( reg & 0x0F )); |
nikmaos | 0:1b92bdad27f6 | 26 | SPI1MasterTransferByte(num - 1); |
nikmaos | 0:1b92bdad27f6 | 27 | while (num--) |
nikmaos | 0:1b92bdad27f6 | 28 | { |
nikmaos | 0:1b92bdad27f6 | 29 | res[num]=SPI1MasterTransferByte(DS1248_NOP_COMMAND); |
nikmaos | 0:1b92bdad27f6 | 30 | } |
nikmaos | 0:1b92bdad27f6 | 31 | DS1248_CS = 1; |
nikmaos | 0:1b92bdad27f6 | 32 | return res[0]; |
nikmaos | 0:1b92bdad27f6 | 33 | } |
nikmaos | 0:1b92bdad27f6 | 34 | |
nikmaos | 0:1b92bdad27f6 | 35 | unsigned char ADS1248WriteRegister( unsigned char reg, unsigned char num, uint8_t data) |
nikmaos | 0:1b92bdad27f6 | 36 | { |
nikmaos | 0:1b92bdad27f6 | 37 | DS1248_CS = 0; |
nikmaos | 0:1b92bdad27f6 | 38 | SPI1MasterTransferByte(DS1248_WREG_COMMAND | ( reg & 0x0F )); |
nikmaos | 0:1b92bdad27f6 | 39 | SPI1MasterTransferByte(num - 1); |
nikmaos | 0:1b92bdad27f6 | 40 | SPI1MasterTransferByte(data); |
nikmaos | 0:1b92bdad27f6 | 41 | SPI1MasterTransferByte(DS1248_NOP_COMMAND); |
nikmaos | 0:1b92bdad27f6 | 42 | DS1248_CS = 1; |
nikmaos | 0:1b92bdad27f6 | 43 | return 0; |
nikmaos | 0:1b92bdad27f6 | 44 | } |
nikmaos | 0:1b92bdad27f6 | 45 | |
nikmaos | 0:1b92bdad27f6 | 46 | unsigned char ADS1248StartConversion( void ) |
nikmaos | 0:1b92bdad27f6 | 47 | { |
nikmaos | 0:1b92bdad27f6 | 48 | DS1248_START = 1; |
nikmaos | 0:1b92bdad27f6 | 49 | |
nikmaos | 0:1b92bdad27f6 | 50 | //delay_us ( 5 ); |
nikmaos | 0:1b92bdad27f6 | 51 | |
nikmaos | 0:1b92bdad27f6 | 52 | DS1248_START = 0; |
nikmaos | 0:1b92bdad27f6 | 53 | return 0; |
nikmaos | 0:1b92bdad27f6 | 54 | } |
nikmaos | 0:1b92bdad27f6 | 55 | |
nikmaos | 0:1b92bdad27f6 | 56 | unsigned long ADS1248ReadData( ADS1248_t * ads ) |
nikmaos | 0:1b92bdad27f6 | 57 | { |
nikmaos | 0:1b92bdad27f6 | 58 | |
nikmaos | 0:1b92bdad27f6 | 59 | union{ |
nikmaos | 0:1b92bdad27f6 | 60 | struct{ |
nikmaos | 0:1b92bdad27f6 | 61 | uint8_t |
nikmaos | 0:1b92bdad27f6 | 62 | b1,b2,b3; |
nikmaos | 0:1b92bdad27f6 | 63 | }; |
nikmaos | 0:1b92bdad27f6 | 64 | uint32_t all; |
nikmaos | 0:1b92bdad27f6 | 65 | }data; |
nikmaos | 0:1b92bdad27f6 | 66 | data.all=0; |
nikmaos | 0:1b92bdad27f6 | 67 | |
nikmaos | 0:1b92bdad27f6 | 68 | DS1248_CS = 0; |
nikmaos | 0:1b92bdad27f6 | 69 | wait_us(1); |
nikmaos | 0:1b92bdad27f6 | 70 | SPI1MasterTransferByte(DS1248_RDATA_COMMAND); |
nikmaos | 0:1b92bdad27f6 | 71 | data.b3=SPI1MasterTransferByte(DS1248_NOP_COMMAND); |
nikmaos | 0:1b92bdad27f6 | 72 | data.b2=SPI1MasterTransferByte(DS1248_NOP_COMMAND); |
nikmaos | 0:1b92bdad27f6 | 73 | data.b1=SPI1MasterTransferByte(DS1248_NOP_COMMAND); |
nikmaos | 0:1b92bdad27f6 | 74 | wait_us(1); |
nikmaos | 0:1b92bdad27f6 | 75 | DS1248_CS = 1; |
nikmaos | 0:1b92bdad27f6 | 76 | |
nikmaos | 0:1b92bdad27f6 | 77 | return data.all; |
nikmaos | 0:1b92bdad27f6 | 78 | } |
nikmaos | 0:1b92bdad27f6 | 79 | |
nikmaos | 0:1b92bdad27f6 | 80 | unsigned char ADS1248SettingReg ( ADS1248_t * ads ) |
nikmaos | 0:1b92bdad27f6 | 81 | { |
nikmaos | 0:1b92bdad27f6 | 82 | DS1248_START = 1; |
nikmaos | 0:1b92bdad27f6 | 83 | DS1248_CS = 0; |
nikmaos | 0:1b92bdad27f6 | 84 | wait_us(1); |
nikmaos | 0:1b92bdad27f6 | 85 | SPI1MasterTransferByte(DS1248_RESET_COMMAND); |
nikmaos | 0:1b92bdad27f6 | 86 | wait_us(600); |
nikmaos | 0:1b92bdad27f6 | 87 | SPI1MasterTransferByte(DS1248_SDATAC_COMMAND); |
nikmaos | 0:1b92bdad27f6 | 88 | |
nikmaos | 0:1b92bdad27f6 | 89 | ADS1248WriteRegister ( DS1248_REGISTER_MUX0, 1, ads->MUX0.all ); |
nikmaos | 0:1b92bdad27f6 | 90 | ADS1248WriteRegister ( DS1248_REGISTER_VBIAS, 1,ads->VBIAS.all); |
nikmaos | 0:1b92bdad27f6 | 91 | ADS1248WriteRegister ( DS1248_REGISTER_MUX1, 1, ads->MUX1.all ); |
nikmaos | 0:1b92bdad27f6 | 92 | ADS1248WriteRegister ( DS1248_REGISTER_SYS0, 1, ads->SYS0.all ); |
nikmaos | 0:1b92bdad27f6 | 93 | ADS1248WriteRegister ( DS1248_REGISTER_IDAC0,1, ads->IDAC0.all); |
nikmaos | 0:1b92bdad27f6 | 94 | ADS1248WriteRegister ( DS1248_REGISTER_IDAC1,1, ads->IDAC1.all); |
nikmaos | 0:1b92bdad27f6 | 95 | ADS1248WriteRegister ( DS1248_REGISTER_FSC0,1, ads->FSC.FSC0); |
nikmaos | 0:1b92bdad27f6 | 96 | ADS1248WriteRegister ( DS1248_REGISTER_FSC1,1, ads->FSC.FSC1); |
nikmaos | 0:1b92bdad27f6 | 97 | ADS1248WriteRegister ( DS1248_REGISTER_FSC2,1, ads->FSC.FSC2); |
nikmaos | 0:1b92bdad27f6 | 98 | |
nikmaos | 0:1b92bdad27f6 | 99 | SPI1MasterTransferByte(DS1248_SYNC_COMMAND); |
nikmaos | 0:1b92bdad27f6 | 100 | wait_us(1); |
nikmaos | 0:1b92bdad27f6 | 101 | DS1248_CS = 1; |
nikmaos | 0:1b92bdad27f6 | 102 | return 0; |
nikmaos | 0:1b92bdad27f6 | 103 | |
nikmaos | 0:1b92bdad27f6 | 104 | } |