Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MCP3425.cpp
00001 //********************** 00002 // MCP3425.cpp for mbed 00003 // 00004 // MCP3425 mcp3425(P0_5,P0_4); 00005 // or 00006 // I2C i2c(P0_5,P0_4); 00007 // MCP3425 mcp3425(i2c); 00008 // 00009 // (C)Copyright 2014 All rights reserved by Y.Onodera 00010 // http://einstlab.web.fc2.com 00011 //********************** 00012 00013 #include "mbed.h" 00014 #include "MCP3425.h" 00015 00016 MCP3425::MCP3425 (PinName sda, PinName scl) : _i2c(sda, scl) { 00017 init(); 00018 } 00019 MCP3425::MCP3425 (I2C& p_i2c) : _i2c(p_i2c) { 00020 init(); 00021 } 00022 00023 00024 short MCP3425::get() 00025 { 00026 00027 _i2c.read( MCP3425_ADDR, buf, 3); 00028 00029 ad.byte.HB=buf[0]; 00030 ad.byte.LB=buf[1]; 00031 config.UC=buf[2]; 00032 return ad.S; 00033 00034 } 00035 00036 00037 void MCP3425::init() 00038 { 00039 00040 config.bit.RDY=1; 00041 config.bit.C=0; 00042 config.bit.OC=1; 00043 config.bit.S=2; 00044 config.bit.G=0; 00045 // Initiate Continuous 16bits, 15SPS 00046 buf[0]=config.UC; 00047 _i2c.write(MCP3425_ADDR, buf, 1); 00048 00049 } 00050
Generated on Tue Jul 26 2022 08:57:44 by
1.7.2