This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pullup Resistors

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.

Parents
  • 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.

Reply
  • 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.

Children
No data