<?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>First I2C code on nRF Connect, I think I&amp;#39;m close</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87883/first-i2c-code-on-nrf-connect-i-think-i-m-close</link><description>Crawling up the learning curve here, doing my best to solve my own problems, but I&amp;#39;m down to just permuting things on this one and I&amp;#39;m not making much progress and all the examples I can find just seem a little different to what I want to do.. Trying</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 14 May 2022 08:42:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87883/first-i2c-code-on-nrf-connect-i-think-i-m-close" /><item><title>RE: First I2C code on nRF Connect, I think I'm close</title><link>https://devzone.nordicsemi.com/thread/367910?ContentTypeID=1</link><pubDate>Sat, 14 May 2022 08:42:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a87bc72b-7c37-46ec-b6b0-149f796a7656</guid><dc:creator>Paul Kelly</dc:creator><description>&lt;p&gt;So here&amp;#39;s where I got to:&lt;br /&gt;I went through the fujitsu example and got my head around the difference between writing a driver and just spitting I2C out. You don&amp;#39;t need the second bit in the overlay file:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;my_eeprom:nRF52833@28 {
&amp;#160; &amp;#160; &amp;#160;status = &amp;quot;okay&amp;quot;;
&amp;#160; &amp;#160; &amp;#160;reg = &amp;lt;0x28&amp;gt;;
&amp;#160; &amp;#160; &amp;#160;label = &amp;quot;config_eeprom&amp;quot;;
&amp;#160; &amp;#160;};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you just want to drive the bus directly.&lt;br /&gt;&lt;br /&gt;Then I went over the tutorial and got aliases an nodelabels back in my head and managed to get a reference to the device. This got me past the problem that generated this post.&lt;br /&gt;&lt;br /&gt;Next I wrote a simple, blocking, library and that more or less just worked.&lt;br /&gt;&lt;br /&gt;So I&amp;#39;m moving forward again!&lt;br /&gt;&lt;br /&gt;I&amp;#39;m storing a whole bunch of config information on the eeprom, The product can&amp;#39;t really do anything until this is loaded, so a blocking implementation is mostly OK. I can wear some delays on writes too.&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I&amp;#39;ll revisit this later and get it playing nice with threads...&lt;br /&gt;Many thanks to all...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: First I2C code on nRF Connect, I think I'm close</title><link>https://devzone.nordicsemi.com/thread/367821?ContentTypeID=1</link><pubDate>Fri, 13 May 2022 11:29:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:869e679f-0a66-47fc-93db-40f9633fa3df</guid><dc:creator>&amp;#216;ivind</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;quot;my_eeprom&amp;quot; is a node label, not an alias. Replace DT_ALIAS() with DT_NODELABEL().&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: First I2C code on nRF Connect, I think I'm close</title><link>https://devzone.nordicsemi.com/thread/367753?ContentTypeID=1</link><pubDate>Fri, 13 May 2022 06:15:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d7bb5c1-ed02-40ee-8ec3-70870c62ec2a</guid><dc:creator>tedhavelka</dc:creator><description>&lt;p&gt;Hello Paul Kelly,&lt;/p&gt;
&lt;p&gt;Regarding your shared code excerpts, your device tree source looks good and so too your Kconfig settings from project source &amp;#39;prj.conf&amp;#39;.&amp;nbsp; In your void main() routine, and the pound define involving Zephyr macros just above it, it appears that you are creating a device pointer ( I mean a C pointer to a Zephyr device that is your EEPROM ) and then you are calling a routine to set the I2C peripheral&amp;#39;s clock rate using that EEPROM device pointer.&lt;/p&gt;
&lt;p&gt;I believe you may want or need to set I2C clock speed via the I2C device structure, or pointer to it, rather than the EEPROM device structure.&lt;/p&gt;
&lt;p&gt;You have the option to set your chosen I2C peripheral instance clock or bus speed in your board&amp;#39;s DTS file, in the way that Nordic&amp;#39;s &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/main/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L129" rel="noopener noreferrer" target="_blank"&gt;nRF9160 DTS board file sets i2c2 clock frequency&lt;/a&gt;, using device tree source.&amp;nbsp; This obviates the need to call API routine i2c_configure().&lt;/p&gt;
&lt;p&gt;And actually on review I see you already have a DTS line to set I2C clock speed.&amp;nbsp; You can change the stanza &amp;#39;clock-frequency = &amp;lt;100000&amp;gt;;&amp;#39; as needed.&lt;/p&gt;
&lt;p&gt;So a next question as you &amp;quot;try to get project talking with an EEPROM&amp;quot; would be, do you have a driver available for your particular EEPROM?&amp;nbsp; Most likely if you have one it will be a Zephyr &amp;quot;out of tree&amp;quot; driver.&amp;nbsp; Zephyr&amp;#39;s &amp;quot;in tree&amp;quot; drivers, maybe you know this, are generally for peripherals which are found on most or many microcontrollers, e.g. peripherals like UART, I2C, ADC.&amp;nbsp; Peripherals which are most often on chip.&amp;nbsp; Your prj.conf line &amp;#39;CONFIG_I2C=y&amp;#39; enables the compiling of Zephyr&amp;#39;s &lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/main/drivers/i2c" rel="noopener noreferrer" target="_blank"&gt;in tree I2C drivers&lt;/a&gt;.&amp;nbsp; If your EEPROM has a driver already available, an initializing routine there will assign the i2c0 device you want to express in your line &amp;#39;#define twi0 DT_LABEL(DT_ALIAS(my_eeprom))&amp;#39;.&amp;nbsp; Also, if you have and can enjoy the EEPROM driver already written, that will shield you from having to call the I2C API routines directly.&amp;nbsp; The out-of-tree driver API will have things like &amp;quot;write_config_register()&amp;quot;, &amp;quot;read_page()&amp;quot;, etc, and your main line code won&amp;#39;t have to deal with or know about the lower level bus protocol and I2C details.&lt;/p&gt;
&lt;p&gt;If the manufacture of your EEPROM and larger open source community have not yet written a driver for it, you have choices.&amp;nbsp; You could write your own out-of-tree driver -- not trivial! -- but an effort with many potential future returns if you plan on re-using and sharing your code, and developing long term with Zephyr.&amp;nbsp; You could also more or less &amp;quot;bit bang&amp;quot; your driver in main line code.&amp;nbsp; But in that case, the code is messier in its factoring, and you cannot easily share or port that kind of driver implementation to others to use, or even to other projects of your own.&amp;nbsp; You would then also miss out on some really cool features explained in &lt;a href="https://www.youtube.com/watch?v=sWaxQyIgEBY" rel="noopener noreferrer" target="_blank"&gt;Marti Bolivar&amp;#39;s Zephyr and Device Tree Tutorial&lt;/a&gt;, especially some of the flexible things we can do with multiple device instances as described at about the 40 minute mark in this video.&lt;/p&gt;
&lt;p&gt;In your code above I&amp;#39;m not able to answer specifically why &lt;span&gt;DT_N_ALIAS_my_eeprom_P_label is undefined.&amp;nbsp; I still have trouble often when tracking down the same kind of error when I amend project device tree sources.&amp;nbsp; But I hope this answer helps in the broader sense.&amp;nbsp; You are certainly close to setting your needed I2C clock speed.&amp;nbsp; The bigger question will probably be whether you have an EEPROM driver available or must write one.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Take care,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;- Ted&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>