<?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>Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/69763/garbled-i2c-unless-printf-is-used</link><description>Hi, I have a very odd problem but one which is consistent. As part of my lcd library I send several &amp;#39;&amp;#39;packets&amp;#39; of data interleaved with spacing from a timer. It typically looks like - 6 bytes - 50us - 6 bytes - 50us - 6 bytes ... 
 A second timer works</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 30 Dec 2020 09:38:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/69763/garbled-i2c-unless-printf-is-used" /><item><title>RE: Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/thread/286964?ContentTypeID=1</link><pubDate>Wed, 30 Dec 2020 09:38:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f65a32ba-1c34-4104-ab04-980bf34364f1</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Andrew&lt;/p&gt;
&lt;p&gt;Thanks for the update.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I feel this issue is one that&amp;nbsp;we should be able to solve, but it will probably take some time to figure out what is happening. It is understandable if you want to focus your efforts elsewhere.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/thread/286845?ContentTypeID=1</link><pubDate>Tue, 29 Dec 2020 12:55:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0af9e37e-5741-4a4a-8768-d5bfde3f7264</guid><dc:creator>snoopy20</dc:creator><description>&lt;p&gt;I&amp;#39;ve had to abandon it, the consistency wasn&amp;#39;t there.&lt;br /&gt;&lt;br /&gt;Regards, Andrew&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/thread/286834?ContentTypeID=1</link><pubDate>Tue, 29 Dec 2020 12:27:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:632ca41e-e5ba-4d04-9a35-3ed5f7e10acd</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Thanks for sharing the code, can&amp;#39;t see any issue there ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/thread/286833?ContentTypeID=1</link><pubDate>Tue, 29 Dec 2020 12:27:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6cc4964e-faea-401b-9d30-e94e99a540ac</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The only case where the PPI propagation could be delayed is if the 16MHz peripheral clock is suspended, but unless you enter sleep mode and have disabled all peripherals that require the peripheral clock (such as the UART or a timer in timer mode) this will not be the case. Then the delay of the PPI should be&amp;nbsp;consistent, and only about a clock cycle long.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you going to sleep in between events by the way?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/thread/286296?ContentTypeID=1</link><pubDate>Tue, 22 Dec 2020 13:02:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8948c593-298a-4e9c-a423-e379b9912284</guid><dc:creator>snoopy20</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;struct dmaBufferProto {
uint16_t size;
uint8_t writeLocked;
uint8_t txLocked;
uint8_t packetSize;
uint8_t data[LCD_BUFFER_LENGTH];
};

