<?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>How to implement two TWI instances</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/42276/how-to-implement-two-twi-instances</link><description>Hello, 
 I am having difficulty using a single TWI to support a DAC (MCP4725) and IMU (BNO055). 
 I am using nRF52 DK, and SDK 14.3 with the SEGGER IDE. The DAC is running on a timer with samples being loaded every 200 micro seconds. The IMU is running</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 23 Jan 2019 13:59:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/42276/how-to-implement-two-twi-instances" /><item><title>RE: How to implement two TWI instances</title><link>https://devzone.nordicsemi.com/thread/167389?ContentTypeID=1</link><pubDate>Wed, 23 Jan 2019 13:59:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f89f55a0-a89e-46f8-af22-c32c67da7559</guid><dc:creator>GaryD</dc:creator><description>&lt;p&gt;Torbjorn,&lt;/p&gt;
&lt;p&gt;The dual TWI masters works well - I still have under 1 mS distortion during transmission of samples over BLE.&amp;nbsp; The DAC samples involved in the delay are buffered and the waveform &amp;quot;catches up&amp;quot; by sending the samples out faster than every 200 uS.&amp;nbsp; We can live with that for now.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " height="311" src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/SDS00112.BMP" width="519" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement two TWI instances</title><link>https://devzone.nordicsemi.com/thread/165079?ContentTypeID=1</link><pubDate>Fri, 11 Jan 2019 08:41:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a451801-5de9-4666-9c4f-9cf8be59dc4a</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Gary&lt;/p&gt;
&lt;p&gt;The best of luck. If you have more questions just let me know &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&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: How to implement two TWI instances</title><link>https://devzone.nordicsemi.com/thread/164978?ContentTypeID=1</link><pubDate>Thu, 10 Jan 2019 15:14:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71f4c48e-a3d0-43a8-93e1-130d7b3b820d</guid><dc:creator>GaryD</dc:creator><description>&lt;p&gt;Thank you Torbjorn,&lt;/p&gt;
&lt;p&gt;I will look into these and should have implemented the dual TWI by early next week and will let you know the result.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If that does not completely solve it, I will try the alternative using PPI that you suggested.&lt;/p&gt;
&lt;p&gt;I apologize for the typo on the SDK - I am using SDK 14.2.0&lt;/p&gt;
&lt;p&gt;Thanks for your prompt support.&lt;/p&gt;
&lt;p&gt;Gary&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement two TWI instances</title><link>https://devzone.nordicsemi.com/thread/164917?ContentTypeID=1</link><pubDate>Thu, 10 Jan 2019 12:52:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1964812-32ee-4b62-a189-5d5c7691b892</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Gary&lt;/p&gt;
&lt;p&gt;The advantage of using two TWI masters is that you can run two transactions in parallel, without the second having to wait for the first to complete.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You still need to run some code from the CPU to start the transaction, but this should be a much quicker procedure than the full transaction.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The TWI master interfaces also have an array list feature, which allow you to fire off multiple write transactions without having to run any code on the MCU side. An event from a timer can be connected to the TWI master over PPI, allowing you to trigger the TWI in the background while the CPU is busy doing something else.&amp;nbsp;&lt;br /&gt;If using two TWI master interfaces is not sufficient to get completely smooth ADC data then this is something you could look into.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sampling the ADC should not have to impact the TWI communication, as this can also run transparently in the background. Just make sure that any ADC event handler used to process the data is running at a lower IRQ priority (higher priority number).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know where you found the reference to 800K TWI frequency. The hardware in the nRF52832 is ratified to 400K only, and I couldn&amp;#39;t find the commented define you mentioned in either SDK v14.2.0 or SDK v15.2.0 (there is no SDK v14.3.0).&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: How to implement two TWI instances</title><link>https://devzone.nordicsemi.com/thread/164918?ContentTypeID=1</link><pubDate>Thu, 10 Jan 2019 12:52:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2486d4b-3836-496a-8504-1efc2e028852</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Gary&lt;/p&gt;
&lt;p&gt;The advantage of using two TWI masters is that you can run two transactions in parallel, without the second having to wait for the first to complete.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You still need to run some code from the CPU to start the transaction, but this should be a much quicker procedure than the full transaction.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The TWI master interfaces also have an array list feature, which allow you to fire off multiple write transactions without having to run any code on the MCU side. An event from a timer can be connected to the TWI master over PPI, allowing you to trigger the TWI in the background while the CPU is busy doing something else.&amp;nbsp;&lt;br /&gt;If using two TWI master interfaces is not sufficient to get completely smooth ADC data then this is something you could look into.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sampling the ADC should not have to impact the TWI communication, as this can also run transparently in the background. Just make sure that any ADC event handler used to process the data is running at a lower IRQ priority (higher priority number).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know where you found the reference to 800K TWI frequency. The hardware in the nRF52832 is ratified to 400K only, and I couldn&amp;#39;t find the commented define you mentioned in either SDK v14.2.0 or SDK v15.2.0 (there is no SDK v14.3.0).&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: How to implement two TWI instances</title><link>https://devzone.nordicsemi.com/thread/164797?ContentTypeID=1</link><pubDate>Thu, 10 Jan 2019 02:07:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:194433e1-d789-42b9-9b4e-7122542ade95</guid><dc:creator>GaryD</dc:creator><description>&lt;p&gt;Thanks for the hint on posting code - will try that next time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement two TWI instances</title><link>https://devzone.nordicsemi.com/thread/164791?ContentTypeID=1</link><pubDate>Wed, 09 Jan 2019 20:40:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:01805181-333c-4109-939a-ad7aff65508c</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Seems to be a popular topic lately:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/42228/two-device-use-twi-transfers-may-be-conflict"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/42228/two-device-use-twi-transfers-may-be-conflict&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/42189/combine-two-different-twi-into-a-single-function/164164#164164"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/42189/combine-two-different-twi-into-a-single-function/164164#164164&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement two TWI instances</title><link>https://devzone.nordicsemi.com/thread/164790?ContentTypeID=1</link><pubDate>Wed, 09 Jan 2019 20:37:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee0dce88-328e-45b6-9d1b-451f9e87c070</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;How to properly post source code:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/5811._5F00_Insert-Code-_2D00_-Nordic.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement two TWI instances</title><link>https://devzone.nordicsemi.com/thread/164775?ContentTypeID=1</link><pubDate>Wed, 09 Jan 2019 17:12:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4038a645-e320-4e18-a1a4-a999cfe2c568</guid><dc:creator>GaryD</dc:creator><description>&lt;p&gt;Thank you for your prompt response Torbjorn,&lt;/p&gt;
&lt;p&gt;I will scope out the TWI lines and let you know my findings.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There is an option in the nrf_twi.h file for 800kbps operation that has been commented out - can that be used?&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;typedef enum&lt;br /&gt;{&lt;br /&gt; NRF_TWI_FREQ_100K = TWI_FREQUENCY_FREQUENCY_K100, ///&amp;lt; 100 kbps.&lt;br /&gt; NRF_TWI_FREQ_250K = TWI_FREQUENCY_FREQUENCY_K250, ///&amp;lt; 250 kbps.&lt;br /&gt; NRF_TWI_FREQ_400K = TWI_FREQUENCY_FREQUENCY_K400, ///&amp;lt; 400 kbps.&lt;br /&gt; //NRF_TWI_FREQ_800K = TWI_FREQUENCY_FREQUENCY_K800 ///&amp;lt; 800 kbps&lt;br /&gt;} nrf_twi_frequency_t;&lt;/p&gt;
&lt;p&gt;Also, I used 10k pullups for the SDA/SCL lines and I found your spec calls out for less than 7k - I plan to change it to around 5k. Do I need to beef up the GPIO output to handle a 5k pullup resistors?&lt;/p&gt;
&lt;p&gt;There are no reads from the DAC, only writes based on an app timer going off every 200 micro seconds.&amp;nbsp; The IMU&amp;nbsp;is read&amp;nbsp;for six 16 bit samples running on a separate app timer at 20 milliseconds.&amp;nbsp; The IMU only requires 128 clock cycles to transfer the data in from the IMU but one point I will check is to see if the IMU promptly responds to the read request - if not, then the TWI bus may be locked up waiting on the IMU.&amp;nbsp; Do you agree that using a second TWI master can resolve the issue and not impact the other TWI?&lt;/p&gt;
&lt;p&gt;I do have four ADCs running on internal clocks for other data collection but that only happens every couple of seconds.&amp;nbsp; Can the &amp;quot;independent&amp;quot; running of ADC collection impact the timing on the TWI channels?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I also have PWM being generated at varying duty cycles (1 to 10 %) at frequencies up to 20 K Hz.&amp;nbsp; Again, the frequency of corruption does not correlate to the PWM generation.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I will check on the using a unique index in the&amp;nbsp;NRF_DRV_TWI_INSTANCE(x) macro - I am not sure how to do that but will let you know if I need additional help to check that.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement two TWI instances</title><link>https://devzone.nordicsemi.com/thread/164736?ContentTypeID=1</link><pubDate>Wed, 09 Jan 2019 14:24:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7540e5ce-1a85-4313-b575-661e8134f21d</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Gary&lt;/p&gt;
&lt;p&gt;Have you tried to scope the TWI lines to see how the TWI transactions are scheduled?&lt;/p&gt;
&lt;p&gt;Are you sure that there is enough time to read both the sensors within the same interval?&lt;/p&gt;
&lt;p&gt;Is the DAC being read every 200us, or does it buffer multiple samples before you have to read them out?&lt;/p&gt;
&lt;p&gt;1. If the problem is bus bandwidth then using 2 TWI&amp;#39;s should solve the problem, but it is possible you could also solve it by finding a different way to schedule the TWI access (by making sure you wait for the next DAC transaction before servicing the IMU for instance).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2. Yes, any GPIO on the nRF52832 can be used for TWI.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;3. Assuming you initialize the m_imu variable using a unique index in the&amp;nbsp;NRF_DRV_TWI_INSTANCE(x) macro, then it should be correct.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;4. Without knowing more about your system I don&amp;#39;t want to speculate too much. Is the timer sampling the ADC internal in the ADC, or controlled from the Nordic device?&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></channel></rss>