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

Any help on a ParallelIn SerialOut Bitshifter?


  • Please log in to reply
39 replies to this topic

#21 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 06 April 2011 - 08:23 PM

Got two 165's working in a serie right now with this schematic:

Posted Image

Software needs some improvements, comments and such, but that won't take too long. Yay! :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#22 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 April 2011 - 03:32 AM

Stefan, yesterday evening I was busy for a meeting. Happy to see that you were able to connect two shifters without troubles. What's next?
Biggest fault of Netduino? It runs by electricity.

#23 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 07 April 2011 - 06:07 AM

Next I'm going to finish the code :) Also, for now, I've got enough knowledge of how SPI works I suppose, so I'm going to document that all. After that, PWM will be next. I got a few servos, motor driver and led driver. It's still a big learning process here ;) -edit- just read that with NETMF4.2 a PWM class will be added, so I think I'm going to look into that then
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#24 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 April 2011 - 07:03 AM

The brand new scope and the pwm is the perfect marriage! I begin having fewer time for this kind of games, because I am involved as organizer in the next spring country fest. Anyway, with the little time I may find, I'd like to try to write my own native library, because I think there are many serious gaps in the current framework. Cheers
Biggest fault of Netduino? It runs by electricity.

#25 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 07 April 2011 - 07:45 AM

I begin having fewer time for this kind of games, because I am involved as organizer in the next spring country fest.
Anyway, with the little time I may find, I'd like to try to write my own native library, because I think there are many serious gaps in the current framework.

Indeed. I also found that out while working with SPI.

Strange SPI things I found:
  • SPI is made for multiple devices on one serial bus, but the NETMF doesn't have a decent way to handle this. Wait until my MultiSPI wrapper-class is done! I improved this very nicely B)
  • SPI read-only isn't possible. For example, I connected the 74HC165s with three cables: SS, MISO, SCLK. Should be enough, appairently it's enough since it works. But there isn't a SPI.Read() function, I still have to write the exact same number of bytes I want to read with SPI.WriteRead(). I tried to write 0 bytes and read 2 but that won't work. Writing 1 byte and wanting to read 2 makes everything hang. But there is no way it could write a thing since there is no MOSI connected! Therefore I'm considering to make a Read()-method in my wrapper-class that writes empty bytes and reads everything.

"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#26 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 07 April 2011 - 08:05 AM

I tried to write 0 bytes and read 2 but that won't work. Writing 1 byte and wanting to read 2 makes everything hang.

Have you tried passing 'null' write buffer?

#27 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 07 April 2011 - 08:17 AM

Have you tried passing 'null' write buffer?

not yet, good one, going to try that tonight! Still, my point that a Read() only function is lacking is a fact ;) If null works, I'm going to use that in my wrapper.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#28 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 April 2011 - 09:01 AM

Have you tried passing 'null' write buffer?

I think it's a good idea, but *ANYWAY* never never the systems should hang because any data has been passed wrong. Maybe failing the operation, but hanging must be avoided as the hell.

Stefan, consider also that I am still scared about the occupation of the TinyCLR itself, which is missing of many libs. So, by adding redundant calls or whatever else, is going only worser.
Ciao
Biggest fault of Netduino? It runs by electricity.

#29 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 07 April 2011 - 09:06 AM

It really hang. Couldn't even deploy stuff. I had to keep te reset button pressed and released it during the deployment of the correct code. Could be a bug indeed. But tonight I'm going to use null. Sounds plausible.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#30 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 07 April 2011 - 11:49 AM

Too bad
SPI.Configuration cnf = new SPI.Configuration(Pins.GPIO_PIN_D10, false, 0, 0, false, false, 1000, SPI_Devices.SPI1);
SPI spi = new SPI(cnf);

byte[] wb = new byte[3];
byte[] rb = new byte[3];
spi.WriteRead(wb, rb);

spi.WriteRead(null, rb);
it breaks on the last line with:

An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#31 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 07 April 2011 - 12:08 PM

Sorry, my bad, the write buffer cannot be null. Anyway, you should be able to read from the slave device with only MISO and SCK connected, but you have to write the same number of bytes as you want to read - the content of slave's circular buffer is shifted on clock edge, Netduino needs the write buffer to generate necessary clock pulses. Thus, spi.WriteRead(wb, rb); should work (assuming the configuration is correct).

