ADS1231 General Purpose library to deal with ADS1231 AD Converter
Embed:
(wiki syntax)
Show/hide line numbers
ADS1231_GP.cpp
00001 /* 00002 ADS1231 General Purpose library 00003 Fernando Cosentino 00004 Nimbus Centre 00005 Cork Institute of Technology 00006 fernando.cosentino@cit.ie 00007 */ 00008 00009 #include "ADS1231_GP.h" 00010 00011 ADS1231_GP::ADS1231_GP(PinName doutPin, PinName clkPin, PinName pdwnPin): dout(doutPin), clk(clkPin), pdwn(pdwnPin) { 00012 pdwn = 0; 00013 } 00014 00015 void ADS1231_GP::setPower(unsigned int p) { 00016 pdwn = p; 00017 } 00018 00019 unsigned int ADS1231_GP::dataAvailable(void) { 00020 if (pdwn == 0) return 0; 00021 if (dout == 0) return 1; 00022 else return 0; 00023 } 00024 00025 unsigned int ADS1231_GP::readValue(void) { 00026 unsigned int val = 0; 00027 int i; 00028 // Extract 24 bits of data 00029 for (i = 0; i < 24; i++) { 00030 // CLK rise 00031 clk = 1; 00032 // Wait CLK up 00033 wait_us(1); 00034 // Sample 00035 val = val << 1; 00036 if (dout != 0) val |= 1; 00037 // CLK fall 00038 clk = 0; 00039 // wait CLK down 00040 wait_us(1); 00041 } 00042 // Apply 25th CLK to force DOUT back into IRQ function 00043 clk = 1; 00044 wait_us(1); 00045 clk = 0; 00046 wait_us(1); 00047 // Return data 00048 return val; 00049 }
Generated on Tue Jul 19 2022 12:52:53 by
1.7.2