This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Changing I/O pull from low to high

Other Parts Discussed in Thread: CC2540

Hi, We have had a board designed similar to the keyfob layout and modified the original Keyfob Peripheral code for our needs, however we could not get the button (specifically B3) presses to be recognised. It turns out the board designer has used high pull instead of low pull for the switch (I think that's what they're called?) and needs me to change the code on the CC2540.

Can anyone please give me a hint as to where/how I would change the pull on the I/O for B3 on the keyfob?

Many Thanks

  • Darren,

    Chapter 7 in the CC253x/4x User Guide has info on the GPIOs. You can find info about the different registers to set a GPIO pin as pull up or pull down.

  • Thank you Chatto,

    I'm on vacation now so will check that out next week.

    Thanks

  • Hi,

    would I be able to get any more help with this?

    I see that I need to set PDUP0 but I have no idea where/how?

    I used the SimpleBLEPeripheral as a starting point and it has no "PDUP" anywhere for me to change.

    Thanks

  • It is in the P2INP register, cf. the CC2540 user guide (http://www.ti.com/lit/pdf/SWRU191), Chapter 7.

  • Thanks, I have read that I'm just not too sure what line of code to put where.

    C isn't a language I know although i've managed to modify the SimpleBLE code for my needs. I just need to change the pull on the button now.

  • It sounds like you are working with SimpleBLEPeripheral, so find this function: HalKeyInit

    Do you have CC2540_MINIDK defined or not? Let's say that you do not, so you will be compiling the 2nd set of code below:

    #if defined ( CC2540_MINIDK )
      HAL_KEY_SW_1_SEL &= ~(HAL_KEY_SW_1_BIT);    /* Set pin function to GPIO */
      HAL_KEY_SW_1_DIR &= ~(HAL_KEY_SW_1_BIT);    /* Set pin direction to Input */
      HAL_KEY_SW_2_SEL &= ~(HAL_KEY_SW_2_BIT);    /* Set pin function to GPIO */
      HAL_KEY_SW_2_DIR &= ~(HAL_KEY_SW_2_BIT);    /* Set pin direction to Input */
    #else
      HAL_KEY_SW_6_SEL &= ~(HAL_KEY_SW_6_BIT);    /* Set pin function to GPIO */
      HAL_KEY_SW_6_DIR &= ~(HAL_KEY_SW_6_BIT);    /* Set pin direction to Input */
      HAL_KEY_JOY_MOVE_SEL &= ~(HAL_KEY_JOY_MOVE_BIT); /* Set pin function to GPIO */
      HAL_KEY_JOY_MOVE_DIR &= ~(HAL_KEY_JOY_MOVE_BIT); /* Set pin direction to Input */

      P2INP |= PUSH2_BV;  /* Configure GPIO tri-state. */
    #endif

    Now, you want pull, so you will not enable the GPIO tri-state like the default behavior above, so just comment out the line. If you want pull-up (h/w reset default), you're done! If you want pull-down, then the above snippet will look like this:


      // I need pull  P2INP |= PUSH2_BV;  /* Configure GPIO tri-state. */

    P2INP |= BV(7);  // I need pull-down.
    #endif

    Warning - you are re-configuring pull for all PORT2 pins, as gleaned from Ch.7:

    Bit-7 PDUP2 0 R/W Port 2 pullup/pulldown select. Selects function for all Port 2 pins configured as
    pullup/pulldown inputs.
    0: Pullup
    1: Pulldown

    Ensure that doing this does not cause any bad side effects in your h/w.

  • Thank you, thats just what I needed.

    I do have CC2540_MINIDK defined and needed Port 0 pins, so added P2INP |= BV(5) to the top section and it works.

    Thank you very much.