<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Accessing DS1307 RTC Addresses with  nrf52 DK Through TWI and nrf_drv_twi_rx Function</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75672/accessing-ds1307-rtc-addresses-with-nrf52-dk-through-twi-and-nrf_drv_twi_rx-function</link><description>I&amp;#39;m trying to read the values from the DS1307 RTC through TWI. I&amp;#39;ve established a connection with the device but am not sure I&amp;#39;m using the nrf_drv_twi_rx() function correctly. When the log is viewed it prints that there was a device successfully detected</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 27 May 2021 02:07:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75672/accessing-ds1307-rtc-addresses-with-nrf52-dk-through-twi-and-nrf_drv_twi_rx-function" /><item><title>RE: Accessing DS1307 RTC Addresses with  nrf52 DK Through TWI and nrf_drv_twi_rx Function</title><link>https://devzone.nordicsemi.com/thread/311931?ContentTypeID=1</link><pubDate>Thu, 27 May 2021 02:07:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55b21281-23b8-4562-90f9-c0b37497724b</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Good news indeed! And thanks for posting the working code, this really helps other users in the future and makes engineers like me more likely to keep helping out :-)&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the location:&lt;/p&gt;
&lt;p&gt;DS1307 64 x 8, Serial, I2C Real Time Clock (Hidden on page 13)&lt;br /&gt;Figure 6. Data Read (Write Pointer, Then Read) Slave Receive and Transmit&lt;/p&gt;
&lt;p&gt;&lt;a href="https://datasheets.maximintegrated.com/en/ds/DS1307.pdf"&gt;DS1307.pdf&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accessing DS1307 RTC Addresses with  nrf52 DK Through TWI and nrf_drv_twi_rx Function</title><link>https://devzone.nordicsemi.com/thread/311930?ContentTypeID=1</link><pubDate>Thu, 27 May 2021 02:00:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14bb57d3-db6f-4fec-aad7-02ac85e0cdcd</guid><dc:creator>jake11212</dc:creator><description>&lt;p&gt;This worked perfectly, thank you so much!&amp;nbsp; Could you link to where you found the information about transmitting the read address?&amp;nbsp; I couldn&amp;#39;t find where this info was but I&amp;#39;d like to read a bit more about how the TWI functions work.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Also here is my final code for anyone in the future that wants to see how I fixed this issue, sorry it&amp;#39;s a bit messy.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;



#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;


/* TWI instance ID. */

#define TWI_INSTANCE_ID 0

static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);

void twi_init(void) //configure twi connection
{
  ret_code_t err_code; 

  const nrf_drv_twi_config_t twi_config = {
    .scl = 22, //configure pin 22 to scl
    .sda = 23, //configure pin 23 to sda
    .frequency = NRF_DRV_TWI_FREQ_100K, //nrf freq 100k 250k or 400k
    .interrupt_priority = APP_IRQ_PRIORITY_HIGH, //if using a soft device this has to be changed accordingly
    .clear_bus_init = false 

    };

    err_code = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_config, NULL, NULL); //can pass this an interrupt handler
    APP_ERROR_CHECK(err_code);

    nrf_drv_twi_enable(&amp;amp;m_twi);

}


