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.

vzgromozdun's Content

There have been 3 items by vzgromozdun (Search limited from 20-April 23)


By content type

See this member's

Sort by                Order  

#16975 Netduino 4.2 beta 1 + PCF8575 I2C Port expander

Posted by vzgromozdun on 23 August 2011 - 09:23 AM in Beta Firmware and Drivers

        Dim DEVICE_ID As UShort = &H70 >> 1 'pcf8574a address 0


Not clearly understand why your expander have such address.
Mine works just fine with default 0x20 address (all address pins of expander connected to GND).

Regards,
Dmitry



#16494 Netduino 4.2 beta 1 + PCF8575 I2C Port expander

Posted by vzgromozdun on 08 August 2011 - 07:28 PM in Beta Firmware and Drivers

Well, it works right now actually! I did stupid mistake - I have used digital ports 4 and 5 for I2C instead of analog ones. And another one correction - expander works fine with 5k pullup resistors.



#16096 Netduino 4.2 beta 1 + PCF8575 I2C Port expander

Posted by vzgromozdun on 31 July 2011 - 03:38 PM in Beta Firmware and Drivers

Hi All,

This is my first post here.

I have problems with connecting PCF8575 port extender to my netduino.

Goal: Implement trivial blink using port extender.
Actual result: there are always logical "1" at output ports.

Could anybody please look what I'm doing wrong?
Have red post about "i2c internal address" - i'm not 100% sure what this is required for me, but I have found in expander datasheet following:

To
write to the ports (output mode), the master first addresses the slave device, setting the last bit of the byte
containing the slave address to logic 0.



I'm using following hardware:

Wiring:
  • SCL - attached to pin 5
  • SDA - attached to pin 4
  • VCC - used pullup resitors to +5V
  • GND - nothing special

Here is my code:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using System.Reflection;

namespace NetduinoApplication1
{
    public class Program
    {
        static ushort DEVICE_ID = 0x20;

        public static void Main()
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            I2CDevice.Configuration conf = new I2CDevice.Configuration(DEVICE_ID, 100);
            I2CDevice dev = new I2CDevice(conf);

            while (true)
            {
                led.Write(true);
                I2CDevice.I2CWriteTransaction writeUpTrans = CreateWriteTransaction(new byte[2] { 255, 255 }, DEVICE_ID, 1);
                int sended = dev.Execute(new I2CDevice.I2CTransaction[] { writeUpTrans }, 1000);
                Thread.Sleep(100);

                led.Write(false);
                I2CDevice.I2CWriteTransaction writeDownTrans = CreateWriteTransaction(new byte[2] { 0, 0 }, DEVICE_ID, 1);
                sended = dev.Execute(new I2CDevice.I2CTransaction[] {  writeDownTrans }, 1000);
                Thread.Sleep(100);

            }
        }

        static I2CDevice.I2CWriteTransaction CreateWriteTransaction(byte[] buffer, uint internalAddress, byte internalAddressSize)
        {
            I2CDevice.I2CWriteTransaction writeTransaction = I2CDevice.CreateWriteTransaction(buffer);
            Type writeTransactionType = typeof(I2CDevice.I2CWriteTransaction);

            FieldInfo fieldInfo = writeTransactionType.GetField("Custom_InternalAddress", BindingFlags.NonPublic | BindingFlags.Instance);
            fieldInfo.SetValue(writeTransaction, internalAddress);

            fieldInfo = writeTransactionType.GetField("Custom_InternalAddressSize", BindingFlags.NonPublic | BindingFlags.Instance);
            fieldInfo.SetValue(writeTransaction, internalAddressSize);

            return writeTransaction;
        }

        static I2CDevice.I2CReadTransaction CreateReadTransaction(byte[] buffer, uint internalAddress, byte internalAddressSize)
        {
            I2CDevice.I2CReadTransaction readTransaction = I2CDevice.CreateReadTransaction(buffer);
            Type readTransactionType = typeof(I2CDevice.I2CReadTransaction);

            FieldInfo fieldInfo = readTransactionType.GetField("Custom_InternalAddress", BindingFlags.NonPublic | BindingFlags.Instance);
            fieldInfo.SetValue(readTransaction, internalAddress);

            fieldInfo = readTransactionType.GetField("Custom_InternalAddressSize", BindingFlags.NonPublic | BindingFlags.Instance);
            fieldInfo.SetValue(readTransaction, internalAddressSize);

            return readTransaction;
        }
    }
}

Thanks in advance,
Dmitry




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.