I2c problem (potential work for someone)

I have a problem connecting I2c sensor.
My board is based on EMX chip
On the same line I have 2 sensors connected
That’s the code I’m using but I don’t read anything from the first sensor and If I change the read nothing from sensor 2 too.
This board it’s not the first time that we produce, but our programmer has left us without software and I have to rewrite it.
If someone paying can help me let me know.
My email address is matteo.sarti@ gmail.com


using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.Hardware;

namespace Example
{
    public class Program
    {
        public static void Main()
        {
            // Create the bus
            Cpu.Pin clockPin = Cpu.Pin.GPIO_Pin14;
            Cpu.Pin dataPin = Cpu.Pin.GPIO_Pin15; 
            SoftwareI2CBus i2cBus = new SoftwareI2CBus(clockPin, dataPin);
            
            SoftwareI2CBus.I2CDevice i2cDevice1 = i2cBus.CreateI2CDevice(0x78, 100);                   
            SoftwareI2CBus.I2CDevice i2cDevice2 = i2cBus.CreateI2CDevice(0x02A0, 100);

            //int numWritten;
            int numRead;      

            // read 
            byte[] dataToRead = new byte[2];
            numRead = i2cDevice2.Read(dataToRead, 0, dataToRead.Length);        

          
        }

    }
} 

I don’t see any code that reads from the first sensor.

Must nothing be written to the sensors?

Can you tell us what sensors?

That’s the sensors that I’m using
http://www.sensortechnics.com/en/products/pressure-sensors-and-transmitters/amplified-pressure-sensors/hdi/

and

If device2 is the Microchip part then the address is wrong. Assuming you have the 3 address lines low it should be 0x48 and not 0x02A0 as in your code.

Have you got PULLUPS on the SDA and SCL lines?

What value are you seeing in the reply for each device? Is if 0xFF for each byte?

I’ve changed come with this new one suggested in documentation of ghi


using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.IO;


namespace change_this_to_your_namespace
{
    public class Program
    {
        public static void Main()
        {
            //create I2C Device object representing both devices on our bus
            I2CDevice.Configuration conDeviceA =
               new I2CDevice.Configuration(0x78, 100);
            I2CDevice.Configuration conDeviceB =
               new I2CDevice.Configuration(0x48, 100);

            //create I2C Bus object using one of the devices on the bus
            I2CDevice MyI2C = new I2CDevice(conDeviceA);
            // Note you could have chosen to create the bus using the conDeviceB parameter, which ever you choose it will be the "selected" device on the bus to start with. Here's how you would do that:
            // I2CDevice MyI2C = new I2CDevice(conDeviceB);

            //create transactions (we need 2 in this example)
            I2CDevice.I2CTransaction[] xActions =
               new I2CDevice.I2CTransaction[2];

            // create write buffer (we need one byte)
            byte[] RegisterNum = new byte[1] { 0 };
            xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);
            // create read buffer to read the register
            byte[] RegisterValue = new byte[2];
            xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);



            // Explicitly set the I2C bus to access device A by setting the I2C Config to the Device A's config.
            MyI2C.Config = conDeviceA;
            if (MyI2C.Execute(xActions, 1000) == 0)
                
            {
                Debug.Print("Failed to perform I2C transaction");
            }
            else
            {
                Debug.Print("Register value: " + RegisterValue[0].ToString() + RegisterValue[1].ToString());
            }

            // Explicitly set the I2C bus to access device B by setting the I2C Config to the Device B's config.
            MyI2C.Config = conDeviceB;
            if (MyI2C.Execute(xActions, 1000) == 0)
            {
                Debug.Print("Failed to perform I2C transaction");
            }
            else
            {
                Debug.Print("Register value: " + RegisterValue[0].ToString());
            }
        }
    }
}

Actually I canread from second sensor (temperature sensor) problem is the first one that raplay just with 0 and nothing mode even if I try to apply pressure.

Ideas???

Producer of sensor suggest to do something like that but I don’t know how to do!!

byte byte_msb, byte_lsb; // 8bit values
int16 pressure; // 16bit value
// Set I2C unit to I2C master mode, clock speed 100 kHz and 7 bit addressing
configureI2C (I2C_MASTER | CLK_SPEED_100KHZ | ADDRESSING_7BIT);
// Set the target address of the sensor (0x78 = 120dec)
I2C_set_target(0x78);
// Send start condition for reading from sensor (slave)
I2C_send_start_read();
// Read first (MSB) data byte and answer with ACK (continue communication)
I2C_read (&byte_msb, SEND_ACK);
// Read second (LSB) data byte and answer with NACK (end communication)
I2C_read (&byte_lsb, SEND_NACK);
// Send Stop condition
I2C_send_stop();
// Put both values together
pressure = ((int16)byte_msb << 8) | byte_lsb;

I have seen another thread with this topic. This problem seems to be solved.


Hi Matteo,

Did you managed to get your sensors working.

If not, you can measure the value on the analogue pin to check the sensor. From the documentation:

[quote]Check the analogue output signal of the
sensor. If it responds to pressure changes the
sensor works. Then, errors of the digital output
can be limited to problems of the I²C bus.[/quote]

Btw., these sensors can also be ordered with additional temperature output. That would make the second temp sensor obsolete.

Succes, Sinan