int main(void)
{

    ret_code_t err_code;
    uint8_t address = 0x68; //address of DS1307
    uint8_t rx_data[7]  = {0}; //buffer for rx twi info. array of 7 uint8_t to hold 7 bytes received over twi
    uint8_t startAddress = 0x00;

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO(&amp;quot;Application Started&amp;quot;);

    NRF_LOG_FLUSH();

    twi_init();


    //Line 61 through 66 is what I changed from the original code
    
    err_code = nrf_drv_twi_tx(&amp;amp;m_twi, address, &amp;amp;startAddress, 1, true); //transmit to designate the start address

    if (NRF_SUCCESS == err_code) //if the starting address was successfully transmitted receive the 7 bytes for the clock time
    {
        err_code = nrf_drv_twi_rx(&amp;amp;m_twi, address, &amp;amp;rx_data, sizeof(rx_data));
    }


    if(err_code == NRF_SUCCESS) //if the rx was successful log the info
    {
      NRF_LOG_INFO(&amp;quot;Successfully detected a device at address: 0x%x&amp;quot;, address);

      for(int i = 0; i &amp;lt; 7; ++i) //display the data obtained from the rx
      {
        NRF_LOG_INFO(&amp;quot;Data %d obtained from registry: %x&amp;quot;, (i+1), rx_data[i]);
      }

    }
    
    else
    {

    NRF_LOG_INFO(&amp;quot;No device detected at address 0x%x&amp;quot;, address);

    }


    NRF_LOG_FLUSH();






    while (true)
    {
        /* Empty loop. */
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accessing DS1307 RTC Addresses with  nrf52 DK Through TWI and nrf_drv_twi_rx Function</title><link>https://devzone.nordicsemi.com/thread/311926?ContentTypeID=1</link><pubDate>Thu, 27 May 2021 01:42:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:536aed6f-b184-4577-ab3a-98ee2a66f38d</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;&amp;quot;&lt;em&gt;The DS1307 then begins to transmit data starting with the register address pointed to by the register pointer. If the register pointer is not written to before the initiation of a read mode the first address that is read is the last one stored in the register pointer. The register pointer automatically increments after each byte are read&lt;/em&gt;.&amp;quot;&lt;/p&gt;
&lt;p&gt;Expected operation is to transmit the required address to read - 0x00 in this case if wanting to read the time - before each read of the time. That requires a single byte write&amp;nbsp;&lt;em&gt;nrf_drv_twi_tx()&lt;/em&gt; before each&amp;nbsp;&lt;em&gt;nrf_drv_twi_rx()&lt;/em&gt;&amp;nbsp;or better a combined write of 0x00 followed by a read in the same twi/i2c function; this is possible with the i2c driver but I don&amp;#39;t use that so can&amp;#39;t advise.&lt;/p&gt;
&lt;p&gt;Using wrap-around is not reliable; in any case 56 bytes RAM plus 8 bytes time = 64 bytes, so using an array of 63 bytes explains why the data moves 1 bytes each read of 63 bytes. 64 bytes would work but is not recommended ..&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accessing DS1307 RTC Addresses with  nrf52 DK Through TWI and nrf_drv_twi_rx Function</title><link>https://devzone.nordicsemi.com/thread/311924?ContentTypeID=1</link><pubDate>Thu, 27 May 2021 01:10:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e3cb63bc-71fa-48fa-b083-08c8844ccb38</guid><dc:creator>jake11212</dc:creator><description>&lt;p&gt;Through some further troubleshooting I changed the rx_data array to hold 63 uint8_t and to get 63 bytes from the&amp;nbsp;nrf_drv_twi_rx() function.&amp;nbsp; The correct date and time info (7 bytes holding info about sec, min, hour, month, etc) is all contiguous, but each time the program runs the group of correct information moves down one space in the rx_data array (ie: if sec, min, hour are in spaces 0, 1, and 2 the first build/run, the second build/run they are now in spaces 1,2,3 respectively).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The datasheet says that: &amp;quot;During a multi-byte access, when the address pointer reaches 3Fh, the end of RAM space, it wraps around to location 00h, the beginning of the clock space.&amp;quot;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Based on this, it seems that the address pointer is not correctly resetting to the beginning of the clock space each run which is causing the offset.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t find information in the development library about how the nrf_drv_twi_rx() function knows what to use for the address pointer to read data from the slave device, or how this pointer is controlled.&amp;nbsp;&amp;nbsp;Could someone explain how to alter the address pointer being used by the nrf_drv_twi_rx() function?&amp;nbsp; Or let me know if you think there is some other problem.&amp;nbsp; Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>