<?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>Calling TWI driver from multiple files using nrf_drv_twi</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/8959/calling-twi-driver-from-multiple-files-using-nrf_drv_twi</link><description>Hi,
I use nrf51822 with SDK8.1, S110 and gcc with Makefile. I want to use nrf_drv_twi in both my main “.c” file as well as a library “.c” file that is included in the build. So in my main file I have: 
 #include &amp;lt;nrf_drv_twi.h&amp;gt;
//create TWI hardware</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 29 Aug 2015 01:40:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/8959/calling-twi-driver-from-multiple-files-using-nrf_drv_twi" /><item><title>RE: Calling TWI driver from multiple files using nrf_drv_twi</title><link>https://devzone.nordicsemi.com/thread/33002?ContentTypeID=1</link><pubDate>Sat, 29 Aug 2015 01:40:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:99243e4e-a147-4e20-9922-94a4d65f4462</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;This is a basic C question. Either pass the twi instance to your library functions as a parameter, ie change the function from&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void some_function( char some_data ); 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void some_function( nrf_drv_twi_t *twi_ptr, char some_data );
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or declare it in a header file marked extern&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;extern nrf_drv_twi_t twi;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and define it in one of the C files&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrf_drv_twi_t twi;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;it&amp;#39;s now an external symbol you can use from anywhere&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>