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

TWI Scanner Example No device was found 16-bit sensor

I'm trying the given example <twi_sensor>.  I connect nRF52 DK P0.26 to my sensor's SDA, nRF52 DK P0.27 connects to my sensor's SCL. My sensor runs at 400kHz, so I modified frequency as NRF_DRV_TWI_FREQ_400K, 16-bit. My PuTTY shows that: 

TWI scanner started.

No device was found.

Sensor I2C sequence is given below. I suspect the reason for having no detection is because of the sensor data is 16-bit? Thanks

Parents
  • Here is my code, I guess it's the 16 bit data issue. Plz help if you know how to modify the code. Thanks 

    int main(void)
    {
        ret_code_t err_code;
        uint8_t address;
        uint8_t sample_data[1]; // 16 bit data, so use "[1]" here
        bool detected_device = false;
    
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        NRF_LOG_INFO("TWI scanner started.");
        NRF_LOG_FLUSH();
        twi_init();
    
        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;
                NRF_LOG_INFO("TWI device detected at address 0x%x.", address);
            }
            NRF_LOG_FLUSH();
        }
    
        if (!detected_device)
        {
            NRF_LOG_INFO("No device was found.");
            NRF_LOG_FLUSH();
        }
    
        while (true)
        {
            /* Empty loop. */
        }
    }
    

Reply
  • Here is my code, I guess it's the 16 bit data issue. Plz help if you know how to modify the code. Thanks 

    int main(void)
    {
        ret_code_t err_code;
        uint8_t address;
        uint8_t sample_data[1]; // 16 bit data, so use "[1]" here
        bool detected_device = false;
    
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        NRF_LOG_INFO("TWI scanner started.");
        NRF_LOG_FLUSH();
        twi_init();
    
        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;
                NRF_LOG_INFO("TWI device detected at address 0x%x.", address);
            }
            NRF_LOG_FLUSH();
        }
    
        if (!detected_device)
        {
            NRF_LOG_INFO("No device was found.");
            NRF_LOG_FLUSH();
        }
    
        while (true)
        {
            /* Empty loop. */
        }
    }
    

Children
No Data
Related