- written by Seunghee Han to help nRF beginners
- based on: nRF52832 development kit pca10040, SES Mac ver.
- nRF52832 is the bluetooth chip on one of the smallest bluetooth module in the world, TAIYO YUDEN EYSHSNZW
- tips when coding:
- open the main.c file with VSCode and edit there since it has much better interface than SES
- open the project in SES. when you change anything in the main.c in VSCode, SES will update it immediately (and vice versa)
- when you want to know more about a particular nrf function/variable/… , right click it on SES > go to definitions to see the definition in the header file
- very useful youtube channel on SES tutorials!!
- helpful blog on nrf52 programming
- contents
nRF Basics
- uint16_t: unsigned int 16 bits (0~65,535). uint8_t: unsigned int 8 bits (0~255)
- why not use just int or short sth like this? these may vary in size across different platforms/systems → uint16,8_t used for embedded systems
- legacy driver (nrf_drv_… ) vs. new (nrfx_…)
- uploading code to evaluation board (development kit): Build solution → target>Download “project name”
- uploading code to the chip (not evaluation board)
BLE Basics
Timer
nrfx_timer.c & nrf_timer.h ← look at these files for implementation details
- define timer:
const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0); — using TIMER0
- nrf52832 has 5 timers, each timer has 4 compare channels/registers
- nRF Timer has 2 modes:
- Timer mode: ticks at a fixed frequency
- In Timer mode, the TIMER's internal Counter register is incremented by one for every tick of the timer frequency fTIMER.
- each timer instance has 4 compare channels/registers, so you can set up 4 timer compare events for each timer
- Counter mode: event-based counting
- In counter mode, the TIMER's internal Counter register is incremented by one each time the COUNT task is triggered, meaning the timer frequency and the prescaler are not utilized in counter mode.
- In counter mode, a COMPARE event is generated when the Counter is incremented and then becomes equal to the value specified in one of the capture compare registers. When the Counter value becomes equal to the value specified in a capture compare register CC[n], the corresponding compare event COMPARE[n] is generated.
- this applies to the timer mode too, but the timer runs in automated ticks instead of being incremented by specific COUNT tasks
- for counter mode, clear_mask thingy doesn’t work. it only works in timer mode
- counting
- capturing
- can capture counter value into register (CC3), and read off the captured value by
m_counter.p_reg->CC[3];