This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Accessing GPIO and timer/counter registers on nRF52832.

Hello,

So I am aware the nRF52832 utilizes the ARM cortex M4 microprocessor and has 32 configurable GPIO, but I'm failing to find how to access the registers controlling these, as well as the registers controlling the timer counter registers for PWM generation. I have experience with Atmel microprocessor register accessing, but have never worked with ARM or Keil before so my experience is quite limited. Is there a datasheet going over how to access the nRF52832's GPIO, or is this just in the Cortex-M4's datasheet?

Furthermore, how similar is coding in Keil compared to coding in Segger Embedded studio?

Thanks for any help.

Parents
  • 1) Get the nRF52832 reference manual from here:

    https://infocenter.nordicsemi.com/index.jsp?topic=%2Fstruct_nrf52%2Fstruct%2Fnrf52832.html&cp=3_1

    2) Get the ARM Cortex-M4 Generic User Guide from here:

    http://infocenter.arm.com/help/topic/com.arm.doc.dui0553b/DUI0553.pdf

    3) Get the Nordic 15.3.0 SDK from here:

    https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v15.x.x/

    Register windows on ARM are always memory-mapped. I know that Atmel ATmega processors have some special instructions for reading/writing registers but with ARM you just have to know the address where the window is located and do loads/stores.

    There are some register windows which are specific to the ARM Cortex-M4 and which will be present in any chip from any vendor that uses the Cortex-M4 CPU core in their design. The ARM Cortex-M4 Generic User Guide documents all of those, including ARM-specific components like the NVIC (interrupt controller), ARM Generic Timer and the MPU (memory protection unit).

    The bulk of the peripheral stack is designed by Nordic. The documentation for that is in the Nordic reference manual (product specification).

    In theory these two manuals should document everything in the chip.

    The SDK contains a number of "bitfields" files which contain structure overlay definitions that match the register window layouts. They also contain the base addresses. Note that there are separate files for each chip (the SDK has files for both the nRF52832 and nRF52840).

    For the GPIO controller, there is an NRF_P0 macro which defines the base address for the GPIO registers in the nRF52832. (Note: nRF52840 has  more pins, so it has both an NRF_P0 and NRF_P1 bank.) Registers are accessed like this:

        uint32 pin_state;

        pin_state = NRF_P0->IN;

        NRF_P0->OUTSET = 0x1;  /* Set pin 0 to high */

    Note that the register names match what's in the Nordic reference manual. This convention is also used by ARM in their own example software. Note however that the Nordic SDK has API libraries and wrappers for manipulating their own peripherals.

    -Bill

Reply
  • 1) Get the nRF52832 reference manual from here:

    https://infocenter.nordicsemi.com/index.jsp?topic=%2Fstruct_nrf52%2Fstruct%2Fnrf52832.html&cp=3_1

    2) Get the ARM Cortex-M4 Generic User Guide from here:

    http://infocenter.arm.com/help/topic/com.arm.doc.dui0553b/DUI0553.pdf

    3) Get the Nordic 15.3.0 SDK from here:

    https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v15.x.x/

    Register windows on ARM are always memory-mapped. I know that Atmel ATmega processors have some special instructions for reading/writing registers but with ARM you just have to know the address where the window is located and do loads/stores.

    There are some register windows which are specific to the ARM Cortex-M4 and which will be present in any chip from any vendor that uses the Cortex-M4 CPU core in their design. The ARM Cortex-M4 Generic User Guide documents all of those, including ARM-specific components like the NVIC (interrupt controller), ARM Generic Timer and the MPU (memory protection unit).

    The bulk of the peripheral stack is designed by Nordic. The documentation for that is in the Nordic reference manual (product specification).

    In theory these two manuals should document everything in the chip.

    The SDK contains a number of "bitfields" files which contain structure overlay definitions that match the register window layouts. They also contain the base addresses. Note that there are separate files for each chip (the SDK has files for both the nRF52832 and nRF52840).

    For the GPIO controller, there is an NRF_P0 macro which defines the base address for the GPIO registers in the nRF52832. (Note: nRF52840 has  more pins, so it has both an NRF_P0 and NRF_P1 bank.) Registers are accessed like this:

        uint32 pin_state;

        pin_state = NRF_P0->IN;

        NRF_P0->OUTSET = 0x1;  /* Set pin 0 to high */

    Note that the register names match what's in the Nordic reference manual. This convention is also used by ARM in their own example software. Note however that the Nordic SDK has API libraries and wrappers for manipulating their own peripherals.

    -Bill

Children
No Data
Related