mbed library to interface a Texas Instruments' ADS7828, 12-bits, 8-channels, I2C interfaced ADC

Dependents:   ADS7828_demo

Committer:
frada
Date:
Tue Dec 30 18:45:23 2014 +0000
Revision:
3:abbfd9c7f30c
Parent:
2:2ff328d8e4dd
-;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frada 1:19b0f0ba4d12 1 /***************************************************************************
frada 3:abbfd9c7f30c 2 * @author Francesco Adamo
frada 3:abbfd9c7f30c 3 *
frada 3:abbfd9c7f30c 4 * @section LICENSE
frada 3:abbfd9c7f30c 5 *
frada 3:abbfd9c7f30c 6 * Copyright (c) 2014 Francesco Adamo
frada 3:abbfd9c7f30c 7 *
frada 3:abbfd9c7f30c 8 * @section DESCRIPTION
frada 3:abbfd9c7f30c 9 *
frada 3:abbfd9c7f30c 10 * ADS7828.H
frada 3:abbfd9c7f30c 11 * Header file for library ADS7828
frada 3:abbfd9c7f30c 12 * The ADS7828 is a 12-bits, 8-channels, I2C-interfaced from Texas Instruments
frada 3:abbfd9c7f30c 13 *
frada 3:abbfd9c7f30c 14 * (c) 2014 - By Francesco Adamo, Italy
frada 1:19b0f0ba4d12 15 *****************************************************************************/
frada 1:19b0f0ba4d12 16
frada 1:19b0f0ba4d12 17 #ifndef ADS7828_H
frada 1:19b0f0ba4d12 18 #define ADS7828_H
frada 1:19b0f0ba4d12 19
frada 1:19b0f0ba4d12 20 #include "mbed.h"
frada 1:19b0f0ba4d12 21
frada 1:19b0f0ba4d12 22 #define ADS7828_BASE_ADDRESS 0x90
frada 1:19b0f0ba4d12 23
frada 1:19b0f0ba4d12 24 // ADS7828 command codes
frada 1:19b0f0ba4d12 25 #define CH01_DIFF (uint8_t) (0x00 << 4) // CH0+, CH1-
frada 1:19b0f0ba4d12 26 #define CH23_DIFF (uint8_t) (0x01 << 4) // CH2+, CH2-
frada 1:19b0f0ba4d12 27 #define CH45_DIFF (uint8_t) (0x02 << 4) // CH4+, CH5-
frada 1:19b0f0ba4d12 28 #define CH67_DIFF (uint8_t) (0x03 << 4) // CH6+, CH7-
frada 1:19b0f0ba4d12 29 #define CH10_DIFF (uint8_t) (0x04 << 4) // CH1+, CH0-
frada 1:19b0f0ba4d12 30 #define CH32_DIFF (uint8_t) (0x05 << 4) // CH3+, CH2-
frada 1:19b0f0ba4d12 31 #define CH54_DIFF (uint8_t) (0x06 << 4) // CH5+, CH4-
frada 1:19b0f0ba4d12 32 #define CH76_DIFF (uint8_t) (0x07 << 4) // CH6+, CH6-
frada 1:19b0f0ba4d12 33
frada 1:19b0f0ba4d12 34 #define CH0_SE (uint8_t) (0x00 << 4)
frada 1:19b0f0ba4d12 35 #define CH2_SE (uint8_t) (0x01 << 4)
frada 1:19b0f0ba4d12 36 #define CH4_SE (uint8_t) (0x02 << 4)
frada 1:19b0f0ba4d12 37 #define CH6_SE (uint8_t) (0x03 << 4)
frada 1:19b0f0ba4d12 38 #define CH1_SE (uint8_t) (0x04 << 4)
frada 1:19b0f0ba4d12 39 #define CH3_SE (uint8_t) (0x05 << 4)
frada 1:19b0f0ba4d12 40 #define CH5_SE (uint8_t) (0x06 << 4)
frada 1:19b0f0ba4d12 41 #define CH7_SE (uint8_t) (0x07 << 4)
frada 1:19b0f0ba4d12 42
frada 1:19b0f0ba4d12 43 #define MODE_SE (uint8_t) (0x01 << 8)
frada 1:19b0f0ba4d12 44 #define MODE_DIFF (uint8_t) 0x00
frada 1:19b0f0ba4d12 45
frada 1:19b0f0ba4d12 46 #define MODE_POWER_DOWN_BETWEEN_CONVERSIONS (uint8_t) (0x00 << 2)
frada 1:19b0f0ba4d12 47 #define MODE_INTERNAL_REF_OFF_ADC_ON (uint8_t) (0x01 << 2)
frada 1:19b0f0ba4d12 48 #define MODE_INTERNAL_REF_ON_ADC_OFF (uint8_t) (0x02 << 2)
frada 1:19b0f0ba4d12 49 #define MODE_INTERNAL_REF_ON_ADC_ON (uint8_t) (0x03 << 2)
frada 1:19b0f0ba4d12 50
frada 1:19b0f0ba4d12 51
frada 1:19b0f0ba4d12 52 class ADS7828 {
frada 1:19b0f0ba4d12 53 private:
frada 1:19b0f0ba4d12 54 I2C _i2c;
frada 1:19b0f0ba4d12 55 char address;
frada 1:19b0f0ba4d12 56 double VFSR;
frada 1:19b0f0ba4d12 57
frada 1:19b0f0ba4d12 58 public:
frada 1:19b0f0ba4d12 59 ADS7828(PinName sda, PinName scl); // Constructor
frada 1:19b0f0ba4d12 60 ADS7828(PinName sda, PinName scl, int freq); // Constructor overload
frada 1:19b0f0ba4d12 61 ADS7828(PinName sda, PinName scl, int freq, char subAddress); // Constructor overload
frada 2:2ff328d8e4dd 62 ADS7828(PinName sda, PinName scl, int freq, char subAddress, double VREF); // Constructor overload
frada 1:19b0f0ba4d12 63
frada 1:19b0f0ba4d12 64 int readRawValue(char mode, char channel);
frada 1:19b0f0ba4d12 65 double readAnalogValue(char mode, char channel);
frada 1:19b0f0ba4d12 66 };
frada 1:19b0f0ba4d12 67
frada 1:19b0f0ba4d12 68 #endif //#ifndef ADS7828_H