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
  • 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]);

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

  • Thanks for your help.

    #define ECG_INTB NRF_GPIO_PIN_MAP(0,19)
    #define I2C_SDA2 NRF_GPIO_PIN_MAP(0,21)

    #define GYRO_SCLK2_I2C_SCL1         20

    #define I2C_SCL2 NRF_GPIO_PIN_MAP(0,23)

    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); 

    The pin GYRO_SCLK2_I2C_SCL1  is connected also with pins I2C_SCL2 but this one is out of service and never worked (perhaps missing soldering) that is way I'm using GYRO_SCLK2_I2C_SCL1 as clock

    for TWIM1.  The GYRO_SCLK2_I2C_SCL1 is shared with SPI2 for  another interface. TWIM1 and SPI2 works well together up to first ECG_INTB lecture as state. I've tried different configuration for not working

    2C_SCL2 without any success. 

  • I'm sorry, I am not able to run it. Can you add your main file/project?

Related