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

nrf52 dk board TWI SCANNING EXAMPLE INTERFACING WITH EXTERNAL EEPROM

nrf52 dk board TWI SCANNING EXAMPLE INTERFACING WITH EXTERNAL EEPROM 

Hi, this is vadivelan

I am working on a task like interfacing external EEPROM memory with nrf52dk board I used TWI scanner example for that then I interfaced with external EEPROM but it's showing on terminal "no devices was found " my EEPROM ic address for reading 0x51 ..

{

err_code = nrf_drv_twi_rx(&m_twi, address, &sample_data, sizeof(sample_data));
printf("error_code =%d",err_code);

}

I checked err_code value is=33281 receiving 

how to solve this issue help me/...

  • Hello Vedivelan,

    I used TWI scanner example for that then I interfaced with external EEPROM but it's showing on terminal "no devices was found "

    This makes me suspect that there is an issue with your connection between the nRF and the EEPROM. Could you show some schematics of how you have wired the two together?

    I checked err_code value is=33281 receiving 

    Could you show me the entire code snippet for the function or section of code leading up to this value?

    Please also make sure that you have DEBUG defined in your preprocessor defines, like shown in the included image:

    This will make the logger print a detailed error message whenever a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK.

    Please add DEBUG to your preprocessor defines, and let me know what the error message in your log says when this error is encountered.

    Best regards,
    Karl

  • hi Karl Ylvisakar thanks for the reply

    there is an issue in connection before I connected directly 5v EEPROM ic but when i changed 5v to 3.3v after that particular device address found 

    but now i send data='1' to EEPROM address 0x50 there is no issue on that but try to receive data with rx() function getting value in buffe data is in int value=255 

    what i am making mistake help me 


    /* TWI instance ID. */
    #if TWI0_ENABLED
    #define TWI_INSTANCE_ID 0
    #elif TWI1_ENABLED
    #define TWI_INSTANCE_ID 1
    #endif

    /* Number of possible TWI addresses. */
    #define TWI_ADDRESSES 127

    /* TWI instance. */
    static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);


    /**
    * @brief TWI initialization.
    */
    void twi_init (void)
    {
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_config = {
    .scl = ARDUINO_SCL_PIN,
    // .scl_pull = NRF_GPIO_PIN_PULLUP,
    .sda = ARDUINO_SDA_PIN,
    //.sda_pull = NRF_GPIO_PIN_PULLUP
    .frequency = NRF_DRV_TWI_FREQ_400K,
    .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);


    }

    /**
    * @brief Function for main application entry.
    */
    int main(void)
    {
    ret_code_t err_code;
    uint8_t address;
    uint8_t sample_data;
    uint8_t sample_dat ='1';
    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();
    bsp_board_init(BSP_INIT_LEDS);
    bsp_board_init(BSP_INIT_BUTTONS);



    // nrf_delay_ms(50);

    err_code= nrf_drv_twi_tx(&m_twi,0x50,&sample_dat,sizeof(sample_dat),0);
    printf("error_code=%d",err_code);
    if (err_code == NRF_SUCCESS)
    {
    detected_device = true;
    NRF_LOG_INFO("0");
    }

    if (err_code == NRF_ERROR_INVALID_ADDR)
    {
    detected_device = true;
    NRF_LOG_INFO("1");
    }
    if (err_code ==NRF_ERROR_INTERNAL)
    {
    detected_device = true;
    NRF_LOG_INFO("2");
    }
    if (err_code == NRF_ERROR_DRV_TWI_ERR_OVERRUN )
    {
    detected_device = true;
    NRF_LOG_INFO("3");
    }
    if (err_code ==NRF_ERROR_DRV_TWI_ERR_ANACK )
    {
    detected_device = true;
    NRF_LOG_INFO(" 4");
    }



    • for (address = 0; address <= TWI_ADDRESSES; address++)
      {
      nrf_delay_ms(50);
      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);

      printf(" sample data=%c\n\r", sample_data); //255
      printf("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(1)
      {
      for (int i = 0; i < LEDS_NUMBER; i++)
      {
      bsp_board_led_invert(i);
      nrf_delay_ms(500);

      }



      }
      }
      /** @} */
  • 0_velan_1 said:
    thanks for the reply

    No problem at all, I am happy to help!

    0_velan_1 said:
    there is an issue in connection before I connected directly 5v EEPROM ic but when i changed 5v to 3.3v after that particular device address found 

    I am glad to hear that you are now able to find the address of the device! I must advice you to always check the proper VDD level of an IC before connecting power to it - many IC's, including the nRF52 family - may be damaged and/or fried if you connect 5 V directly to its VDD bus. The damage may not always be obvious, and so it could cost you many hours of debugging to detect and identify the issue down the road, which can be very frustrating. Please make sure to always check this in the future.

    I am not sure that I understand your intentions with the if-statements containing logging happening after the call to nrf_drv_twi_tx - are you here implementing your own error checking?
    If so, I would advice you to make sure DEBUG is enabled - like I mentioned in my previous comment - and instead just pass the error code to an APP_ERROR_CHECK.

    0_velan_1 said:
    but now i send data='1' to EEPROM address 0x50 there is no issue on that but try to receive data with rx() function getting value in buffe data is in int value=255 

    What value were you expecting to read from this particular memory location?
    Do you have access to a logical analyzer?
    It would help a lot to be able to see what is happening on the lines here.

    Could you also clarify exactly where the error code was read out to be 33281?

    For future reference, please always use the Insert -> Code option when sharing code here on DevZone, this drastically increases the readability.

    Best regards,
    Karl

  • What value were you expecting to read from this particular memory location?

    What value were you expecting to read from this particular memory location?

    i passed data to sample_dat='1'

    err_code= nrf_drv_twi_tx(&m_twi,0x50,&sample_dat,sizeof(sample_dat),0);

    for that  here 

    err_code = nrf_drv_twi_rx(&m_twi, 0x51, &sample_data, sizeof(sample_data));

    in the sample_data buffer variable, i want data '1' from EEPROM memory but got 255 in decimal value 

    I have doubt that I'm doing correct or not...

    Do you have access to a logical analyzer?

    no

    Could you also clarify exactly where the error code was read out to be 33281?

    that issue resolved but I got from here

    err_code = nrf_drv_twi_rx(&m_twi,address, &sample_data, sizeof(sample_data));

    in this function return value that time i got 33281

    here there is loop is address 1 to 127 address scanning on that for example address 1  scanning for that particular address no device found means this value=33281 that function returning ..

     

  • 0_velan_1 said:

    i passed data to sample_dat='1'

    err_code= nrf_drv_twi_tx(&m_twi,0x50,&sample_dat,sizeof(sample_dat),0);

    for that  here 

    err_code = nrf_drv_twi_rx(&m_twi, 0x51, &sample_data, sizeof(sample_data));

    in the sample_data buffer variable, i want data '1' from EEPROM memory but got 255 in decimal value 

    I have doubt that I'm doing correct or not...

    It might be beneficial for you to have a look at the TWI master mode example, it demonstrates how to interface a simulated EEPROM module. You there see how you could go about implementing EEPROM interface. It might be easier for you to start out from this example, since the scanner is able to find the device on the bus successfully. Exactly which EEPROM module are you working with by the way, and how long times does it require in between transfers?

    0_velan_1 said:
    Do you have access to a logical analyzer?

    no

    That is unfortunate - developing and debugging serial interfaces are tenfold easier with a logical analyzer, for future reference. Can you show me what you logs says when you run your program?

    0_velan_1 said:

    that issue resolved but I got from here

    err_code = nrf_drv_twi_rx(&m_twi,address, &sample_data, sizeof(sample_data));

    in this function return value that time i got 33281

    This does not correspond to any of the error codes this function can return. I am not sure I understand the structure of the code you have pasted earlier, there was some issues with the formatting in your previous comment. Is the last code block following immediately after the logging if's, or does it come in somewhere else? There is a random bullet point present, and some odd indentation.
    Please use the Insert -> Code option when sharing code, and make sure that the code is properly readable before submitting - this makes it easier for others to read, debug, and help you.

    Karl Ylvisaker said:
    I am not sure that I understand your intentions with the if-statements containing logging happening after the call to nrf_drv_twi_tx - are you here implementing your own error checking?

    Please answer this question. I would recommend that you instead make use of the APP_ERROR_CHECK, for future reference. Please do this, and add APP_ERROR_CHECKs to all returned error codes from SDK functions.

    Looking forward to resolving this issue together!

    Best regards,
    Karl

Related