NRF52840 I2C ADDRESS.

Hello Everyone,

                           I am working on NRF52840 development kit. I am trying to run I2c master. My main goal is to send some data to slave via I2C lines. I am using the example code "TWI scanner" from the sdk examples. I have attached the slave microcontroller (ATSAMD20) and I am running i2c slave code on it. The Slave address is 0x54. I have set it as 0x54 in the slave code. Now when I try to scan the devices from NRF52840, the device is found at 0x28 address. Why is it so?? 

Parents
  • Thanks for your reply Kenneth. Something weird is happening at my side. I agree with your left bit shifting. I tried to test the code again. Now NRF52840 is scanning 2 addresses. 

    my code is as follows:-

    int main(void){

    ret_code_t err_code;
    uint8_t address = (0x54U); 
    uint8_t data;
    bool detected_device = false;
    bool result = false;

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO("TWI scanner started.");
    NRF_LOG_FLUSH();
    twi_init();
    nrf_delay_ms(1000); // give some delay

    for (address = 1; address <= TWI_ADDRESSES; address++)
    {
    err_code = nrf_drv_twi_rx(&m_twi, address, &data, sizeof(data));
    if (err_code == NRF_SUCCESS)
    {
    detected_device = true;
    NRF_LOG_INFO("TWI device detected at address 0x%x...0x%x", address,data);
    NRF_LOG_FLUSH();
    send_data();
    }
    NRF_LOG_FLUSH();
    }


    void send_data(void)
    {
    ret_code_t err_code;
    uint8_t address = (0x54U);
    uint8_t sample_data=0xaa;
    uint8_t sample_data1;


    err_code = nrf_drv_twi_tx(&m_twi, address, &sample_data, sizeof(sample_data), true);
    //Wait for the transmission to get completed
    //while (m_xfer_done == false){}
    nrf_delay_ms(1000); // give some delay


    // If transmission was not successful, exit the function with false as return value
    if (NRF_SUCCESS != err_code)
    {
    NRF_LOG_INFO("FAILED 1.");
    NRF_LOG_FLUSH();
    }
    else
    {
    NRF_LOG_INFO("SUCCESS 1.");
    NRF_LOG_FLUSH();
    }

    }

    This is my log on nrf module :- 

    <info> app: TWI scanner started.
    <info> app: TWI device detected at address 0x28...0x0
    <info> app: SUCCESS 1.
    <info> app: TWI device detected at address 0x54...0xAA
    <info> app: SUCCESS 1.

    0XAA is the data which I had sent to the slave. Now why is it scanning 2 addresses when I have attached only one slave with address 0x54?? 

Reply
  • Thanks for your reply Kenneth. Something weird is happening at my side. I agree with your left bit shifting. I tried to test the code again. Now NRF52840 is scanning 2 addresses. 

    my code is as follows:-

    int main(void){

    ret_code_t err_code;
    uint8_t address = (0x54U); 
    uint8_t data;
    bool detected_device = false;
    bool result = false;

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO("TWI scanner started.");
    NRF_LOG_FLUSH();
    twi_init();
    nrf_delay_ms(1000); // give some delay

    for (address = 1; address <= TWI_ADDRESSES; address++)
    {
    err_code = nrf_drv_twi_rx(&m_twi, address, &data, sizeof(data));
    if (err_code == NRF_SUCCESS)
    {
    detected_device = true;
    NRF_LOG_INFO("TWI device detected at address 0x%x...0x%x", address,data);
    NRF_LOG_FLUSH();
    send_data();
    }
    NRF_LOG_FLUSH();
    }


    void send_data(void)
    {
    ret_code_t err_code;
    uint8_t address = (0x54U);
    uint8_t sample_data=0xaa;
    uint8_t sample_data1;


    err_code = nrf_drv_twi_tx(&m_twi, address, &sample_data, sizeof(sample_data), true);
    //Wait for the transmission to get completed
    //while (m_xfer_done == false){}
    nrf_delay_ms(1000); // give some delay


    // If transmission was not successful, exit the function with false as return value
    if (NRF_SUCCESS != err_code)
    {
    NRF_LOG_INFO("FAILED 1.");
    NRF_LOG_FLUSH();
    }
    else
    {
    NRF_LOG_INFO("SUCCESS 1.");
    NRF_LOG_FLUSH();
    }

    }

    This is my log on nrf module :- 

    <info> app: TWI scanner started.
    <info> app: TWI device detected at address 0x28...0x0
    <info> app: SUCCESS 1.
    <info> app: TWI device detected at address 0x54...0xAA
    <info> app: SUCCESS 1.

    0XAA is the data which I had sent to the slave. Now why is it scanning 2 addresses when I have attached only one slave with address 0x54?? 

Children
Related