#32 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 07 April 2011 - 12:14 PM

Okay, then my MultiSPI wrapper-class will get a method a bit like this:
public void Read(byte[] ReadBuffer)
{
    byte[] WriteBuffer = new byte[ReadBuffer.Length];
    _spi.WriteRead(WriteBuffer, ReadBuffer);
}

:D
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#33 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 07 April 2011 - 12:20 PM

public void Read(byte[] buffer)
{
   _spi.WriteRead(buffer, buffer);
}
Posted Image

#34 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 07 April 2011 - 12:21 PM

public void Read(byte[] buffer)
{
   _spi.WriteRead(buffer, buffer);
}

Darn, you're clever mate! B)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#35 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 11 April 2011 - 06:44 AM

With all your help I got the following code working. I need to add some comments and do some cleanup before release but it will definitely be this week.

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using StefanCo.NETMF.Hardware;

namespace NetduinoApplication1
{
    public class Program
    {
        // In the global scope so the leds will be available at all time
        private static OutputPortShift[] Leds = new OutputPortShift[16];

        public static void Main()
        {
            // We have two 74HC165 IC's in a chain
            Ic74HC165Chain ChainIn = new Ic74HC165Chain(SPI_Devices.SPI1, Pins.GPIO_PIN_D10, 2);
            Ic74HC165 IcIn1 = new Ic74HC165(ChainIn, 0);
            Ic74HC165 IcIn2 = new Ic74HC165(ChainIn, 1);

            // We have two 74HC595 IC's in a chain
            Ic74HC595Chain ChainOut = new Ic74HC595Chain(SPI_Devices.SPI1, Pins.GPIO_PIN_D9, 2);
            Ic74HC595 IcOut1 = new Ic74HC595(ChainOut, 0);
            Ic74HC595 IcOut2 = new Ic74HC595(ChainOut, 1);

            // All together, we got 16 Interrupt Ports
            InterruptPortShift[] Buttons = new InterruptPortShift[16];
            Buttons[0] = new InterruptPortShift(IcIn1, Ic74HC165.Pins.GPI_PIN_D0, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[1] = new InterruptPortShift(IcIn1, Ic74HC165.Pins.GPI_PIN_D1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[2] = new InterruptPortShift(IcIn1, Ic74HC165.Pins.GPI_PIN_D2, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[3] = new InterruptPortShift(IcIn1, Ic74HC165.Pins.GPI_PIN_D3, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[4] = new InterruptPortShift(IcIn1, Ic74HC165.Pins.GPI_PIN_D4, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[5] = new InterruptPortShift(IcIn1, Ic74HC165.Pins.GPI_PIN_D5, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[6] = new InterruptPortShift(IcIn1, Ic74HC165.Pins.GPI_PIN_D6, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[7] = new InterruptPortShift(IcIn1, Ic74HC165.Pins.GPI_PIN_D7, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[8] = new InterruptPortShift(IcIn2, Ic74HC165.Pins.GPI_PIN_D0, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[9] = new InterruptPortShift(IcIn2, Ic74HC165.Pins.GPI_PIN_D1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[10] = new InterruptPortShift(IcIn2, Ic74HC165.Pins.GPI_PIN_D2, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[11] = new InterruptPortShift(IcIn2, Ic74HC165.Pins.GPI_PIN_D3, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[12] = new InterruptPortShift(IcIn2, Ic74HC165.Pins.GPI_PIN_D4, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[13] = new InterruptPortShift(IcIn2, Ic74HC165.Pins.GPI_PIN_D5, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[14] = new InterruptPortShift(IcIn2, Ic74HC165.Pins.GPI_PIN_D6, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Buttons[15] = new InterruptPortShift(IcIn2, Ic74HC165.Pins.GPI_PIN_D7, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

            // And 16 Output Ports
            Leds[0] = new OutputPortShift(IcOut1, Ic74HC595.Pins.GPO_PIN_D0, false);
            Leds[1] = new OutputPortShift(IcOut1, Ic74HC595.Pins.GPO_PIN_D1, false);
            Leds[2] = new OutputPortShift(IcOut1, Ic74HC595.Pins.GPO_PIN_D2, false);
            Leds[3] = new OutputPortShift(IcOut1, Ic74HC595.Pins.GPO_PIN_D3, false);
            Leds[4] = new OutputPortShift(IcOut1, Ic74HC595.Pins.GPO_PIN_D4, false);
            Leds[5] = new OutputPortShift(IcOut1, Ic74HC595.Pins.GPO_PIN_D5, false);
            Leds[6] = new OutputPortShift(IcOut1, Ic74HC595.Pins.GPO_PIN_D6, false);
            Leds[7] = new OutputPortShift(IcOut1, Ic74HC595.Pins.GPO_PIN_D7, false);
            Leds[8] = new OutputPortShift(IcOut2, Ic74HC595.Pins.GPO_PIN_D0, false);
            Leds[9] = new OutputPortShift(IcOut2, Ic74HC595.Pins.GPO_PIN_D1, false);
            Leds[10] = new OutputPortShift(IcOut2, Ic74HC595.Pins.GPO_PIN_D2, false);
            Leds[11] = new OutputPortShift(IcOut2, Ic74HC595.Pins.GPO_PIN_D3, false);
            Leds[12] = new OutputPortShift(IcOut2, Ic74HC595.Pins.GPO_PIN_D4, false);
            Leds[13] = new OutputPortShift(IcOut2, Ic74HC595.Pins.GPO_PIN_D5, false);
            Leds[14] = new OutputPortShift(IcOut2, Ic74HC595.Pins.GPO_PIN_D6, false);
            Leds[15] = new OutputPortShift(IcOut2, Ic74HC595.Pins.GPO_PIN_D7, false);

            // We need to place an event on each button
            for (var i = 0; i < Buttons.Length; ++i)
            {
                // Points to the correct event handler
                if (i < 8) 
                    Buttons[i].OnInterrupt += new NativeEventHandler(IcIn1_OnInterrupt);
                else
                    Buttons[i].OnInterrupt += new NativeEventHandler(IcIn2_OnInterrupt);
                // Enables interrupts
                Buttons[i].EnableInterrupt();
            }

            // Now let's get the rest done by events
            Thread.Sleep(Timeout.Infinite);
        }

        static void IcIn1_OnInterrupt(uint PinId, uint Value, DateTime Time)
        {
            Leds[PinId].Write(Value == 0 ? true : false);
        }

        static void IcIn2_OnInterrupt(uint PinId, uint Value, DateTime Time)
        {
            Leds[8 + PinId].Write(Value == 0 ? true : false);
        }

    }
}

This is the hardware setup (click on it for a bigger picture):
Posted Image
(with this schematic only one LED should be active at the same time, but only one resistor spared me some matarials and space on the breadboard ;) )
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#36 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 11 April 2011 - 07:08 AM

Stefan, does the '165 wrapper run on a proprietary thread to poll the inputs?
Biggest fault of Netduino? It runs by electricity.

#37 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 11 April 2011 - 07:19 AM

Stefan, does the '165 wrapper run on a proprietary thread to poll the inputs?

yep, but that seperate thread only starts when an interrupt is actually enabled and all interrupt ports use the same thread which actually exists in the class Ic74HC165Chain.
I know it can become a performance issue, but the alternative is a more complex schematic. So I guessed as soon as performance gets an issue the developer just must get more creative ;)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#38 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 30 April 2011 - 04:02 PM

Hi Stefan, I looked at your code for bitshifter ... cool :) How can we integrate it with microliquidcrystal lcd class ? It is a question of integrating a new transport but I don't know how to do that lol And did I see correctly, you re-read all pins for each pin status read ? wonder why ! Keep the good work ! Check this link : http://geekswithblog...id_crystal.aspx A sample with connections and code would be cool ! Mike.
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#39 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 30 April 2011 - 07:29 PM

How can we integrate it with microliquidcrystal lcd class ? It is a question of integrating a new transport but I don't know how to do that lol

That's something I have still to work on, haven't done it yet but it's quite possible!

And did I see correctly, you re-read all pins for each pin status read ? wonder why !

I can't read a single bit from a bitshift IC. To get the current state of a pin, I have to read them all.

Check this link :

http://geekswithblog...id_crystal.aspx

Remember I gave you that link in chat once? :D
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#40 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 30 April 2011 - 09:07 PM

Remember I gave you that link in chat once? :D

LoL me and my short term memory ...
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !




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.