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

how do I change PWM port to 1 on example "low_power_pwm"

Hi, I have Design a new product based on the NRF52840 I am trying to get the lcd up and running so first thing is the pwm for the backlight. I am using pin 1.08 for the pwm. but I seem to have problem trying to convert LED1 to Port 1 I setup the Low_power_pwm example project and changed the defined board to Custom_board and copied PCA10056.h and renamed it custom_board it compiles fine and works but once I try to change the definition of LED1 It now compiles but will NOT toggle the output P1.8

here is the part of custom_board.h that I changed:

original: / LEDs definitions for PCA10056 #define LEDS_NUMBER 4

#define LED_1 NRF_GPIO_PIN_MAP(0,13) #define LED_2 NRF_GPIO_PIN_MAP(0,14) #define LED_3 NRF_GPIO_PIN_MAP(0,15) #define LED_4 NRF_GPIO_PIN_MAP(0,16)

#define LEDS_ACTIVE_STATE 0

#define LEDS_LIST { LED_1, LED_2, LED_3, LED_4 }

#define LEDS_INV_MASK LEDS_MASK

#define BSP_LED_0 13 #define BSP_LED_1 14 #define BSP_LED_2 15 #define BSP_LED_3 16

I made two changes: #define LED_1 NRF_GPIO_PIN_MAP(1,8) and the second change #define BSP_LED_0 8

the original compiled and worked in the Preview -DK using P0.13 after making this change it compiled and I downloaded it to my board and But I have NO output on port 1.8

What am I missing ?

Parents
  • FormerMember
    +1 FormerMember

    To get the correct pin numbers for pin P1.x, you can use ´NRF_GPIO_PIN_MAP()´in nrf_gpio.h.

    For example, pin P1.08:

    #define PIN_D7    NRF_GPIO_PIN_MAP(1,8) 
    

    By porting P1.8 this way, the value of PIN_D7 is 40 (32+8).

    However, low_power_pwm_init() requires a bit mask, which is a uint32_t. In that case, P1.08 is pin 8 on port 1:

    low_power_pwm_config.bit_mask       = (1 <<  NRF_GPIO_PIN_MAP(0,8)); 
    low_power_pwm_config.p_port         = NRF_P1;
    

    In low_power_pwm_init(), when configuring the output pin(s), the port is not taken care of. Therefore, to make the pwm driver work with port 1 pins, nrf_gpio_port_dir_output_set() has to be used to configure the pin in low_power_pwm_init():

     nrf_gpio_port_dir_output_set(p_pwm_config->p_port,p_pwm_instance->bit_mask); //todo
        //while (bit_mask)
        //{
        //    if (bit_mask & 0x1UL)
        //    {
        //        //nrf_gpio_cfg_output(pin_number);
        //    }
        //
        //    pin_number++;
        //    bit_mask >>= 1UL;
        //}
    
  • Thank you Kristin,

    I it was the Direction not getting set that I missed.

Reply Children
No Data
Related