Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

RTC TWI Driver SDK 17

Hello,

I'm working on a driver for the PCF85063A RTC in SDK 17 with the nRF52DK. I am able to successfully set registers, however I'm getting strange behavior with reads.

void read_RTC(void)
{
    uint8_t clock_data[7];
    uint8_t reg_address = 0x04;
    ret_code_t err_code = 0;

    err_code = nrf_drv_twi_tx(&m_twi, RTC_ADDRESS, &reg_address, 1, true);
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("TWI TX failed. Error code: %d", err_code);
        return;
    }
    nrf_delay_ms(10);

    err_code = nrf_drv_twi_rx(&m_twi, RTC_ADDRESS, clock_data, sizeof(clock_data));
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("TWI RX failed. Error code: %d", err_code);
        return;
    }

    for(int i = 0; i < sizeof(clock_data); i++)
    {
        NRF_LOG_INFO("Data[%d]: 0x%02X", i, clock_data[i]);
    }
}

I want to first write to the clock to set the address pointer to 0x04 using nrf_drv_twi_tx with the no_stop flag set to true. I then want to read 7 bytes for all the relevant time data using nrf_drv_twi_rx, This works correctly, but when I try to read other registers by changing the reg_address from 0x04 to 0x00 for example to read the first registers I get the same clock data back reading 7 bytes from register 0x04 - 0x0A, so it seems the address pointer is not being set correctly by the tx. 

Another strange behavior I noticed is that the data I get shifts if I send buffers of different sizes. For instance a buffer of size 7 always returns the information in registers 0x04 - 0x0A, but if I change the size of the buffer to 10 I get the information from registers 0x00 - 0x09. 

It seems there is an issue with how the address pointer is updating, but I'm not sure what is going on.

Thanks!

Parents
  • Hello,


    Are you using the TWIM driver in blocking or non-blocking mode (ref. TWIM driver)? If non-blocking, you should check the data that is received in the registered TWIM callback. It's also important that the provided TWIM buffers remain in static memory until the transaction is complete and not on the stack. You can ensure this by prefixing the variable declarations with the keyword 'static'.

    Best regards,

    Vidar

Reply
  • Hello,


    Are you using the TWIM driver in blocking or non-blocking mode (ref. TWIM driver)? If non-blocking, you should check the data that is received in the registered TWIM callback. It's also important that the provided TWIM buffers remain in static memory until the transaction is complete and not on the stack. You can ensure this by prefixing the variable declarations with the keyword 'static'.

    Best regards,

    Vidar

Children
No Data
Related