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

Default pin config = 31 is WRONG for nRF52840

in the sdk_config.h there are plenty of definitions, where "31" is used as a non-valid PIN value

This is destructive if you want to use p0.31

For example:

If one uses nrf_drv_pwm_init with {.driverConfig== NRF_DRV_PWM_DEFAULT_CONFIG} and changing only the pin you like, it will configure pin 0.31 as PWM !

You have to change the sdk_config.h default constants

Parents
  • Hi,

    For PWM you can use the NRF_DRV_PWM_PIN_NOT_USED define if you dont't want to use all the 4 channels in the PWM instance. With this method you don't need to change the sdk_config.h default vales. You can use NRF_DRV_PWM_PIN_NOT_USED like this:

    nrf_drv_pwm_config_t const config0 =
        {
            .output_pins =
            {
                BSP_LED_0 | NRF_DRV_PWM_PIN_INVERTED, // channel 0
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 1
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 2
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 3
            },
            .irq_priority = APP_IRQ_PRIORITY_LOWEST,
            .base_clock   = NRF_PWM_CLK_125kHz,
            .count_mode   = NRF_PWM_MODE_UP,
            .top_value    = 25000,
            .load_mode    = NRF_PWM_LOAD_COMMON,
            .step_mode    = NRF_PWM_STEP_AUTO
        };

  • I know. it was just an example, not the question.

    There is no reason that defaults equals 31, except for 31 being invalid pin number in OTHER-THAN-nRF52840 chips.

  • Pin 31 is a valid pin number in both nRF52832 and nRF52840.

    The GPIO Port peripheral implements up to 32 pins, PIN0 through PIN31. Each of these pins can be individually configured in the PIN_CNF[n] registers (n=0..31).

Reply Children
  • So why would a value called "NRF_DRV_PWM_DEFAULT_CONFIG" effect configuration of a valid pin ID? It just makes no sense, and for me as a user - it is a bug.

    Furthermore, in the sdk_config.h comments, it seams that pin_number values end in 31. for example: 

    // <o> PWM_DEFAULT_CONFIG_OUT0_PIN - Out0 pin  <0-31> 

    An obvious solution will be changing the value of PWM_DEFAULT_CONFIG_OUT0_PIN to NRF_DRV_PWM_PIN_NOT_USED and so on

Related