Greetings,

I am trying to use ADS7828 which is an 8-channel I2C ADC  from TI. I am 
using javascript to accomplish this task. I am using the latest version of 
bonescript.
I have added this line:  echo BB-I2C1 > /sys/devices/bone_capemgr.9/slots 
 to  /etc/profile.d/node.sh to execute upon power up or reset.

Executing ls -l /sys/bus/i2c/devices/i2c-*, gives the following results:

lrwxrwxrwx 1 root root 0 May 15 04:39 /sys/bus/i2c/devices/i2c-0 -> 
../../../devices/ocp.3/44e0b000.i2c/i2c-0
lrwxrwxrwx 1 root root 0 May 15 04:39 /sys/bus/i2c/devices/i2c-1 -> 
../../../devices/ocp.3/4819c000.i2c/i2c-1
lrwxrwxrwx 1 root root 0 Nov  4 16:27 /sys/bus/i2c/devices/i2c-2 -> 
../../../devices/ocp.3/4802a000.i2c/i2c-2

Here is my code:

var b = require("bonescript")
var port = '/dev/i2c-2';
b.i2cOpen(port, 0x49, {});
testADC();

function testADC()
{
    // Internal Voltage Reference 2.5V
    // Single-ended conversion 
    // channel number address is kind of weird on this chip
    var channelNumber = [0x00, 0x04, 0x01, 0x05, 0x02, 0x06, 0x03, 0x07];
    var channelOutput = [0, 0, 0, 0, 0, 0, 0, 0];
    var n;
    
//    b.i2cOpen(port, 0x49);
    
    for (n = 0; n < 8; n++)
    {
       channelOutput[n] =  readADCchannel(channelNumber[n]);
    }
}

function readADCchannel (adcChannelNumber)
{
    var command;
    var singleEnded = 0x80;
    var voltageReference = 0x0C;
    var buffer = [];
    
    command = singleEnded + (adcChannelNumber << 4) + voltageReference;

    // send command to start conversion
    *b.i2cWriteByte(port, command);*

    // Conversion should start immediately
    console.log(command);  
    // serves as a time delay
    for (var x = 0; x < 300000; x++)
    {
    }
    
    // read the conversion result
    *buffer = b.i2cReadBytes(port, {} , 2);*

    console.log("Buffer0 = " + buffer[0]);
    console.log("Buffer1 = " + buffer[1]);

    var voltage = ((buffer[1] + (buffer[0] * 256)) * 2500) / 4096;
    var s = "Output Voltage of Channel: " + adcChannelNumber + " = " + 
voltage + "mv";
    console.log(s); 
    return voltage;
}

I am using Cloud9 to debug this. I put two break points where I am writing 
to and reading from the chip. I am using a Gabotronics  Xmega Xminilab to 
read the I2C exchange between the BBB and the ADC converter.
http://www.gabotronics.com/development-boards/xmega-xminilab.htm

After executing the b.i2cWriteByte((port, command); I correctly see the 
following bytes on the Xminilab display 49> 8C+  the > indicates a write 
cycle to address 0x49 which is the ADC address and the + sign indicates an 
ack from the ADC. If I execute the b.i2cReadBytes(port, {} , 2); command 
I see the following: 49> 00+ 49< 00+ 00- . The 49> 00+ indicates another 
write cycle with 00 command , the < indicates a read cycle from address 
0x49 followed by the two bytes that I am interested in, basically the ADC 
reading, the - sign indicates no ack..

The question is where is the second write cycle coming from? It basically 
screws up the ADC reading and all I get is a zero reading from the ADC.

So, what am I doing wrong here? I can't use i2cReadByte because the ADC 
outputs 2 bytes as a result of read request.

This is driving me crazy.

Thanks in advance,

Mostafa 
 

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to