Library for Akizuki MCP3425 ADC module

Fork of MCP3425 by yasuyuki onodera

Library for MCP3425 ADC module from Akizuki-denshi.

MCP3425.h

Committer:
sakurahilljp
Date:
2016-04-12
Revision:
1:5ac344aa0aac
Parent:
0:b7bc51be525f
Child:
2:7375e645e806

File content as of revision 1:5ac344aa0aac:

//**********************
// MCP3425.h for mbed
//
// (C)Copyright 2014 All rights reserved by Y.Onodera
// http://einstlab.web.fc2.com
//**********************

#ifndef MCP3425_H_
#define MCP3425_H_

#define MCP3425_ADDR  (0xD0)

#include "mbed.h"
#include "typedef.h"


typedef union
{
    unsigned char UC;
    struct
    {
        unsigned char G:2;      // 00=1, 01=2, 10=4, 11=8 Gain
        unsigned char S:2;      // 00=12bits, 01=14bits, 10=16bits
        unsigned char OC:1;     // 0=One-shot, 1=Continuous
        unsigned char C:2;      // NA
        unsigned char RDY:1;    // wrinting 1=Initiate, reading 0=Ready
    } bit;
} CONFIG;



class MCP3425{
public:
    MCP3425 (PinName sda, PinName scl);
    MCP3425 (I2C& p_i2c);
    void init();
    short get(); // Returns AD code
    float read(); // Returns voltage

protected:
    static const float VREF;
    
    I2C _i2c;

    CONFIG config;
    WORD_VAL ad;
    char buf[3];

};

#endif /* MCP3425_H_ */