X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=wiringPi%2Fmcp3004.c;h=82c73dd253165d306c8c2e81db108c11ccbcb53f;hb=4d43c8cdca06a03e7e6c051ef0b7a5180da17467;hp=1c9357f237a84b53e6e388df09e620ed627fd5df;hpb=45bfe43c1e8fe7e51a410403fe628c53d7a5e387;p=wiringPi.git diff --git a/wiringPi/mcp3004.c b/wiringPi/mcp3004.c index 1c9357f..82c73dd 100644 --- a/wiringPi/mcp3004.c +++ b/wiringPi/mcp3004.c @@ -2,6 +2,8 @@ * mcp3004.c: * Extend wiringPi with the MCP3004 SPI Analog to Digital convertor * Copyright (c) 2012-2013 Gordon Henderson + * + * Thanks also to "ShorTie" on IRC for some remote debugging help! *********************************************************************** * This file is part of wiringPi: * https://projects.drogon.net/raspberry-pi/wiringpi/ @@ -35,18 +37,19 @@ static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) { - unsigned char spiData [2] ; + unsigned char spiData [3] ; unsigned char chanBits ; int chan = pin - node->pinBase ; - chanBits = 0b11000000 | (chan << 3) ; + chanBits = 0b10000000 | (chan << 4) ; - spiData [0] = chanBits ; - spiData [1] = 0 ; + spiData [0] = 1 ; // Start bit + spiData [1] = chanBits ; + spiData [2] = 0 ; - wiringPiSPIDataRW (node->fd, spiData, 2) ; + wiringPiSPIDataRW (node->fd, spiData, 3) ; - return ((spiData [0] << 7) | (spiData [1] >> 1)) & 0x3FF ; + return ((spiData [1] << 8) | spiData [2]) & 0x3FF ; }