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.

How do I read GPIO?

Other Parts Discussed in Thread: CC2540

So I gathered from this post (http://e2e.ti.com/support/low_power_rf/f/538/t/177958.aspx) that I can write GPIO by specifying the pin name and setting it equal to 0 or 1 (P0_6 = 1).

How can I read the value of, say, P0_5? And more importantly, how can I use that trigger an interrupt to call a function?

So far I have looked through the SWRU1C User's Guide, SWRU301a User's Guide, the TI_BLE_Sample_Applications_Guide, the TI_BLE_Software_Developer's_Guide, the  BLE_API_Guide_main.htm, and a few of the sample applications including the KeyFobDemo (which uses the button inputs) but that seems to rely on the HAL_KEY software pragma which requires the simplekeys.c which requires the Joystick(??) library.

Basically, I'm lost in too much documentation - can someone point me in the direction of some simple I/O operations to get me up and running?

  • Reading a port is achieved by reading the port register, e.g. to read P0_5 you could use:

    (P0 & 0x20)

    Where the result is true if P0_5 is high and false if P0_5 is low (assuming P0_5 is configured as an input).

    To trigger an interrupt on P0_5, you need to configure the P0 interrupt and ensure you have a P0 ISR. There are a number of registers to configure interrupts that will need to be modified. Refer to the CC2540 user guide interrupt section.

    If you have enabled an interrupt, you would only need to read the port to:

    1. Distinguish between multiple interrupt pins on the same port (if enabled) in the ISR

    2. Debounce or do further processing of the signal in the ISR

  • I have similar requirement and I have an external interrupt into P0.

    Any input pin in P0 can create an interrupt and I would like to have all 8 pins for P0 to enable interrupt.

    Can you tell me how to use IAR OSAL or HAL to do the coding?

    Since there is realtime constraint, I would like to do it as little interrupt latency as possible.

    Thanks for your help.

    Kan.