12 bit ADC needs to have initial request bits shifted a bit

This commit is contained in:
npotts 2016-01-10 00:23:03 -07:00
parent 1224148572
commit 24e96ba433
1 changed files with 11 additions and 3 deletions

View File

@ -38,9 +38,17 @@ const (
// AnalogValueAt returns the analog value at the given channel of the convertor.
func (m *MCP3008) AnalogValueAt(chanNum int) (int, error) {
var data [3]uint8
data[0] = startBit
data[1] = uint8(m.Mode)<<7 | uint8(chanNum)<<4
data[2] = 0
switch m.Bits {
case Bits10:
data[0] = startBit
data[1] = uint8(m.Mode)<<7 | uint8(chanNum)<<4
data[2] = 0
case Bits12:
//[0x06| (channel >> 2), channel << 6, 0]
data[0] = 0x06 | (uint8(chanNum) >> 2)
data[1] = uint8(chanNum) << 6
data[2] = 0
}
glog.V(2).Infof("mcp3008: sendingdata buffer %v", data)
if err := m.Bus.TransferAndReceiveData(data[:]); err != nil {