8 years, 11 months ago.

Port mask operation unclear from example

The PortIn example contains the following line:

PortIn p(Port2, 0x0000003F); p21-p26

I am afraid that I must be obtuse. I can't see how the "0x0000003F" mask relates to pins 21-26. I would think that "0x0000003F" would refer to pins 0-5. This, of course, assumes that pin 0 is, as typical, the least significant integer bit.

Can anyone shed some light on how the mask should be calculated?

Question relating to:

Thanks for this. I really like what you've posted here and wish you the best of luck with this blog! https://www.brotherprintersupportnumber.com/blog/how-to-fix-brother-printer-error-code-0x803c010b/

posted by Albert John 22 Nov 2018

3 Answers

8 years, 11 months ago.

On the mbed LPC1768 pins 21 - 26 connect to LPC1768 Port 2 as follows:

pin 21 = Port 2 bit 5
pin 22 = Port 2 bit 4
pin 23 = Port 2 bit 3
pin 24 = Port 2 bit 2
pin 25 = Port 2 bit 1
pin 26 = Port 2 bit 0

The 6 least significant bits of Port 2 are used, hence the PortIn mask is 0x0000003F.

Accepted Answer
8 years, 11 months ago.

The example is for the LPC1768, which has its pins numbered in ascending order for easy usage, but besides that there are also the 'real' pinnames, which are like P2_20. So thats why that mask has different values than 21-26.

8 years, 7 months ago.

Hello guys I am in trouble too. I can' t really get how to use pins like P0.18 Which bitmask should I use? I need 8 pins used as a PortIn. Any Ideas? thanks

In that notation it is easy: Port 0, bitmask 1<<18 should work.

posted by Erik - 22 Sep 2015

And for multiple pins do a logical OR of the pin masks. e.g. for pins P0.18, P0.19 and P0.21...

PortIn p(Port0, 1<<18 | 1<<19 | 1<<21);

posted by Andy A 22 Sep 2015