<?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>TWI speed not correct</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60516/twi-speed-not-correct</link><description>Hello DevZone, 
 
 I was tinkering around with the speed of the TWIM0 module in the nRF52832. 
 I have a cheap USB logic analyzer to help me display the waveforms and I made a discovery. 
 
 Testing the TWIM0 with 100kbps results this: 
 
 Perfect 100kHz</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 06 Sep 2022 22:08:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60516/twi-speed-not-correct" /><item><title>RE: TWI speed not correct</title><link>https://devzone.nordicsemi.com/thread/384874?ContentTypeID=1</link><pubDate>Tue, 06 Sep 2022 22:08:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f70bc6c9-1bff-4f54-920b-f61589fcfcbd</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Excellent thinking, most helpful and may explain issues we have also seen; I used a different divisor matching that of the uart, but this seems like a better underlying cause. The discussion I had with&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/olfox"&gt;olfox&lt;/a&gt; s here under&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/85953/gpio-to-1-7v-after-enabling-twi"&gt;twi&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI speed not correct</title><link>https://devzone.nordicsemi.com/thread/384872?ContentTypeID=1</link><pubDate>Tue, 06 Sep 2022 21:46:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e30d8eef-53fe-4e67-a7b2-3476b1efc0aa</guid><dc:creator>dbouchie</dc:creator><description>&lt;p&gt;I&amp;#39;ve had a similar issue. I think I found the source of the issue: the chip&amp;#39;s TWIM clock stretching. I&amp;#39;m unfamilar of how the internal chip circuitry works, but I noticed when I added a longer wire to my circuit, all of a sudden the clock rate went from 250kHZ to 125kHz (with the master frequency set to 250kHz). Just by adding a wire! The additional capacitance must have some effect on the clock stretching circuit. &lt;br /&gt;&lt;br /&gt;Just speculating, but the theory would be the slow rise times fool the TWIM into thinking a peripheral is clock stretching, so the TWI skips a clock cycle until the clock line rises back again.&lt;br /&gt;&lt;br /&gt;For workarounds, try using a larger pull-up resistor.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI speed not correct</title><link>https://devzone.nordicsemi.com/thread/247299?ContentTypeID=1</link><pubDate>Wed, 29 Apr 2020 10:59:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84c51f81-3145-484b-91d8-1c5b7182de45</guid><dc:creator>T IJ</dc:creator><description>&lt;p&gt;Sorry for the late response, had some hospital stuff to do.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve tried the TWI scanner and it resulted in the same speed. 200kbps with 400kbps settings.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using SDK 15.0, I&amp;nbsp; dont know if this makes the difference.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI speed not correct</title><link>https://devzone.nordicsemi.com/thread/247002?ContentTypeID=1</link><pubDate>Tue, 28 Apr 2020 08:47:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c096e91-59cc-42e4-8bb0-d4d39063a0a4</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Can you try the SDK example as suggested?&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI speed not correct</title><link>https://devzone.nordicsemi.com/thread/246975?ContentTypeID=1</link><pubDate>Tue, 28 Apr 2020 07:01:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f86f523e-2bf5-4d48-8041-729d39548f03</guid><dc:creator>T IJ</dc:creator><description>&lt;p&gt;This is my code how I use the TWI&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    const nrf_twi_config_t twi_config = {.scl = 25,
        .sda = 24,
        .frequency = 0x0c880000, //TWI_FREQUENCY_FREQUENCY_K400,
        .interrupt_priority = 2};

    twi_setup(NRF_TWIM0, &amp;amp;twi_config);


