nRF51822 peripheral applications [2]:gpiote application-Key detection

Source: Internet
Author: User

Copyright Notice: This article is for bloggers original articles, reproduced please indicate the author and source. Strong Light Flashlight [ Ekrem Technology-Wireless business unit ]

1. nRF51822 Register Type

nRF51822 Register and the general microcontroller is different, the nRF51822 register is divided into the following three kinds.

    • Task: Mission register, which can be triggered by a program or event.
    • Events: Event registers, events can cause interrupts or trigger tasks.
    • Register: Ordinary registers, the same as the general microcontroller registers.

Task and event make it easy to operate on-chip peripherals and easily use a wide range of peripherals with minimal configuration. At the same time, task and event can effectively reduce CPU time, and reduce CPU load.

Task and event are used in conjunction with the PPI (programmable peripheral interconnect) to connect an event and a task through the PPI, which, when connected, triggers the corresponding task to perform the corresponding function.

Example: Implement the status of the LEDs every 1S flip.

    • General Practice: Configure timer Timing time of 1 s, generate an interrupt per second, in the Interrupt service program through the software operation to flip the status of the indicator. In this process, it must be done through software operations.
    • Through task and event implementation: Configure the relevant parameters of the timer , configure the Gpiote task as the rollover pin state, configure a channel for the PPI to connect the timer's matching events and the Gpiote task. In this way, when the timer produces a matching event, the Gpiote task is automatically triggered to flip the LED status without any software intervention.
2. Gpiote (GPIO Tasks and Events)2.1 Function Description

NRF51822 introduces the concept of tasks and events (Gpiote) on the basis of Gpio, nRF51822 Gpiote has 4 channels, each of which can select a PIN, and the selected PIN can be configured as task mode or event mode. It is important to note that a pin cannot be assigned to multiple gpiote channels at the same time, which can cause unexpected errors.

The Gpiote channel's task can be used to perform the following write operations:

    • Position.
    • Clear.
    • Flip.

Events can be generated by the following input states:

    • Rising edge.
    • Falling Edge.
    • Any level transition.
2.1.1 Pins tasks and Events

Tasks and events are configured through Config[n] (n=0~3) and each config[n] register corresponds to a set of out[n] task registers and In[n] event registers. Out[n] for the write pin, In[n] is triggered by a change in the pin state.

When a PIN is assigned to a out[n] task or in[n] event, the PIN is only written by the Gpiote module, and the normal Gpio write is not valid.

Once the Out[n] task or In[n] event is configured to control a PIN, the output value of the PIN can only be operated by the Gpiote module, and the register operation using the GPIO is ignored.

When the Gpiote channel is configured to operate on a task pin, the outinit in the config[n] register determines the initial value of the pin. You can configure the Outinit to set the PIN initialization status to high or low.

2.1.2 Port event

Gpiote contains a port event in addition to 4 channels. The port event is triggered by multiple pins using the Gpio detect signal, and the rising edge on any of the pins in the port triggers the port event.

You can set one or more Gpio detect to generate a port event that can be used as a wake-up source or as an interrupt source.

3. Key test procedure

The procedure used in this experiment is: Nrf51-app-button-example-master.

3.1 Operating Environment

    • Compilation environment: MDK5.
    • SDK version: SDK 8.0.0
3.2 Key Detection principle

The processing of the keys in the program is as follows: through the port event of the Gpiote to detect if there is a button press, when the check to press the button, the Start timer timer (bit 50ms set in the program), in the Timer timeout interrupt if it is detected that the key is still pressed state, it is considered to be a valid key. The timer (software timer) is used here to eliminate key jitter.

Figure 1: Key detection and jitter suppression

If the first key detection process is not finished (the button's timer is still running), and there is a button press, then the timer will start again, as shown in.

Figure 2: Multiple key handling

3.3 program Download and verification3.3.1 Program Download

There is no need to download the protocol stack for this experiment, and if the protocol stack has already been downloaded in the Development Board, it needs to be erased through NRF studio.

The program can be downloaded with Nrfgo Studio, or it can be downloaded directly in MDK, where we download it in Nrfgo Studio. Switch to the "Program Application" tab. Click the "Browse ..." button to open the hex file for the application (Gpiote_button.hex in the "... \ nrf51-app-button-example-master\pca10028 \arm5\_build" directory). Click "Program" to download the application.

3.3.2 Experimental Phenomena

Press the S1~s4 button individually, and the corresponding indicator (D1~D4) status will be flipped once per press.

nRF51822 peripheral applications [2]:gpiote application-Key detection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.