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

I2C fails to work when P0_15, P0_16 is configured

On a custom pcb, an I2C sensor is connected on P0_15 and P0_16 ( SDA & SCL ).

When sensor reading is requested, the code is designed to wait till the reading is returned from the sensor. The code gets stuck waiting at this.

When browsing through the nRF52832 pin assignments, observed that the TRACEDATA pins are shared with P0_15, P0_16 ( https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpin.html ).

Any suggestions on how to make sure that the pins are being used as I2C and not as TRACEDATA pins?

Parents
  • This is in system_nrf52.c:

        /* Enable Trace functionality. If ENABLE_TRACE is not defined, TRACE pins will be used as GPIOs (see Product
           Specification to see which ones). */
        #if defined (ENABLE_TRACE)
            CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
            NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Parallel << CLOCK_TRACECONFIG_TRACEMUX_Pos;
            NRF_P0->PIN_CNF[14] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
            NRF_P0->PIN_CNF[15] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
            NRF_P0->PIN_CNF[16] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
            NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
            NRF_P0->PIN_CNF[20] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        #endif

    ENABLE_TRACE may be defined in a project file or sdk_config.h. Worth checking CoreDebug->DEMCR and NRF_CLOCK->TRACECONFIG to see what they are currently set at.

    // TRACE pins can be used as GPIOs or Trace, special case
    if ( (CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) == CoreDebug_DEMCR_TRCENA_Msk )
    {
        if (PinId == TRACE_D0_PIN)  return "TRACE D0";  // 18
        if (PinId == TRACE_D1_PIN)  return "TRACE D1";  // 16
        if (PinId == TRACE_D2_PIN)  return "TRACE D2";  // 15
        if (PinId == TRACE_D3_PIN)  return "TRACE D3";  // 14
        if (PinId == TRACE_CLK_PIN) return "TRACE CLK"; // 20
    }

Reply
  • This is in system_nrf52.c:

        /* Enable Trace functionality. If ENABLE_TRACE is not defined, TRACE pins will be used as GPIOs (see Product
           Specification to see which ones). */
        #if defined (ENABLE_TRACE)
            CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
            NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Parallel << CLOCK_TRACECONFIG_TRACEMUX_Pos;
            NRF_P0->PIN_CNF[14] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
            NRF_P0->PIN_CNF[15] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
            NRF_P0->PIN_CNF[16] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
            NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
            NRF_P0->PIN_CNF[20] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        #endif

    ENABLE_TRACE may be defined in a project file or sdk_config.h. Worth checking CoreDebug->DEMCR and NRF_CLOCK->TRACECONFIG to see what they are currently set at.

    // TRACE pins can be used as GPIOs or Trace, special case
    if ( (CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) == CoreDebug_DEMCR_TRCENA_Msk )
    {
        if (PinId == TRACE_D0_PIN)  return "TRACE D0";  // 18
        if (PinId == TRACE_D1_PIN)  return "TRACE D1";  // 16
        if (PinId == TRACE_D2_PIN)  return "TRACE D2";  // 15
        if (PinId == TRACE_D3_PIN)  return "TRACE D3";  // 14
        if (PinId == TRACE_CLK_PIN) return "TRACE CLK"; // 20
    }

Children
No Data
Related