ADVANCED TECHNIQUES FOR DESIGN ENGINEERS
Post comments on this article and find any associated files and/or downloads at
n SCREENSHOT 1. The Configuration Wizard allows us
to easily change the nRF52832 peripheral configuration.
n SCREENSHOT 2. As you can see, the contents of the
sdk_config.h file can be altered by our selections within
the Configuration Wizard.
A scripting language allows us to create our own custom
sdk_config.h entries, which can be accessed via the
Recall that we have the ability to right-click on
types and be directed to their original definitions.
Here is what the nrf_drv_spi_t structure looks like:
@brief Macro for creating an SPI master driver
#define NRF_DRV_SPI_INSTANCE(id) \
.p_registers = NRF_DRV_SPI_PERIPHERAL(id), \
.irq = CONCAT_3(SPI, id, _IRQ), \
.drv_inst_idx = CONCAT_3(SPI, id, _INSTANCE_ \
.use_easy_dma = CONCAT_3(SPI, id, _USE_EASY_ \
///< Pointer to the structure with SPI/SPIM
///< peripheral instance registers.
///< SPI/SPIM peripheral instance IRQ number.
///< Driver instance index.
///< True if the peripheral with EasyDMA (SPIM)
///< shall be used.
The .p_registers statement is pretty straightforward.
The other definitions within the macro are just as easy to
understand if you do the concatenation:
.irq = SPI0_IRQ
.drv_inst_idx = SPI0_INSTANCE_INDEX
.use_easy_dma = SPI0_USE_EASY_DMA
If we keep right-clicking, we will find within the nrf52.h
file that SPI0_IRQ = 3. There is a definition to be found for
SPI0_INSTANCE_INDEX within the nrf_drv_spi.h file:
#define SPI0_INSTANCE_INDEX 0
Note that we used the nrf_drv_spi_t type to create the
spi0 structure. We populated the new structure using the
macro NRF_DRV_SPI_INSTANCE(SPI_INSTANCE). Using
the magic of right-clicking again, we can reveal the macro’s
The state of SPI0_USE_EASY_DMA is determined by
a setting within the Configuration Wizard. I’ve captured
the negative point of definition for DMA operation in
At this point, we have defined the SPI portal GPIO
pins and the spi0 instance. The SPI portal is being built to
transfer data. So, we will need to allocate some storage to
house the data that will be exchanged over our new SPI
portal. For this, we need not conjure up any nRF52832-
specific code. Just plain old C will work here:
#define txdata “NutsVolts”
static uint8_t m_tx_buf = txdata;
//extra byte in rx_buf for NULL character
static uint8_t m_rx_buf[sizeof(txdata) + 1];
//number of bytes to transfer = m_length
January 2017 57