I have a problem with my DS1621 I2C Controller after upgrade to SDK 4.2 with firmware 4.2.0.0 RC1.
The following code works fine with firmware 4.1.0.6 but not with the new Version.
using System; using System.Net; using System.Net.Sockets; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; namespace Datalogger.Devices { public class DS1621 { private static byte READ_CMD = 0xAA; private static byte COUNTER_CMD = 0xA8; private static byte SLOPE_CMD = 0xA9; private static byte START_CMD = 0xEE; private static byte STOP_CMD = 0x22; private static byte TH_CMD = 0xA1; private static byte TL_CMD = 0xA2; private static byte CONFIG_CMD = 0xAC; private ushort adress = 0x48; private I2CDevice i2c = null; public DS1621(ushort addr) { adress = addr; I2CDevice.Configuration config = new I2CDevice.Configuration(adress, 100); i2c = new I2CDevice(config); I2CDevice.I2CTransaction[] transactions = new I2CDevice.I2CTransaction[1]; transactions[0] = I2CDevice.CreateWriteTransaction(new byte[] { CONFIG_CMD, 0x00 }); int rc = i2c.Execute(transactions, 100); // Debug.Print("INIT(" + adress + ")=" + rc); if (rc != 2) { throw new Exception("INIT faled"); } } public void reset() { i2c.Dispose(); } public double ReadTempFromDevice() { I2CDevice.I2CTransaction[] transactions = new I2CDevice.I2CTransaction[1]; byte[] read_buffer = new byte[2]; int rc = 0; transactions[0] = I2CDevice.CreateWriteTransaction(new byte[] { START_CMD }); rc = i2c.Execute(transactions, 1000); // Debug.Print("START=" + rc); if (rc != 1) return -900; Thread.Sleep(50); transactions[0] = I2CDevice.CreateWriteTransaction(new byte[] { STOP_CMD }); rc = i2c.Execute(transactions, 1000); //Debug.Print("STOP=" + rc); if (rc != 1) return -901; read_buffer[0] = 0; read_buffer[1] = 0; transactions = new I2CDevice.I2CTransaction[2]; transactions[0] = I2CDevice.CreateWriteTransaction(new byte[] { READ_CMD }); transactions[1] = I2CDevice.CreateReadTransaction(read_buffer); rc = i2c.Execute(transactions, 1000); // Debug.Print("READ=" + rc); if (rc != 3) return -902; //Debug.Print("buffer[0]" + read_buffer[0]); //Debug.Print("buffer[1]" + read_buffer[1]); double temp = read_buffer[0] + (read_buffer[1] == 128 ? 0.5 : 0); return temp; } } }
The Read command will return rc=1 not rc=3 as before and the read_buffer is empty.
Has anyone an idea to help.
I switch to 4.2.0.0 RC1 because problem with the SD-CARD. The project shall write the temperature from 4 DS1621 devices to
a log file on the SD-Card
Best reagards
Armin
Edited by Stefan, 23 August 2011 - 04:29 PM.
Added code tags