Time in 2021 Nian 1 Yue 25 Ri , winter vacation home, a good school to learn
Development Board : snow's 100 head piece NRF52840 EVAL KIT
Download tool: JINLK V11 (preferably JLINK V9 or higher, some people use JLINK OB, other downloaders STLINK, DAP are not recommended)
Version number: KEIL5 programming environment, CMSIS is 5.3.0, CMSIS of NRF52840 is 8.35.0
Reference material: NRF52840-Eval-Kit-Schematic.pdf (Schematic)
nRF5_SDK_17.0.2_d674dde (official routine)
nRF5_SDK_17.0.0_offline_doc (official document)
Realization function: lighting, running water, flashing, etc.
Schematic diagram
LED light position is 13,14,9+32=41,16
When 13,14,41,16 is given low level, the LED is on
Use nrf_gpio_cfg_output to configure the IO port to output mode
code show as below
nrf_gpio_cfg_output(13);
nrf_gpio_cfg_output(14);
nrf_gpio_cfg_output(41);
nrf_gpio_cfg_output(16);
When the IO port output is 1, the LED is off, when the output is 0, the LED is on
Note: set is to set IO to 1, clear is to clear (IO is set to 0), toggle is to flip the IO state
code show as below
nrf_gpio_cfg_output(13);
nrf_gpio_cfg_output(14);
nrf_gpio_cfg_output(41);
nrf_gpio_cfg_output(16);
nrf_gpio_pin_set(13);
nrf_gpio_pin_set(14);
nrf_gpio_pin_set(41);
nrf_gpio_pin_set(16);
nrf_gpio_pin_clear(13);
Download and burn, you can find that there is indeed an LED on (IO13 is on)
We will also use a delay function
nrf_delay_ms(300);
Note, include the header file
#include "nrf_delay.h"
The flashing light program is as follows
while(1)
{
nrf_gpio_pin_toggle(13);
nrf_gpio_pin_toggle(14);
nrf_gpio_pin_toggle(41);
nrf_gpio_pin_toggle(16);
nrf_delay_ms(300);
}
The flow lamp program is as follows
while(1)
{
nrf_gpio_pin_clear(13);
nrf_delay_ms(300);
nrf_gpio_pin_set(13);
nrf_gpio_pin_clear(14);
nrf_delay_ms(300);
nrf_gpio_pin_set(14);
nrf_gpio_pin_clear(41);
nrf_delay_ms(300);
nrf_gpio_pin_set(41);
nrf_gpio_pin_clear(16);
nrf_delay_ms(300);
nrf_gpio_pin_set(16);
}
In addition, you can also use macro definitions to define the name of the lamp, such as LED0, LED1,...
Use NRF_GPIO_PIN_MAP to define
Then you can use LED0 instead of 13, such as
I'll learn here when you light the lamp, see you later