This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

TWI not working on nrf52832 dev board: NRF_DRV_TWI_ERROR

Hi,

I have a pretty hard time to get I2C/TWI running on my 52832 Dev-board (pca 10036). My problem is, that i do not get any physical I2C signal out of the board's pins. I tried nordic's TWI master/slave example from the SDK 0.9.2, shortened the relevant pins, with no success. Then I wrote a minimal TWI test programm. E.g.:

const nrf_drv_twi_t           p_twi_instance = NRF_DRV_TWI_INSTANCE(1);

ret_code = nrf_drv_twi_init(&p_twi_instance, &p_twi_config, twi_event_handler); // Initiate twi driver with instance and configuration values
APP_ERROR_CHECK(ret_code); // Check for errors in return value

nrf_drv_twi_enable(&p_twi_instance); // Enable the TWI instance

// Send dummy data on TWI buss on address 0x68
 ret_code = nrf_drv_twi_tx(&p_twi_instance, address, &dummy_data, 1, false);

and handle the twi event:

// TWI event handler. Processing TWI events originating from
// nrf_drv_twi_tx()

static void twi_event_handler(nrf_drv_twi_evt_t *evt){

   if(evt->type == NRF_DRV_TWI_ERROR)
   {
      /* Error 2 is
      * NRF_TWI_ERROR_ADDRESS_NACK = TWI_ERRORSRC_ANACK_Msk,
      * NACK received after sending the address.
      * as defined in nrf_twi.h
      * So I guess I don't get any response from my external device.
      */
   }

   if(evt->type == NRF_DRV_TWI_TX_DONE)
   {
      SEGGER_RTT_printf(0,"TWI event success ...\r\n");
   }
}

The TWI is initiated without any error and the program runs fine, but in the event handler I always get a NRF_DRV_TWI_ERROR, regardless of the TWI slaves.

Then i attached my Saleae Logic Analyzer into the TWI bus with 10K Ohm pull-up resistors to see, if there are any logic signals. But neither for SCL nor SCA pins was any signal detected.

Then I probed every pin on the 52832 Dev-Board with the logic analyzer, just to make sure I don't have misconfigured pins, but i could not get any signal on any pin.

Next I probed the logic analyzer with a 51822 board, and with this board I can see the SCL and SCA signals, so the logic analyzer is working correctly.

So, is TWI (nrf_drv_twi.c, etc.) working on a 52832 Dev-board?

Any idea, why I don't even get the TWI clock signal on the pin?

Is my board maybe physically damaged?

Any help is greatly appreciated! Yours Johannes

  • Hi monpetit,

    I am using nRF52's SDK 0.9.2. Sorry about making it not clear enough in my previous question. Never thought about to mix nRF51 SDK 10.0.0 with a nRF52 DK board. But if you tested this combination successfully, I will give it a try.

  • Don't use the twi driver to test, write the registers directly. Try both of the TWI masters, either in legacy TWI mode or the new TWIM mode, not that there's a lot of difference. Since TWI isn't mentioned as not working in the errata sheet, it's working, writing something direct to the hardware instances will tell you if you have a hardware issue on your board. But that doesn't really seem likely, if the rest of the chip is working, there's no reason both TWIs should just be failed.

    Just make sure you put the right thing in the ENABLE register - needs to be '5' to enable the TWI and disable the other peripherals at the same address.

    Should take no more than 20 lines of code to pump one byte out of the TWI master which you can capture on the analyser and show TWI is working.

    Once you've proved at least one of them works, you can look at why the code using the driver doesn't.

  • Tested on PCA10036 and PCA10040 with your code and this config:

    const nrf_drv_twi_config_t p_twi_config = {
       .scl                = 11,
       .sda                = 12,
       .frequency          = NRF_TWI_FREQ_400K,
       .interrupt_priority = APP_IRQ_PRIORITY_LOW
    };
    

    And with the logic analyzer connected to SCL, SDA and ground (no pullup) it works. I was using SDK 0.9.2.

    As RK said, check if this is a fault with the chip or with the SDK by writing to the registers.

  • Hi,

    I suspect, that there is an issue with the pca10036 board or chip.

    I2C / TWI is not working, if I use the standard settings from nrf_drv_config.h.

    define TWI1_CONFIG_FREQUENCY    NRF_TWI_FREQ_100K
    #define TWI1_CONFIG_SCL          0
    #define TWI1_CONFIG_SDA          1
    #define TWI1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_HIGH
    

    With the default pins 0 and 1, I never get any signal.

    Therefore I tried various pin combinations:

           SCL  SCA
    pin:   0      1    does not work
           1      21      "
           21     5       "
           3      4       "
           5      6    works
           6      7    works
    

    So, for me the default settings are not usable, and even the working pin combinations I have to find out individually either by a program routine or with a logic analyzer. My toolchain is PCA10036, Keil uVision 5.x, SDK 0.9.2.

    Hopefully, this information helps somebody to save precious time. Thank you all, who commented on my question, which helped to solve the problem. Your Johannes

  • Pin 0 and 1 are used for 32 KHz crystal, so it is no wonder it does not work. I wonder why these are the default and will check this internally. Pin 3 and 4 should work since these are not used for anything. For full pinout of the DK, see here.

Related