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

Read / Write Port by byte via Tris


  • Please log in to reply
6 replies to this topic

#1 thosey

thosey

    New Member

  • Members
  • Pip
  • 3 posts

Posted 23 October 2012 - 03:30 AM

How can I read and write the Tris ports via a byte. Common functionality on most micro controllers however I can not figure it out on the Netduino. Arduino example: DDRB = 0xFF; // Set PortB to outputs. PORTB = 0x00; // Set all pins to low.

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 23 October 2012 - 05:21 AM

Hi thosey, NETMF accesses pins individually rather than as ports. You can use the TristatePort class to manage the pins (as well as OutputPort, InputPort, and InterruptPort). Chris

#3 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 23 October 2012 - 12:53 PM

How can I read and write the Tris ports via a byte. Common functionality on most micro controllers however I can not figure it out on the Netduino.

Arduino example:
DDRB = 0xFF; // Set PortB to outputs.



In Netduino:
static OutputPort[] DDRB_8 = new OutputPort[8];

DDRB_8[0] = new OutputPort(Pins.GPIO_PIN_D0,True);
:
:
:
DDRB_8[7] = new OutputPort(Pins.GPIO_PIN_D7,True)



In PORTB = 0x00; // Set all pins to low(clear all PORTB). U don't needed to do this


Hope that help!



#4 thosey

thosey

    New Member

  • Members
  • Pip
  • 3 posts

Posted 24 October 2012 - 02:18 AM

Thank you Chris and Supra, I am not to pleased with this. Very lacking in my opinion; however, I will have to accept. Thanks again.

#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 24 October 2012 - 03:54 AM

Hi thosey, This is something that could be added as a native code addition to the firmware. Just FYI. Chris

#6 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 24 October 2012 - 05:54 AM

This is something that could be added as a native code addition to the firmware. Just FYI.

I must admit that although I've been doing this with the STM8's for a while now it's only just occurred to me how useful it could be to be able to latch data onto a number of OutputPorts in a single step. Alright, we could probably write a class which does this but it would not be instantaneous because of the nature of NETMF.

Regards,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#7 thosey

thosey

    New Member

  • Members
  • Pip
  • 3 posts

Posted 25 October 2012 - 05:13 PM

Thanks Chris and Mark. Yes, sometimes it is nice to cut out overhead from needing functions and classes. This will improve both speed and memory even for an interpreted JIT compiled VM. Since OutputPort and InputPort are both a class and not a function it demands more memory location than even a simple static class with functions. Hence a static class only needs to be invoked once and thus keeps the user from using memory to invoke other classes for other I/O ports. I think that you have a great product for the hobbyist or a new programmer that never had to bit bang and compress code to fit within memory confinements; but, those of us that have had to contain with memory confinements tend to rely on our old habits of compression. The only problem is having a byte that is global in scope versus encapsulated and protected within a class. I will try to provide a sample of the benefit. Note that I did not test either code so I may have some mistakes in here. I think Mark was seeing my meaning here. Example 1: Code should produce a much smaller memory with much more speed in either a JIT VM or assembly hex code file. DDRB = 0x0F; // Set PortB LSB to outputs and MSB to inputs. PORTB = 0x00; // Set all LBS pins to low. MSB are inputs and ignored. if((PORTB & 0x90) == 0x10) // Check to see if bit7 = 0 and bit4 = 1 { PORTB = 0x0F & 0x06; // Turn on bit2 and bit1 } Example 2: Compared to perhaps an easier to understand c# object based program that at a minimum creates 8 objects with overhead. OutputPort[] DDRB_LSB = new OutputPort[4]; DDRB_LSB[0] = new OutputPort(Pins.GPIO_PIN_D0, false); DDRB_LSB[1] = new OutputPort(Pins.GPIO_PIN_D1, false); DDRB_LSB[2] = new OutputPort(Pins.GPIO_PIN_D2, false); DDRB_LSB[3] = new OutputPort(Pins.GPIO_PIN_D3, false); // Just to keep the bits striaght create 8 objects instead of 4. InputPort[] DDRB_MSB = new InputPort[8]; DDRB_MSB[4] = new InputPort(Pins.GPIO_PIN_D4, false, Port.ResistorMode.Disabled); DDRB_MSB[5] = new InputPort(Pins.GPIO_PIN_D5, false, Port.ResistorMode.Disabled); DDRB_MSB[6] = new InputPort(Pins.GPIO_PIN_D6, false, Port.ResistorMode.Disabled); DDRB_MSB[7] = new InputPort(Pins.GPIO_PIN_D7, false, Port.ResistorMode.Disabled); if (!DDRB_MSB[7].Read() && DDRB_MSB[4].Read()) { DDRB_LSB[1].Write(true); DDRB_LSB[2].Write(true); } Thanks, Tim




1 user(s) are reading this topic

0 members, 1 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.