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

Reading and Writing Bytes to Pins


  • Please log in to reply
10 replies to this topic

#1 bryancostanich

bryancostanich

    Advanced Member

  • Administrators
  • 62 posts

Posted 23 August 2010 - 01:24 AM

Hey all, is there a class someplace that does serial read/writes of bytes to pins? i see the hardware input port, but that just has a Read method which returns 0/1, so it would have to be wrapped. does that functionality exist already somewhere? what i need is like System.IO.Ports.SerialPort i imagine, but instead of creating it via a name like "Com1" or whatever, i would pass it a set of pins (or just one pin if i want read only access). i'd like to not go implementing something that already exists.

#2 bryancostanich

bryancostanich

    Advanced Member

  • Administrators
  • 62 posts

Posted 23 August 2010 - 02:15 AM

Can the Microsoft.SPOT.Hardware.SPI class be used for this somehow? it needs a configuration which needs a CPU pin, is there a map between the CPU pins and the netduino hardware pins?

#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 23 August 2010 - 03:00 AM

Can the Microsoft.SPOT.Hardware.SPI class be used for this somehow? it needs a configuration which needs a CPU pin, is there a map between the CPU pins and the netduino hardware pins?


The "Pins." enumeration contains the pin definitions for the Netduino pins. It's in the SecretLabs.NETMF.Hardware.Netduino namespace (which is included in Netduino applications by default).

Chris

#4 bryancostanich

bryancostanich

    Advanced Member

  • Administrators
  • 62 posts

Posted 23 August 2010 - 03:25 AM

So i can use that enumeration in place of the other? also, is this SPI class the answer? do you have any sample code by any chance?

#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 23 August 2010 - 03:34 AM

Yes, absolutely...the "Pins." enumeration returns a Cpu.Pin. You can use them anywhere that a Cpu.Pin is required in the .NET MF or SecretLabs namespaces. As to whether or not the SPI class is the answer to what you're trying to accomplish...can you give us an example of what you're trying to do? The SerialPort class will write serial data over D0/D1 or D2/D3. The SPI class will write SPI data over D11-D13. The I2C class will write I2C data over pins A4/A5. If those are what you need, then it's built in. If you're looking for something different, then we can make recommendations as to what to do (and whether to do it in managed C# or native code). We'll be releasing drivers for a number of shields alongside the v4.1.1 release in September. In the meantime... Here is an example of using SPI from a community member's code: http://forums.netdui...ch__1#entry1055 Chris

#6 bryancostanich

bryancostanich

    Advanced Member

  • Administrators
  • 62 posts

Posted 23 August 2010 - 05:08 AM

Yes, absolutely...the "Pins." enumeration returns a Cpu.Pin. You can use them anywhere that a Cpu.Pin is required in the .NET MF or SecretLabs namespaces.

As to whether or not the SPI class is the answer to what you're trying to accomplish...can you give us an example of what you're trying to do?

The SerialPort class will write serial data over D0/D1 or D2/D3. The SPI class will write SPI data over D11-D13. The I2C class will write I2C data over pins A4/A5. If those are what you need, then it's built in. If you're looking for something different, then we can make recommendations as to what to do (and whether to do it in managed C# or native code).

We'll be releasing drivers for a number of shields alongside the v4.1.1 release in September. In the meantime...

Here is an example of using SPI from a community member's code:
http://forums.netdui...ch__1#entry1055

Chris


got it, yes, that's what i want to do. last question, i don't see anything to configure typical serial setup stuff such as baud rate, parity bit, etc. is there a way to do that?

#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 23 August 2010 - 05:26 AM

got it, yes, that's what i want to do. last question, i don't see anything to configure typical serial setup stuff such as baud rate, parity bit, etc. is there a way to do that?


For serial baud rate, parity, etc. you can either use the System.IO.SerialPort constructor or set the properties of System.IO.SerialPort manually.

You'll also need to add a reference to the Microsoft.SPOT.Hardware.SerialPort.dll assembly to your project to use the serial port feature...

Chris

#8 bryancostanich

bryancostanich

    Advanced Member

  • Administrators
  • 62 posts

Posted 23 August 2010 - 05:44 AM

but serial port doesn't work for pins. i'm trying to get serial functionality on the digital input pins. for instance, i have a gps module that dumps raw data on a particular pin. i'd like to create a serial listener that listens on that pin at a certain baud rate, parity, etc.

#9 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 23 August 2010 - 05:56 AM

but serial port doesn't work for pins. i'm trying to get serial functionality on the digital input pins. for instance, i have a gps module that dumps raw data on a particular pin. i'd like to create a serial listener that listens on that pin at a certain baud rate, parity, etc.


You should hook the GPS module up to the RX line of serial port #1 (RX = pin D0) or serial port #2 (RX = pin D2). Schematics are here. Then use an instance of the System.IO.SerialPort class to read your GPS data. Some of our users have already built a GPS Parser if you'd like to use that as well.

The Atmel MCU natively provides SerialPort on certain pins--but if you're looking for custom serial support on digital pins other than those that the Atmel MCU provides then you'll need a native C++ driver and bit-banged communication.

Chris

#10 bryancostanich

bryancostanich

    Advanced Member

  • Administrators
  • 62 posts

Posted 23 August 2010 - 06:30 AM

ok. so this chip has 2 uarts, right? so i get two "true" serial interfaces (d0 rx, d1 tx, and d2 rx, d3, tx), that's what you're saying, correct? now, if i create a System.IO.SerialPort object, what is the named instance of those two serial interfaces, com1 and com2? now, on serial communication across other pins, true serial communications have been limited (traditionally) by the number of uarts on the chip, however, with modern chips, such as this, that's not really an issue with a proper message pump and, in this case (with .net), threading. i don't believe i need a native c++ driver. correct me if i'm wrong. (even if you do correct me, i'm going to try and prove that it's possible - i've been able to get it to work with a number of less powerful chips. :) ). hhahaha what i am hoping, however, is that i can wrangle an SPI to do this for me. we'll see. as far as the GPS parser, i'm going to go with this one: http://code.google.com/p/gpstalk/ - it's open source (i wrote it), and it appears much more feature rich than the other examples here i've seen. and.. it's being used in swedish missile guidance systems. hhahhahahah

#11 greg

greg

    Advanced Member

  • Members
  • PipPipPip
  • 169 posts
  • LocationChicago, IL

Posted 23 August 2010 - 11:40 AM

ok. so this chip has 2 uarts, right? so i get two "true" serial interfaces (d0 rx, d1 tx, and d2 rx, d3, tx), that's what you're saying, correct? now, if i create a System.IO.SerialPort object, what is the named instance of those two serial interfaces, com1 and com2?

now, on serial communication across other pins, true serial communications have been limited (traditionally) by the number of uarts on the chip, however, with modern chips, such as this, that's not really an issue with a proper message pump and, in this case (with .net), threading. i don't believe i need a native c++ driver. correct me if i'm wrong. (even if you do correct me, i'm going to try and prove that it's possible - i've been able to get it to work with a number of less powerful chips. :) ). hhahaha

what i am hoping, however, is that i can wrangle an SPI to do this for me. we'll see.

as far as the GPS parser, i'm going to go with this one: http://code.google.com/p/gpstalk/ - it's open source (i wrote it), and it appears much more feature rich than the other examples here i've seen. and.. it's being used in swedish missile guidance systems. hhahhahahah


Yes, D0/D1 are COM1 and D2/D3 are COM2.




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.