Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

I2C DS1621 Problem after Upgrade to SDK 4.2


  • Please log in to reply
1 reply to this topic

#1 Armin Schlueter

Armin Schlueter

    New Member

  • Members
  • Pip
  • 1 posts

Posted 23 August 2011 - 03:19 PM

Hello!

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


#2 GregR

GregR

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationKeller, Tx

Posted 07 September 2012 - 06:54 PM

Did you ever get this working? I have been playing with a DS1621 and I cannot get a temperature reading out of that thing at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.