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

TWI scan no device found

Hello, I've been trying to setup TWI with 3 sensors and so far I had no luck (custom board). Here's the situation:

1) 3 sensors are connected to nrf52820, SCL to P0.15, SDA to P0.14

2) External pull up resistors, 10k

3) Sensors are powered up using P0.08

On startup, I'm setting P0.08 to high, which powers up the sensors. After that I initialize and start TWI using the following code (mostly from TWI scan example):

#define SDA_PIN NRF_GPIO_PIN_MAP(0, 14)
#define SCL_PIN NRF_GPIO_PIN_MAP(0, 15)

void twi_init(void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_config = {
        .scl = SCL_PIN,
        .sda = SDA_PIN,
        .frequency = NRF_DRV_TWI_FREQ_100K,
        .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
        .clear_bus_init = false};

    err_code = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);

    APP_ERROR_CHECK(err_code);

    nrf_drv_twi_enable(&m_twi);
}

Next, with a delay, I start scanning for I2C devices, using the code below (mostly from TWI scan example):

void scan(void)
{
    ret_code_t err_code;
    uint8_t address;
    uint8_t sample_data;
    bool detected_device = false;

    for (address = 1; address <= TWI_ADDRESSES; address++)
    {
        err_code = nrf_drv_twi_rx(&m_twi, address, &sample_data, sizeof(sample_data));
        if (err_code == NRF_SUCCESS)
        {
            detected_device = true;
        }
    }


    set_scan_characteristic_value(detected_device);
}

But no i2c devices are detected. `nrf_drv_twi_rx` always returns `NRF_ERROR_INTERNAL`. Checking SCL and SDA after TWI init, SCL is high, and SDA is low. Unfortunately I don't have an oscilloscope to check the SCL. Can you please guide me to the right direction? 

I'm using NRF5 SDK 17.0.2

Parents Reply Children
No Data
Related