12-Bit, 8-Channel, ADC System Monitor w/ Temp Sensor, Internal/External Reference, & I2C Interface
Dependents: ADC128D818_HelloWorld
Revision 1:5f9dbbbc34c5, committed 2013-09-02
- Comitter:
- fblanc
- Date:
- Mon Sep 02 11:39:46 2013 +0000
- Parent:
- 0:9cc68ef524da
- Child:
- 2:f9a0518b352a
- Commit message:
- doc
Changed in this revision
ADC128D818.cpp | Show annotated file Show diff for this revision Revisions of this file |
ADC128D818.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ADC128D818.cpp Tue Aug 27 11:38:38 2013 +0000 +++ b/ADC128D818.cpp Mon Sep 02 11:39:46 2013 +0000 @@ -1,16 +1,60 @@ - +/** + * @brief ADC128D818 12-Bit, 8-Channel, ADC System Monitor w/ Temp Sensor, Internal/External Reference, & I2C Interfac + * http://www.ti.com/product/adc128d818/ + * @date 02/09/2013 + * @author F.BLANC LAAS-CNRS + * http://homepages.laas.fr/fblanc/ + */ + #include "ADC128D818.h" -//Create instance +/** + * @brief Constructor. + * + * @param sda I2C + * @param scl I2C + * @param adc_int + */ ADC128D818::ADC128D818(PinName sda, PinName scl, PinName adc_int) : _i2c(sda, scl), _Adc_Int (adc_int) { } -//destroy instance +/** + * @brief Destructor. + */ ADC128D818::~ADC128D818() { } +/** + * @brief init + * + * @param address I2C (7bits) + ADC_ADDRESS_LOW_LOW + ADC_ADDRESS_LOW_MID + ADC_ADDRESS_LOW_HIGH + ADC_ADDRESS_MID_LOW + ADC_ADDRESS_MID_MID + ADC_ADDRESS_MID_HIGH + ADC_ADDRESS_HIGH_LOW + ADC_ADDRESS_HIGH_MID + ADC_ADDRESS_HIGH_HIGH + * @param mode : + ADC_MODE_0 + ADC_MODE_1 + ADC_MODE_2 + ADC_MODE_3 + * @param vref + ADC_VREF_INT + ADC_VREF_EXT + * @param rate + ADC_RATE_LOW_POWER + ADC_RATE_CONTINUOUS + * @param mask_channel + * @param mask_int + * @return error 0 OK, -1 NO DEVICE, -2 ADC is BUSY + * @date 02/09/2013 + */ int ADC128D818::init(char address, char mode, char vref, char rate, char mask_channel, char mask_int) { @@ -100,36 +144,57 @@ return 0; } - -int ADC128D818::init_limit(char channel, int limit, char high_low) +/** + * @brief init_limit + * + * @param limit + * @param high_low + ADC_LIMIT_HIGH + ADC_LIMIT_LOW + * @return error 0 OK + * @date 02/09/2013 + */ +int ADC128D818::init_limit(char channel, char limit, char high_low) { - char cmd_data[3]; - char *ptr; - cmd_data[0]=ADC_REG_Limit_Registers + channel + high_low; - ptr=(char *) & limit; - cmd_data[1]=*ptr; - cmd_data[2]=*++ptr; + char cmd_data[2]; + + cmd_data[0]=ADC_REG_Limit_Registers + channel * 2 + high_low; - _i2c.write(_address, cmd_data, 3); //send a byte & wait acknowledged + cmd_data[1]=limit; + + + _i2c.write(_address, cmd_data, 2); //send a byte & wait acknowledged return 0; } - +/** + * @brief read_channel + * @param channel + * @return u32_data + * @date 02/09/2013 + */ int ADC128D818::read_channel(char channel) { - + int u32_data=0; char data[2]; -// char *ptr; + char *ptr; char cmd[1] ; cmd[0] = ADC_REG_Channel_Readings_Registers + channel; _i2c.write(_address, cmd, 1); //send a byte & wait acknowledged - //ptr=(char *) & data; + _i2c.read(_address,data,2); //read a byte - - return (int) data[0]*256+data[1]; + ptr=(char *) & u32_data; + ptr[0]=data[1]; + ptr[1]=data[0]; + return u32_data; } - +/** + * @brief read_register + * @param Register + * @return u8_data + * @date 02/09/2013 + */ char ADC128D818::read_register(char Register) { @@ -141,7 +206,10 @@ return cmd; } - +/** + * @brief start + * @date 02/09/2013 + */ void ADC128D818::start() { char cmd_data[2]; @@ -151,6 +219,10 @@ _i2c.write(_address, cmd_data, 2); //send a 2 byte } +/** + * @brief stop + * @date 02/09/2013 + */ void ADC128D818::stop() { char cmd_data[2];
--- a/ADC128D818.h Tue Aug 27 11:38:38 2013 +0000 +++ b/ADC128D818.h Mon Sep 02 11:39:46 2013 +0000 @@ -1,4 +1,10 @@ - +/** + * @brief ADC128D818 12-Bit, 8-Channel, ADC System Monitor w/ Temp Sensor, Internal/External Reference, & I2C Interfac + * http://www.ti.com/product/adc128d818/ + * @date 02/09/2013 + * @author F.BLANC LAAS-CNRS + * http://homepages.laas.fr/fblanc/ + */ #ifndef ADC128D818_H @@ -48,6 +54,32 @@ ADC_CHANNEL_IN7 = 0x07, ADC_CHANNEL_TEMP = 0x07 }; + enum ADC_INT { + + ADC_INT_IN0 = (char)~(0x01 <<0), + ADC_INT_IN1 = (char)~(0x01 <<1), + ADC_INT_IN2 = (char)~(0x01 <<2), + ADC_INT_IN3 = (char)~(0x01 <<3), + ADC_INT_IN4 = (char)~(0x01 <<4), + ADC_INT_IN5 = (char)~(0x01 <<5), + ADC_INT_IN6 = (char)~(0x01 <<6), + ADC_INT_IN7 = (char)~(0x01 <<7), + ADC_INT_TEMP = (char)~(0x01 <<7), + ADC_INT_ALL = 0x00 + }; + enum ADC_ENABLE { + + ADC_ENABLE_IN0 = (char)~(0x01 <<0), + ADC_ENABLE_IN1 = (char)~(0x01 <<1), + ADC_ENABLE_IN2 = (char)~(0x01 <<2), + ADC_ENABLE_IN3 = (char)~(0x01 <<3), + ADC_ENABLE_IN4 = (char)~(0x01 <<4), + ADC_ENABLE_IN5 = (char)~(0x01 <<5), + ADC_ENABLE_IN6 = (char)~(0x01 <<6), + ADC_ENABLE_IN7 = (char)~(0x01 <<7), + ADC_ENABLE_TEMP = ~(0x01 <<7), + ADC_ENABLE_ALL = 0x00 + }; enum ADC_REG { ADC_REG_Configuration_Register = 0x00, ADC_REG_Interrupt_Status_Register = 0x01, @@ -106,7 +138,7 @@ int read_channel(char channel); char read_register(char Register); int init(char address, char mode, char vref, char rate, char mask_channel, char mask_int); - int init_limit(char channel, int limit, char high_low); + int init_limit(char channel, char limit, char high_low); void start(); void stop(); };