Library for Akizuki MCP3425 ADC module

Fork of MCP3425 by yasuyuki onodera

Library for MCP3425 ADC module from Akizuki-denshi.

Committer:
sakurahilljp
Date:
Tue Apr 12 14:56:07 2016 +0000
Revision:
1:5ac344aa0aac
Parent:
0:b7bc51be525f
Child:
2:7375e645e806
Added read() method which returns voltage.

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
sakurahilljp 1:5ac344aa0aac 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();
sakurahilljp 1:5ac344aa0aac 37 short get(); // Returns AD code
sakurahilljp 1:5ac344aa0aac 38 float read(); // Returns voltage
yasuyuki 0:b7bc51be525f 39
yasuyuki 0:b7bc51be525f 40 protected:
sakurahilljp 1:5ac344aa0aac 41 static const float VREF;
yasuyuki 0:b7bc51be525f 42
yasuyuki 0:b7bc51be525f 43 I2C _i2c;
yasuyuki 0:b7bc51be525f 44
yasuyuki 0:b7bc51be525f 45 CONFIG config;
yasuyuki 0:b7bc51be525f 46 WORD_VAL ad;
yasuyuki 0:b7bc51be525f 47 char buf[3];
yasuyuki 0:b7bc51be525f 48
yasuyuki 0:b7bc51be525f 49 };
yasuyuki 0:b7bc51be525f 50
yasuyuki 0:b7bc51be525f 51 #endif /* MCP3425_H_ */
yasuyuki 0:b7bc51be525f 52
yasuyuki 0:b7bc51be525f 53
yasuyuki 0:b7bc51be525f 54