void twi_setup(NRF_TWIM_Type * p_twim, nrf_twi_config_t const * p_config)
{
    NRFX_ASSERT(p_twim);
    NRFX_ASSERT(p_config);
    NRFX_ASSERT(p_config-&amp;gt;scl != p_config-&amp;gt;sda);
    nrf_twim_disable(p_twim);

    NRF_P0-&amp;gt;PIN_CNF[p_config-&amp;gt;scl] =
        (GPIO_PIN_CNF_DRIVE_S0D1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos) &amp;amp; GPIO_PIN_CNF_DRIVE_Msk |
        GPIO_PIN_CNF_PULL_Pullup &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos;
    NRF_P0-&amp;gt;PIN_CNF[p_config-&amp;gt;sda] =
        (GPIO_PIN_CNF_DRIVE_S0D1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos) &amp;amp; GPIO_PIN_CNF_DRIVE_Msk |
        GPIO_PIN_CNF_PULL_Pullup &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos;
    NRF_P0-&amp;gt;DIRCLR = (1 &amp;lt;&amp;lt; p_config-&amp;gt;scl) | (1 &amp;lt;&amp;lt; p_config-&amp;gt;sda);

    nrf_twim_pins_set(p_twim, p_config-&amp;gt;scl, p_config-&amp;gt;sda);

    nrf_twim_frequency_set(p_twim, p_config-&amp;gt;frequency);

    nrf_twim_int_enable(p_twim, NRF_TWIM_INT_STOPPED_MASK | NRF_TWIM_INT_ERROR_MASK);

    NVIC_SetPriority(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn, p_config-&amp;gt;interrupt_priority);
    NVIC_EnableIRQ(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn);

    nrf_twim_enable(p_twim);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And still I only get 200kbps if I use the TWI_FREQUENCY_FREQUENCY_K400 macro.&lt;/p&gt;
&lt;p&gt;I dont know if I done something odd in my code or not.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI speed not correct</title><link>https://devzone.nordicsemi.com/thread/246858?ContentTypeID=1</link><pubDate>Mon, 27 Apr 2020 13:08:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c642f7df-e2db-437d-890e-1f44d4a4c9fc</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I compiled the twi scanner example:&lt;br /&gt;\nRF5_SDK_15.3.0_59ac345\examples\peripheral\twi_scanner&lt;/p&gt;
&lt;p&gt;Then modified twi_init():&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void twi_init (void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_config = {
       .scl                = ARDUINO_SCL_PIN,
       .sda                = ARDUINO_SDA_PIN,
       .frequency          = NRF_DRV_TWI_FREQ_400K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

    err_code = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_config, NULL, NULL);
    APP_ERROR_CHECK(err_code);

    nrf_gpio_cfg_input(ARDUINO_SCL_PIN, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(ARDUINO_SDA_PIN, NRF_GPIO_PIN_PULLUP);

    nrf_drv_twi_enable(&amp;amp;m_twi);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-4156003637414bc9829031924595710e/pastedimage1587992809545v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI speed not correct</title><link>https://devzone.nordicsemi.com/thread/246223?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2020 11:08:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6109c843-412b-4ab1-983d-fc43544bd102</guid><dc:creator>T IJ</dc:creator><description>&lt;p&gt;The value I read back is set to 6.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI speed not correct</title><link>https://devzone.nordicsemi.com/thread/246219?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2020 11:00:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0bafbd7-782c-49c7-aa67-4c362ec55375</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;If you read out the NRF_TWI-&amp;gt;ENABLE register, what is the value here?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI speed not correct</title><link>https://devzone.nordicsemi.com/thread/246177?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2020 08:38:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3604dfe5-12ab-43c7-b933-63baa0fa56ec</guid><dc:creator>T IJ</dc:creator><description>&lt;p&gt;Ive gotten myself a second&amp;nbsp;nRF52832 development kit to test it on and this one does the same as the other development kit.&lt;/p&gt;
&lt;p&gt;When I set the TWI speed to&amp;nbsp;TWI_FREQUENCY_FREQUENCY_K400 it only sends out a 200kHz clock instead of the 400kHz clock I&amp;#39;d expect.&lt;br /&gt;Only when I set the frequency register to something else than is listed in the datasheet or in nrf52_bitfields.h I am able to get 400kHz or higher even.&lt;/p&gt;
&lt;p&gt;Has anyone experienced this as well?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI speed not correct</title><link>https://devzone.nordicsemi.com/thread/245991?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 10:07:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d71f136e-bb76-4eb9-9d5a-6b29acf4b686</guid><dc:creator>T IJ</dc:creator><description>&lt;p&gt;But the speed listed in the datasheet at 400kbps is not correct, I get 200kbps of speed.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;const nrf_twi_config_t twi_config = 
{
    .scl = 25,
    .sda = 24,
    .frequency = TWI_FREQUENCY_FREQUENCY_K400,
    .interrupt_priority = 2
};

twi_setup(NRF_TWIM0, &amp;amp;twi_config);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This results in 200kbps.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If I change .frequency to 0x0C880000 I get 400kbps, so how is this qualified if it doesntt result in the proper frequency whilst the other frequency settings result in the intended frequency.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI speed not correct</title><link>https://devzone.nordicsemi.com/thread/245989?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 09:58:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:56f2d31c-696b-4b4a-b996-9c13d9202b90</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;It&amp;#39;s only the frequencies listed in the datasheet that has been tested and qualified, so I recommend to use those.&lt;/p&gt;
&lt;p&gt;For TWIM (TWI with EasyDMA) that is:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Ftwim.html&amp;amp;anchor=register.FREQUENCY"&gt;https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Ftwim.html&amp;amp;anchor=register.FREQUENCY&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For TWI (legacy TWI inherit from older nRF51-series):&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Ftwi.html&amp;amp;anchor=register.FREQUENCY"&gt;https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Ftwi.html&amp;amp;anchor=register.FREQUENCY&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It is the ENABLE register that choose whether TWIM or TWI is used, and thereby also the configuration of the registers. If you use TWIM have this errata in mind that indirectly regards frequency:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/errata_nRF52832_Rev2/ERR/nRF52832/Rev2/latest/anomaly_832_219.html"&gt;https://infocenter.nordicsemi.com/topic/errata_nRF52832_Rev2/ERR/nRF52832/Rev2/latest/anomaly_832_219.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>