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

TIWM and GPIO input

I'm developing an interface I2C to one sensor including SCL, SDA and open-drain return to know if

the sensor is ready to work. After Reset by "Build and Run" form Segger (SDK 16) the TWIM works

very well. But after any read form GPIO input (state of sensor) the TWIM is out service and only new

Download remains TWIM working. I've tried: nrf_gpio_pin_input_get, nrf_gpi_input_read. This Input

was reconfigured as follow:  nrf_gpio_cfg(I2C_SDA2,NRF_GPIO_PIN_DIR_INPUT,NRF_GPIO_PIN_INPUT_CONNECT,
NRF_GPIO_PIN_PULLUP,NRF_GPIO_PIN_S0S1,NRF_GPIO_PIN_NOSENSE); but also nrf_gpio_cfg_input (I2C_SDA2,NRF_GPIO_PIN_PULLUP)

with same bad reaction. Is it  possible that only one GPIO's read is able to block TWIM?????. I've tried : On/off of TWIM, new initialization, On/off of sensor

any way I need always to Re-Download nrf52840 to work with I2C. I'm using nrf52840 development board as Jtag interface to my board. 

Parents Reply Children
  • Is blocked on:  while (NRF_TWIM1->EVENTS_STOPPED == 0); I don't understand what one GPIO input reading can change in TWIM periphery?   

  • Additionally, after reading input the I2C clock becomes Low even strong PoolUp?

  • Can you please provide your code? I'm not able to see what the issue is.

    Thanks!

    Kind regards,
    Øyvind

  • Hi, Thanks for your help.

    I2C pins:

    nrf_gpio_cfg(GYRO_SCLK2_I2C_SCL1,NRF_GPIO_PIN_DIR_OUTPUT,NRF_GPIO_PIN_INPUT_CONNECT,
    NRF_GPIO_PIN_PULLUP,NRF_GPIO_PIN_H0H1,NRF_GPIO_PIN_NOSENSE);

    nrf_gpio_cfg(I2C_SDA2,NRF_GPIO_PIN_DIR_INPUT,NRF_GPIO_PIN_INPUT_CONNECT,
    NRF_GPIO_PIN_PULLUP,NRF_GPIO_PIN_S0S1,NRF_GPIO_PIN_NOSENSE);

    State pin:

     nrf_gpio_cfg_input (ECG_INTB,NRF_GPIO_PIN_PULLUP); 

    I2C initiation:

    //Pin definition
    NRF_TWIM1->PSEL.SCL = GYRO_SCLK2_I2C_SCL1;
    NRF_TWIM1->PSEL.SDA = I2C_SDA2;
    // TWIM initialisation
    NRF_TWIM1->ADDRESS = 94;
    NRF_TWIM1->FREQUENCY = TWIM_FREQUENCY_FREQUENCY_K100 << TWIM_FREQUENCY_FREQUENCY_Pos;
    NRF_TWIM1->SHORTS = 0;
    //TWIN enable
    NRF_TWIM1->ENABLE =TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos; // enable

    State pin lecture:

    ret = nrf_gpio_pin_input_get (ECG_INTB); //read IntB

    I2C data:

    static uint8_t LastAddressRead;
    static uint8_t tx_buf[2]; /**< TX buffer. */
    static uint8_t tx_for_rx_buf[1]; /**< TX buffer. */
    static uint8_t rx_buf[1]; /**< RX buffer. */

    I2C read:

    rx_buf[0] = 0; 

    NRF_TWIM1->SHORTS = TWIM_SHORTS_LASTTX_STARTRX_Msk | TWIM_SHORTS_LASTRX_STOP_Msk;

    tx_for_rx_buf[0] = LastAddressRead;
    NRF_TWIM1->TXD.MAXCNT = 1;
    NRF_TWIM1->TXD.PTR = (uint32_t)&tx_for_rx_buf[0];

    NRF_TWIM1->RXD.MAXCNT = 1;
    NRF_TWIM1->RXD.PTR = (uint32_t)&rx_buf[0];

    NRF_TWIM1->EVENTS_STOPPED = 0;
    NRF_TWIM1->EVENTS_LASTTX = 0;

    NRF_TWIM1->TASKS_STARTTX = 1;

     while (NRF_TWIM1->EVENTS_STOPPED == 0);

    nrf_delay_us(50);

    return (rx_buf[0]);

  • Please add all defines as well, as e.g. I2C_SDA2, etc are not in nRF SDK.

Related