using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Microsoft.SPOT.Hardware;
namespace DebugLED
{
public partial class Program
{
void ProgramStarted()
{
OutputPort debugled = new OutputPort((Cpu.Pin) 47, false);
Debug.Print("Debug LED is On? " + debugled.Read().ToString());
}
}
}
Any suggestions on how I could read it while it is already in use by the mainboard ?
If it can’t be read directly and you really want a hardware confirmation, why not a parallel connection to another pin that is set as an input and can be read?
I’ve seen the mainboard code that does that, basically I copy pasted it from there, but it’s a limitation I’m trying to overcome.
I’ve used a bool variable in the past to keep track of the pin value but that adds an extra layer of things to do while using the port.
I think the best approach would be to use a boolean variable. Later, when you are
more confortable with C# and the Micro Framework, you could look into how
to access the hardware registers.
Using the Register API is not a shortcut when you consider the learning curve.
The microprocessor uses memory mapped access to the registers. First you need to determine the CPU pin number for the bit you want to look at. You then need to determine what IO port contains that bit. You then need to determine the memory address of that port. You can then read the register, and then mask out all but the bit of interest. You now have what you are interested in.
I don’t know the shortest point to solution but it will require looking the hardware manual for the chip, the Spider Schematic, and a little code.
I would also look at the Gadgeteer source code for hints.
all i know is that the pin used is 47 and, if i got it right from the microprocessor datasheet, that the memory map from 0x3FFFC000 to 0x3FFFFFFF is for the fast GPIO registers. i also know that every register has 32 bits and for a pin there are 4 bits ? so a register manages 8 pins ? i think i’m walking in the dark now :))
any clues ? and how do i find out where is pin 47 stored in this range that i might have found ?
here is my update on this task: from the manual i’ve found that the pin 1.31 mapped to GPIO47 on the FezSpider is part of the “Table 133. Pin function select register 3 (PINSEL3 - address 0xE002 C00C) bit description” . Using this address for PINSEL3 I’ve written this code but the output does not change after I activate the debug LED.
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware.LowLevel;
using Gadgeteer.Modules.GHIElectronics;
namespace DebugLED
{
public partial class Program
{
void ProgramStarted()
{
button.ButtonReleased += new GTM.GHIElectronics.Button.ButtonEventHandler(button_ButtonReleased);
}
void button_ButtonReleased(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
{
Register pinsel3 = new Register(0xE002C00C);
Debug.Print("Before: " + pinsel3.Read().ToString());
Mainboard.SetDebugLED(true);
Debug.Print("Debug LED turned ON.");
Debug.Print("After: " + pinsel3.Read().ToString());
}
}
}
Output:
Before: 89478405
Debug LED turned ON.
After: 89478405
@ thisway.ro - You are manipulating/inspecting the pin function select register, the register indicats that the P1.31 is configured to act as a general purpose IO pin which is what would be expected. You need to be looking at the pin. You want to be looking at the value of the IOPIN register to read/set the value. The register table of the IOPIN register will probably be later in the user manual after the pin connection information that you are currently looking at.
Basically, the pins on the MCU can be connected to various peripheral within the MCU, so the first thing that needs to be done is to configure where the pin is connected inside the MCU, this is done using the PINSELx register, once the pin is corrected to the intended peripheral then you can manipulate the pin using that peripheral. So in your case you need the pin connected as a general purpose IO (GPIO) and your code is showing that it is already the case since bits 30:31 are both 0 which connects the pin as a GPIO.
from what i could understand so far the information i’m interested into should be stored in the bits 31 and 32 (a half-word) of the PINSEL3 register. is this so part correct ? if so, why the debug information does not change between when it’s set to false and true ?
The PINSEL register selects the function of the pin, not the state of the pin. Keep in mind that you count bits starting at 0 so you are interested in the bits 30 and 31.
You are on the right track, just looking at the wrong register.
Ok, i can understand that, in that case it makes sense that the debug information remains the same as the function of the pins does not change. But what is the name pattern of the register with the state of the pins ? i’m looking over the documentation and i got lost …