volatile static struct {
struct dmaBufferProto buffers[LCD_BUFFER_ARRAY];
struct dmaBufferProto *writeBuffer;
struct dmaBufferProto *transferBuffer;
} dmaBuffer;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/thread/286286?ContentTypeID=1</link><pubDate>Tue, 22 Dec 2020 12:42:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de4567b7-b0ec-4e2c-9e33-2eac4ae379de</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;One thing to check is whether or not the data buffer provided to the TWIM PTR register is static or global, or if&amp;nbsp;it is an automatic stack variable that could be overwritten by other data once you return from the function where it was defined.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This could explain why the printf call solves the issue, since&amp;nbsp;it might delay the time before you return from the function so that the data is written to the I2C bus before the&amp;nbsp;stack memory gets reused.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/thread/286113?ContentTypeID=1</link><pubDate>Mon, 21 Dec 2020 15:54:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:178a6346-8f90-40c8-96d2-f415486c9247</guid><dc:creator>snoopy20</dc:creator><description>&lt;p&gt;Could there be a race between the counter shutting down the first timer and the first timer reaching the second CC and triggering the TWIM? I allocated 50 cycles (of 16MHz), perhaps the propagation of the PPI is quite a bit slower than this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/thread/286109?ContentTypeID=1</link><pubDate>Mon, 21 Dec 2020 15:44:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:293169e3-9ecd-4da0-ac18-b9d26187ee79</guid><dc:creator>snoopy20</dc:creator><description>&lt;p&gt;If it helps here&amp;#39;s the code doing the timing. It should all be hardware based and is as far as I can tell.&lt;br /&gt;&lt;br /&gt;The timing for the space is 1600/16000000 or 100us well within the 52us required.&lt;br /&gt;&lt;br /&gt;Then 50 cycles are allowed for the counter timer to shut down the first timer before the next starttx is called.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;  NRF_GPIO-&amp;gt;PIN_CNF[CFG_PIN_LCD_SCL] = LCD_I2C_PIN_INIT_CONF;
  NRF_GPIO-&amp;gt;PIN_CNF[CFG_PIN_LCD_SDA] = LCD_I2C_PIN_INIT_CONF;
  #ifdef CFG_PIN_LCD_VDD
  NRF_GPIO-&amp;gt;PIN_CNF[CFG_PIN_LCD_VDD] = ((GPIO_PIN_CNF_SENSE_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_SENSE_Pos) | (GPIO_PIN_CNF_DRIVE_S0H1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Disconnect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos));
  NRF_GPIO-&amp;gt;OUTSET = 1 &amp;lt;&amp;lt; CFG_PIN_LCD_VDD;
  #endif

  CFG_TIMER_LCD_SPACE-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_32Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos;
  CFG_TIMER_LCD_SPACE-&amp;gt;PRESCALER = 0;
  CFG_TIMER_LCD_SPACE-&amp;gt;CC[0] = LCD_TICKS_BETWEEN_DATA - 50;
  CFG_TIMER_LCD_SPACE-&amp;gt;CC[1] = LCD_TICKS_BETWEEN_DATA;
  CFG_TIMER_LCD_SPACE-&amp;gt;SHORTS = TIMER_SHORTS_COMPARE1_STOP_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE1_STOP_Pos | TIMER_SHORTS_COMPARE1_CLEAR_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE1_CLEAR_Pos;

  CFG_TIMER_LCD_COUNTER-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_32Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos;
  CFG_TIMER_LCD_COUNTER-&amp;gt;PRESCALER = 0;
  CFG_TIMER_LCD_COUNTER-&amp;gt;MODE = TIMER_MODE_MODE_LowPowerCounter &amp;lt;&amp;lt; TIMER_MODE_MODE_Pos;
  CFG_TIMER_LCD_COUNTER-&amp;gt;SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE0_CLEAR_Pos;
  CFG_TIMER_LCD_COUNTER-&amp;gt;INTENSET = TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos;
 
  CFG_TWIM_LCD_TX-&amp;gt;ADDRESS = LCD_I2C_ADDRESS;
  CFG_TWIM_LCD_TX-&amp;gt;FREQUENCY = TWIM_FREQUENCY_FREQUENCY_K100 &amp;lt;&amp;lt; TWIM_FREQUENCY_FREQUENCY_Pos;
  CFG_TWIM_LCD_TX-&amp;gt;PSEL.SCL = (TWIM_PSEL_SCL_CONNECT_Connected &amp;lt;&amp;lt; TWIM_PSEL_SCL_CONNECT_Pos) | CFG_PIN_LCD_SCL;
  CFG_TWIM_LCD_TX-&amp;gt;PSEL.SDA = (TWIM_PSEL_SDA_CONNECT_Connected &amp;lt;&amp;lt; TWIM_PSEL_SDA_CONNECT_Pos) | CFG_PIN_LCD_SDA;
  CFG_TWIM_LCD_TX-&amp;gt;SHORTS = TWIM_SHORTS_LASTTX_STOP_Enabled &amp;lt;&amp;lt; TWIM_SHORTS_LASTTX_STOP_Pos;
  CFG_TWIM_LCD_TX-&amp;gt;TXD.LIST = TWIM_TXD_LIST_LIST_ArrayList &amp;lt;&amp;lt; TWIM_TXD_LIST_LIST_Pos;
  CFG_TWIM_LCD_TX-&amp;gt;ENABLE = TWIM_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; TWIM_ENABLE_ENABLE_Pos;

  NRF_PPI-&amp;gt;CH[CFG_PPI_LCD_CHANNEL_TWIM_SPACE].EEP = (uint32_t) &amp;amp;CFG_TWIM_LCD_TX-&amp;gt;EVENTS_LASTTX; // wire timer compare
  NRF_PPI-&amp;gt;CH[CFG_PPI_LCD_CHANNEL_TWIM_SPACE].TEP = (uint32_t) &amp;amp;CFG_TIMER_LCD_SPACE-&amp;gt;TASKS_START; 
  NRF_PPI-&amp;gt;CH[CFG_PPI_LCD_CHANNEL_SPACE_COUNT].EEP = (uint32_t) &amp;amp;CFG_TIMER_LCD_SPACE-&amp;gt;EVENTS_COMPARE[0]; // wire timer compare
  NRF_PPI-&amp;gt;CH[CFG_PPI_LCD_CHANNEL_SPACE_COUNT].TEP = (uint32_t) &amp;amp;CFG_TIMER_LCD_COUNTER-&amp;gt;TASKS_COUNT;
  NRF_PPI-&amp;gt;CH[CFG_PPI_LCD_CHANNEL_SPACE_START].EEP = (uint32_t) &amp;amp;CFG_TIMER_LCD_SPACE-&amp;gt;EVENTS_COMPARE[1]; // wire timer compare
  NRF_PPI-&amp;gt;CH[CFG_PPI_LCD_CHANNEL_SPACE_START].TEP = (uint32_t) &amp;amp;CFG_TWIM_LCD_TX-&amp;gt;TASKS_STARTTX;
  NRF_PPI-&amp;gt;CH[CFG_PPI_LCD_CHANNEL_COUNTER_RESET].EEP = (uint32_t) &amp;amp;CFG_TIMER_LCD_COUNTER-&amp;gt;EVENTS_COMPARE[0]; // wire timer compare
  NRF_PPI-&amp;gt;CH[CFG_PPI_LCD_CHANNEL_COUNTER_RESET].TEP = (uint32_t) &amp;amp;CFG_TIMER_LCD_SPACE-&amp;gt;TASKS_STOP;
  NRF_PPI-&amp;gt;FORK[CFG_PPI_LCD_CHANNEL_COUNTER_RESET].TEP = (uint32_t) &amp;amp;CFG_TIMER_LCD_SPACE-&amp;gt;TASKS_CLEAR;
  NRF_PPI-&amp;gt;CHENSET = 1 &amp;lt;&amp;lt; CFG_PPI_LCD_CHANNEL_TWIM_SPACE | 1 &amp;lt;&amp;lt; CFG_PPI_LCD_CHANNEL_SPACE_COUNT | 1 &amp;lt;&amp;lt; CFG_PPI_LCD_CHANNEL_SPACE_START | 1 &amp;lt;&amp;lt; CFG_PPI_LCD_CHANNEL_COUNTER_RESET;  // enable ppi channel
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The hard fault occurs because the TWIM has given up and eventually the circular buffer overruns itself. Not part of the problem as it works fine while the TWIM is operational.&lt;br /&gt;&lt;br /&gt;After a random amount of time, with consistent and identical data packets sent over I2C, the TWIM faults and causes the cascading failure.&lt;br /&gt;&lt;br /&gt;Swagger&amp;nbsp; = Segger. :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/thread/286107?ContentTypeID=1</link><pubDate>Mon, 21 Dec 2020 15:40:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:452e081e-8d0e-43a6-8c69-7557bc096298</guid><dc:creator>awneil</dc:creator><description>[quote userid="89627" url="~/f/nordic-q-a/69763/garbled-i2c-unless-printf-is-used/286099#286099"]the TWIM will randomly begin producing garbage[/quote]
&lt;p&gt;Do you mean it&amp;#39;s transmitting garbage, or just that the LCD is showing garbage?&lt;/p&gt;
&lt;p&gt;Do you have an analyser to see what&amp;#39;s happening on the wires?&lt;/p&gt;
[quote userid="89627" url="~/f/nordic-q-a/69763/garbled-i2c-unless-printf-is-used/286099#286099"]end in a hard fault[/quote]
&lt;p&gt;That points to a bug in the code; eg, buffer overrun, stack corruption, memory leaks ...&lt;/p&gt;
&lt;p&gt;What debugging have you done to find what&amp;#39;s causing the Hard Fault?&lt;/p&gt;
&lt;p&gt;You should get some diagnsotics.&lt;/p&gt;
[quote userid="89627" url="~/f/nordic-q-a/69763/garbled-i2c-unless-printf-is-used/286099#286099"]via swagger[/quote]
&lt;p&gt;has that been a victim of autocorrect?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/thread/286099?ContentTypeID=1</link><pubDate>Mon, 21 Dec 2020 15:20:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d7e498d5-0dd2-452a-a6d3-23ebc11ff3a4</guid><dc:creator>snoopy20</dc:creator><description>&lt;p&gt;The LCD has a I2C piggyback on it, it&amp;#39;s a timing requirement between commands.&lt;br /&gt;&lt;br /&gt;I&amp;#39;ve tried all sorts of timing increases and decreases but after a few days at it I&amp;#39;ve found the TWIM will randomly begin producing garbage and end in a hard fault.&lt;br /&gt;&lt;br /&gt;Yet using&amp;nbsp;printf(&amp;quot;here \n&amp;quot;)&amp;nbsp;in that above statement causes it to behave. I&amp;#39;m unsure if printf (via swagger) stalls the CPU in a different way to nrf_delay burning cycles. I&amp;#39;m specifically interested in whether the clock to the TWIM peripheral is being stalled, which seems more likely.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Garbled I2C unless printf is used</title><link>https://devzone.nordicsemi.com/thread/286091?ContentTypeID=1</link><pubDate>Mon, 21 Dec 2020 14:59:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9e33162-2954-4481-b66c-837560bfeb68</guid><dc:creator>awneil</dc:creator><description>[quote userid="89627" url="~/f/nordic-q-a/69763/garbled-i2c-unless-printf-is-used"]6 bytes - 50us - 6 bytes - 50us - 6 bytes ...[/quote]
&lt;p&gt;What&amp;#39;s the point of the delay?&lt;/p&gt;
&lt;p&gt;Why 50us?&amp;nbsp;Have you verified that you are actually getting 50us?&lt;/p&gt;
[quote userid="89627" url="~/f/nordic-q-a/69763/garbled-i2c-unless-printf-is-used"]If I remove this statement I get garbage[/quote]
&lt;p&gt;sounds like a timing issue.&lt;/p&gt;
&lt;p&gt;What happens if you increase your &amp;quot;50us&amp;quot; ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>