July 13, 2015 | Electronics |
Before you read further, please take a look at my previous article on nRF51-DK programming using GCC, since we’re going to use the same setup here.
This is a simple example that demonstrates PWM, GPIOTE, and NUS (Nordic UART Service) using the S110 softdevice on the nRF51-DK. This example uses the nRF51 SDK version 9.0.0. To use it, modify pca10028/s110/armgcc/Makefile to point SDK_ROOT to your nRF51 SDK directory.
I have tried to remove all unnecessary layers (like the Nordic BSP support) to make this example simple to understand. It uses instances PWM1 and PWM2 associated with Timer1 and Timer2 respectively, and each of them support two PWM channels each. I have used pins 21, 22, 23, 24 for these channels, corresponding to LED1, LED2, LED3 and LED4 on the nRF51-DK (PCA10028) board. Notice that to use these timers, I have enabled them in config/nrf_drv_config.h.
When you upload this code, the LEDs will pulse as shown in the above video. In addition, if you press the switches SW1 and SW2 on the board, it will toggle PWM on LED1 and LED2 respectively. SW1 works by reading the actual value of pin 17, whereas SW2 works using GPIOTE events.
You will also see this appear as a BLE device called PWM and you will be able to communicate with it using UART over BLE using the Nordic nRFToolbox app.
You can get the source code for this project here:
- Nordic nRF51 SDK version 9.0.0 documentation.
Need help with a hardware project or product? Drop us an email at email@example.com. We offer consulting services on AVR and Nordic nRF BLE - hardware design, firmware development, prototyping, PCB design/assembly, sourcing and manufacturing. We can help you bring your product to market!
Bluey nRF52 BLE IoT dev board
We love hearing from our readers. Email us at firstname.lastname@example.org for questions or comments on this article. If you found this article useful, please support us by buying some of our hardware products.