MCP3425 library

Dependents:   mbed_MCP3425

See http://developer.mbed.org/users/yasuyuki/notebook/MCP3425/

Committer:
yasuyuki
Date:
Wed Oct 15 14:37:59 2014 +0000
Revision:
0:b7bc51be525f
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yasuyuki 0:b7bc51be525f 1 //**********************
yasuyuki 0:b7bc51be525f 2 // MCP3425.h for mbed
yasuyuki 0:b7bc51be525f 3 //
yasuyuki 0:b7bc51be525f 4 // (C)Copyright 2014 All rights reserved by Y.Onodera
yasuyuki 0:b7bc51be525f 5 // http://einstlab.web.fc2.com
yasuyuki 0:b7bc51be525f 6 //**********************
yasuyuki 0:b7bc51be525f 7
yasuyuki 0:b7bc51be525f 8 #ifndef MCP3425_H_
yasuyuki 0:b7bc51be525f 9 #define MCP3425_H_
yasuyuki 0:b7bc51be525f 10
yasuyuki 0:b7bc51be525f 11 #define MCP3425_ADDR 0xD0
yasuyuki 0:b7bc51be525f 12
yasuyuki 0:b7bc51be525f 13 #include "mbed.h"
yasuyuki 0:b7bc51be525f 14 #include "typedef.h"
yasuyuki 0:b7bc51be525f 15
yasuyuki 0:b7bc51be525f 16
yasuyuki 0:b7bc51be525f 17 typedef union
yasuyuki 0:b7bc51be525f 18 {
yasuyuki 0:b7bc51be525f 19 unsigned char UC;
yasuyuki 0:b7bc51be525f 20 struct
yasuyuki 0:b7bc51be525f 21 {
yasuyuki 0:b7bc51be525f 22 unsigned char G:2; // 00=1, 01=2, 10=4, 11=8 Gain
yasuyuki 0:b7bc51be525f 23 unsigned char S:2; // 00=12bits, 01=14bits, 10=16bits
yasuyuki 0:b7bc51be525f 24 unsigned char OC:1; // 0=One-shot, 1=Continuous
yasuyuki 0:b7bc51be525f 25 unsigned char C:2; // NA
yasuyuki 0:b7bc51be525f 26 unsigned char RDY:1; // wrinting 1=Initiate, reading 0=Ready
yasuyuki 0:b7bc51be525f 27 } bit;
yasuyuki 0:b7bc51be525f 28 } CONFIG;
yasuyuki 0:b7bc51be525f 29
yasuyuki 0:b7bc51be525f 30
yasuyuki 0:b7bc51be525f 31
yasuyuki 0:b7bc51be525f 32 class MCP3425{
yasuyuki 0:b7bc51be525f 33 public:
yasuyuki 0:b7bc51be525f 34 MCP3425 (PinName sda, PinName scl);
yasuyuki 0:b7bc51be525f 35 MCP3425 (I2C& p_i2c);
yasuyuki 0:b7bc51be525f 36 void init();
yasuyuki 0:b7bc51be525f 37 short get();
yasuyuki 0:b7bc51be525f 38
yasuyuki 0:b7bc51be525f 39 protected:
yasuyuki 0:b7bc51be525f 40
yasuyuki 0:b7bc51be525f 41 I2C _i2c;
yasuyuki 0:b7bc51be525f 42
yasuyuki 0:b7bc51be525f 43 CONFIG config;
yasuyuki 0:b7bc51be525f 44 WORD_VAL ad;
yasuyuki 0:b7bc51be525f 45 char buf[3];
yasuyuki 0:b7bc51be525f 46
yasuyuki 0:b7bc51be525f 47 };
yasuyuki 0:b7bc51be525f 48
yasuyuki 0:b7bc51be525f 49 #endif /* MCP3425_H_ */
yasuyuki 0:b7bc51be525f 50
yasuyuki 0:b7bc51be525f 51
yasuyuki 0:b7bc51be525f 52