I am trying to build a variometer using the Mod-1009 board for MS5611-01BA barometric pressure sensor from Embedded Adventures.
Unfortunately, I cannot read values from the i2c port. SDA is connected to Analog 4, SCLK to 5 and the VCC to 3.3v. I am using the latest framework (4.2).
I am OK with C# and .net but I am clueless in this world. Bellow is my code where the device.Execute always returns zero in the ReadFromDevice method.
using System; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; namespace MS5611baro { // Mod-1009 board for MS5611-01BA Barometric Pressure Sensor from // Embedded Adventures (http://www.embeddedadventures.com/barometric_pressure_sensor_module_mod-1009.html) // MS5611 datasheet http://www.embeddedadventures.com/datasheets/ms5611.pdf // Mod-1009 description http://www.embeddedadventures.com/datasheets/MOD-1009_hw_v1.pdf // // VCC --> 3.3v // SDA --> Analog 4 // SCLK --> Analog 5 // // Pull up resistors: (from Mod-1009 description) The board comes with the pull-up resistors enabled. If you are // connecting to an existing I2C buss that already has pull-up resistors, or you are using internal pull-ups in // your microcontroller, you can disable the pull-up resistors by cutting the PCB jumpers on the MOD-1009 board. public class MS5611_MOD1009 { private const byte _cmdReset = 0x1E; private const byte _cmdPromReadBase = 0xa0; private const ushort _i2cAddr = 0x76; //Embedded Adventures module CSB is VCC --> HIGH --> 0x76 public UInt16[] CalibrationArray = new UInt16[6]; public int LastTransactionCount = -1; private I2CDevice _device = new I2CDevice(new I2CDevice.Configuration(_i2cAddr, 10)); /// <summary> Mod-1009 board for MS5611-01BA Barometric Pressure Sensor from Embedded Adventures</summary> public MS5611_MOD1009() { while (LastTransactionCount < 1) { WriteToDevice(_cmdReset, 100); // ResetSensor(); } } public bool WriteToDevice(byte command, int timeOut = 5) { I2CDevice.I2CWriteTransaction wt = I2CDevice.CreateWriteTransaction(new byte[] { command }); LastTransactionCount = this._device.Execute(new I2CDevice.I2CTransaction[] { wt }, 3); return LastTransactionCount > 0; } public bool ReadFromDevice(byte[] readBuf, int timeOut = 100) { var rtArr = new I2CDevice.I2CReadTransaction[] { I2CDevice.CreateReadTransaction(readBuf) }; LastTransactionCount = _device.Execute(rtArr, timeOut); // --> returns allways zero return LastTransactionCount == readBuf.Length; } public void ReadCalibrationData() { for (byte i = 0; i < 6; i++) { CalibrationArray[i] = ReadSingleCalibrationValue((byte)(i + 1)); } } private UInt16 ReadSingleCalibrationValue(byte valueToRead) { // 1 0 1 0 X X X 0 - The XXX part is used for the parameter index byte paramIndex = (byte)(_cmdPromReadBase + (valueToRead << 1)); // This sets up the system into PROM read mode. if (WriteToDevice(paramIndex)) // --> returns true { byte[] readBuf = new byte[2]; // This part gets the data from the system. if (ReadFromDevice(readBuf, 100)) // --> returns allways false, readBuf is empty {0, 0} { return (UInt16)(readBuf[0] << 8 | readBuf[1]); } } return 0; } } }
using System; using System.Threading; using Microsoft.SPOT; namespace MS5611baro { public class Program { public static void Main() { var baro = new MS5611_MOD1009(); baro.ReadCalibrationData(); } } }
Thanks for help,
Sinan