How does Microsoft.SPOT.Hardware.Cpu.Pin work?

Something I never thought much about. (Guess I should have)

Use to my Spider (Just does it’s thing from Visual Studio) and I never have to worry…

My ChipworksX and G400-D a different matter.

Example using the common Gadgeteer Button Module on a G400HDR

Socket 9 Pin 3 G400_96 ( JP1_35, PB18 / IRQ / ADTRG )
Socket 9 Pin 4 G400_200 ( JP1_3, PA7 / TXD2 ) - (COM4 TXD / SPI0 NPCCS1)

Using Socket 9 Pin 4 for OutputPort

(Cpu.Pin)G400.Pin.PA7 ID returns GPIO_Pin7
(The Gadgeteer Button module LED)

Using Socket 9 Pin 3 InterruptPort

(Cpu.Pin)G400.Pin.PB18 ID returns 50
(The Gadgeteer Button module switch output)

(Cpu.Pin)G400.Pin.PA7 ID = GPIO_Pin7 maps to G400-D processor Pin 200
(??? on schematic)

(Cpu.Pin)G400.Pin.PB18 ID = 50 maps to G400-D processor Pin 96 (PC6)

I do not see the relation of the ID to the actual processor pin number.
Can someone explain this to me?

using G400 = GHI.Hardware.G400; //FEZ Hydra

static OutputPort LED;
static InterruptPort Socket9Button;

LED = new OutputPort((Cpu.Pin)G400.Pin.PA7, true);
Debug.Print("Button LED using pin: " + LED.Id.ToString());

Socket9Button = new InterruptPort((Cpu.Pin)G400.Pin.PB18, false,
                Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
Debug.Print("Button interrupt using pin: " + Socket9Button.Id.ToString());

The code works.

Visual Studio Debug Output
Button LED using pin: 7
Button interrupt using pin: 50


A MCU can be provided in different packages, even with different number of pins (balls). So PA7 can be a pin 1 or 200, or any other pin on the physical chip.

In G400 case it is not even a chip’s pin, but the pin on the socket. And it happens that PA7 was routed to pin 200 on the socket by GHI.

@ Architect -

So PA7 can be a pin 1 or 200, or any other pin on the physical chip.

‘or any other pin on the physical chip’ That is why I was asking…

MCU I’m not sure I know what that is. Does the Premium library provide it?
Something I can look at?

MCU - microcontroller unit.

I am not sure we will have schematics of the actual G400 unit, but the pinout information is more than enough in this case.

Also, in pin relation, MCUs have a number of General Purpose Input and Output pins (GPIO) that, when enumerated, start out usually at 0 and go to the maximum GPIOs available.

In the case of G400, there are 32 pins on 4 different ports, A, B, C, and D. which would lead to an approximate total of 32 x 4 = 128 (port D is fewer than 32). So, a math equation of (Port * 32) + Pin is usually the key to understanding the relation. For PA7 to equal pin ID 7 you take (0 * 32) + 7 will equal 7 and PB18 equals (1 * 32) + 18 to equal pin ID 50.

For the Cerb family, the ports only go to 16 but the general equation will work the same.


@ Aron -


I copied your text and put it in my notes folder… I’ll study it later and write some tests and see what happens.

As a side note:

I wanted to know so I do not try to write a digital port voltage to some pin that does not like a digital level (Maybe this is not even possible) but I do stupid things at times…

@ Architect -

MCU I was thinking you we talking about some kind of translation table in code…

just for future reference: when the beta period is over, the brochure will be maintained at right now we have it in two places so all the beta materials can be found in one folder.