I am writing a GPIO input object that reads the pinstate of GPIO port 0. I am putting in a feature where the different pull resistor states can be specified. They are done so with an enum type in the header. One problem, the code has no effect. The default state of the pin does not change. I am almost certain the values in the pinmodes are right as I checked them with the debugger. I have a feeling there is something simple I am overlooking.
switch(GetPullType()) // Connect specified pull resistor. { case PULLDOWN: LPC_PINCON->PINMODE0 |= (1 << gPinNumber); LPC_PINCON->PINMODE0 |= (1 << gPinNumber + 1); break; case PULLUP: LPC_PINCON->PINMODE0 &= ~(1 << gPinNumber); LPC_PINCON->PINMODE0 &= ~(1 << gPinNumber + 1); break; default: LPC_PINCON->PINMODE0 &= ~(1 << gPinNumber); LPC_PINCON->PINMODE0 |= (1 << gPinNumber + 1); break; }
I checked the inputs with a volt meter. Here is what I read in each mode for any specified pin:
PULLDOWN = 4.3 volts PULLUP = 4.36 volts PULLNONE = 4.35 volts
According to these voltages, the default pullup mode is not changing. I am using the LPC1768 controller with an MCB1700 development board.
Thanks, I was using the wrong formula all along! Still, there are only pulldown resistors work for P0.0 through P0.3. Is this because they have I2C on them as well as the A to D? I cannot seem to find where it says this in the manual. Probably just a footnote somewhere. Where does it say this so I can compensate in my program?
Thanks, Ben
Almost all GPIO have the same options. An exception is I2C signals with open-drain and a need for external pull-up/down.
Thanks, all working now.
I guess you did realize that my rewritten code (where I showed you that you need to multiply bit number with two) can be further optimized from:
LPC_PINCON->PINMODE0 |= (1 << (2*gPinNumber)); LPC_PINCON->PINMODE0 |= (1 << (2*gPinNumber+1));
into:
LPC_PINCON->PINMODE0 |= (3 << (2*gPinNumber));
And the magic value 3 could be changed into a constant named INPUT_MODE_PULLDOWN, to make it easier to see what the statement is intended to do. Of course, INPUT_MODE_PULLDOWN (3) is the only mode setting possible with just an bit-or operation. The other modes needs bit-not-and to clear one or both bits.