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

how to define gpio pins and generate pwm on gpio pins?

Hi There, i am new to nrf51822 and new to program this kind of controller.I searched over the website, I couldn't find a good introductory documentation for programming the nrf51822, specifically the nrf51-dk. i have two problems 1.i want to connect a led and buzzer to gpio pins of nrf51822 so how to declare gpio pins in program for ex. suppose if i press button on nrf board the buzzer connected to gpio pins (for (ex. p0.0) should be on (make some sound). 2.i want to generate a pwm on gpio pin (for ex on p0.1) how to declare this pin as output for pwm how to use functions to declare gpio,led and other stuff as i gone through the tutorial it is not well defined and the tutorials are very much confused and easy to understandable can anybody give me the good explnation about this a good tutorial with each and every line explained will be great help!! Regards, Abhijeet Kapse

Parents
  • Hi,

    As an introduction, I would recommend the Getting Started guide and our examples in the SDK. For PWM generation on the nRF51, you should take a look at the PWM library example. You can find the example in the folder: <SDK_InstallFolder>\examples\peripheral\pwm_library

  • hey,Sigurd how to initialize gpio pins i want to generate a pwm on gpio pins so how to define pin number and its configuration in a function please give me a short example so i can understand it properly. i have already define pins but my program is not working properly this my program:

    #include <stdbool.h> #include <stdint.h> #include "nrf_delay.h" #include "nrf_gpio.h" #include "boards.h" #include "bsp.h" #include "nrf.h" #include "nrf_gpio.h" #include "nrf_delay.h" #define pin_number 5 //#include "nrf_drv_gpiote.h" #define NRF_GPIO_PIN_MAP(port,pin) ((port << 5) | (pin & 0x1F)) //const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;

    /**

    • @brief Function for application main entry. */ int main(void) { for(int i=0;i<=20;i++) { nrf_gpio_cfg_output(5); nrf_gpio_pin_set(5); nrf_delay_ms(10); nrf_gpio_pin_clear(5); nrf_delay_ms(20); } whats wrong with my code ..i am using a just simple for loop for a simple pwm generation great help appreciated!!!
Reply
  • hey,Sigurd how to initialize gpio pins i want to generate a pwm on gpio pins so how to define pin number and its configuration in a function please give me a short example so i can understand it properly. i have already define pins but my program is not working properly this my program:

    #include <stdbool.h> #include <stdint.h> #include "nrf_delay.h" #include "nrf_gpio.h" #include "boards.h" #include "bsp.h" #include "nrf.h" #include "nrf_gpio.h" #include "nrf_delay.h" #define pin_number 5 //#include "nrf_drv_gpiote.h" #define NRF_GPIO_PIN_MAP(port,pin) ((port << 5) | (pin & 0x1F)) //const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;

    /**

    • @brief Function for application main entry. */ int main(void) { for(int i=0;i<=20;i++) { nrf_gpio_cfg_output(5); nrf_gpio_pin_set(5); nrf_delay_ms(10); nrf_gpio_pin_clear(5); nrf_delay_ms(20); } whats wrong with my code ..i am using a just simple for loop for a simple pwm generation great help appreciated!!!
Children
No Data
Related