<?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>nRF5340 - DAC driver in Zephyr</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/63460/nrf5340---dac-driver-in-zephyr</link><description>Hi, 
 
 to develop a device driver in Zephyr for TI DAC80501, a 16-bit DAC, I2C interface, 
 I have to 
 
 1. add the dts child node under the i2c controller node 
 $i2c1 { dac80501@48 { compatible = &amp;quot;ti,dac80501&amp;quot;; reg = &amp;lt;0x48&amp;gt;; }; }; 
 
 2. find a devicetree</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 26 Aug 2020 07:15:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/63460/nrf5340---dac-driver-in-zephyr" /><item><title>RE: nRF5340 - DAC driver in Zephyr</title><link>https://devzone.nordicsemi.com/thread/266365?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2020 07:15:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dfd7160b-8ebe-47e5-ae35-2d0c4ecb3d7a</guid><dc:creator>Gabriele</dc:creator><description>&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;Thank you, I definitely agree with your remark. &lt;br /&gt;My device is a DAC, then putting the driver into &amp;lt;zephyr&amp;gt;/drivers/dac is more appropriate.&lt;br /&gt;Hereinafter the complete process&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;1) Under &amp;lt;zephyr&amp;gt;/drivers/dac/ add files&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;dac_dacx0501.c&lt;br /&gt;&amp;nbsp;dac_dacx0501.h&lt;br /&gt;&amp;nbsp;Kconfig.dacx0501&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;2) In &amp;lt;zephyr&amp;gt;/drivers/dac/CMakeLists.txt add the line &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;zephyr_library_sources_ifdef(CONFIG_DAC_DACX0501&amp;nbsp;&amp;nbsp;&amp;nbsp; dac_dacx0501.c)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;3) In &amp;lt;zephyr&amp;gt;/drivers/dac/Kconfig add the line &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;source &amp;quot;drivers/dac/Kconfig.dacx0501&amp;quot;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;4) In dac_dacx0501.c implement the I2C read/write functions&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;int dacx501_reg_read()&amp;nbsp;&amp;nbsp;to read a register&lt;br /&gt;&amp;nbsp;int dacx501_reg_write()&amp;nbsp;to overwrite a register&lt;br /&gt;&amp;nbsp;int dacx501_init()&amp;nbsp;&amp;nbsp;to initialize the driver and the device&lt;br /&gt;&amp;nbsp;int dacx501_channel_setup()&amp;nbsp;the standard API to open a DAC channel (I have only one)&lt;br /&gt;&amp;nbsp;int dacx501_write_value()&amp;nbsp;the standard API to write a value to DAC&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;As for the application side &amp;lt;src&amp;gt;/main.c&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;5) Include&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;#include &amp;lt;include/device.h&amp;gt;&lt;br /&gt;&amp;nbsp;#include &amp;lt;dac.h&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;6) Retrieve the device structure for a the DAC driver by name using&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;struct device* device_get_binding()&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;7) Create the structure for specifying the configuration of the DAC channel&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;struct dac_channel_cfg&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;8) Use it to configure the DAC channel with&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;int dac_channel_setup()&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;9) Finally you are able to write data to the DAC using&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;int dac_write_value()&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;Gabriele&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - DAC driver in Zephyr</title><link>https://devzone.nordicsemi.com/thread/266300?ContentTypeID=1</link><pubDate>Tue, 25 Aug 2020 15:22:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9881703b-333f-4bc9-971b-6fbe84c65971</guid><dc:creator>DBT</dc:creator><description>&lt;p&gt;I&amp;#39;ve been working on adding a new sensor.&lt;/p&gt;
&lt;p&gt;This ticket has been very helpful.&lt;/p&gt;
&lt;p&gt;Just thought I should add for others that you&amp;#39;ll also want to modify these files when adding a new sensor&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;\zephyr\drivers\sensor\CMakeLists.txt&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="padding-left:60px;"&gt;&lt;em&gt;add_subdirectory_ifdef(CONFIG_&amp;lt;name of sensor&amp;gt;&amp;nbsp; &amp;nbsp;&amp;lt;sensor directory&amp;gt;)&lt;/em&gt;&lt;/p&gt;
&lt;div class="evolution-code-editor theme-clouds"&gt;&lt;a class="fullscreen" href="https://devzone.nordicsemi.com/support/255136"&gt;&lt;/a&gt;
&lt;div class=" ace_editor ace-clouds"&gt;
&lt;div class="ace_scroller"&gt;
&lt;div class="ace_content"&gt;
&lt;div class="ace_layer ace_text-layer"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Add this to&amp;nbsp;&lt;em&gt;\zephyr\drivers\sensor\Kconfig&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;div class="evolution-code-editor theme-clouds" style="padding-left:30px;"&gt;
&lt;div class=" ace_editor ace-clouds"&gt;
&lt;div class="ace_scroller"&gt;
&lt;div class="ace_content"&gt;
&lt;div class="ace_layer ace_print-margin-layer"&gt;&lt;/div&gt;
&lt;div class="ace_layer ace_marker-layer" style="padding-left:30px;"&gt;source &amp;quot;drivers/sensor/&amp;lt;sensor directory&amp;gt;/Kconfig&amp;quot;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - DAC driver in Zephyr</title><link>https://devzone.nordicsemi.com/thread/259002?ContentTypeID=1</link><pubDate>Wed, 08 Jul 2020 13:21:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8c6dcd2-41ce-45bf-ac18-e4168d27c76b</guid><dc:creator>Gabriele</dc:creator><description>&lt;p&gt;My bad mistake! The correct gpio numbers are&lt;br /&gt; sda-pin = &amp;lt;34&amp;gt;;&lt;br /&gt; scl-pin = &amp;lt;35&amp;gt;;&lt;br /&gt;This issue is closed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - DAC driver in Zephyr</title><link>https://devzone.nordicsemi.com/thread/258990?ContentTypeID=1</link><pubDate>Wed, 08 Jul 2020 12:12:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a1c1caf-1f8c-4b57-92cc-bdb5129954b0</guid><dc:creator>Gabriele</dc:creator><description>&lt;p&gt;Additional information you might find of worth&lt;/p&gt;
&lt;p&gt;DT_INST_REG_ADDR(0) expands to 72&lt;/p&gt;
&lt;p&gt;As for the zephyr configuration added to prj.conf&lt;/p&gt;
&lt;p&gt;CONFIG_I2C=y&lt;br /&gt;CONFIG_I2C_1=y&lt;br /&gt;CONFIG_SENSOR=y&lt;br /&gt;CONFIG_DACX0501=y&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Gabriele&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - DAC driver in Zephyr</title><link>https://devzone.nordicsemi.com/thread/258921?ContentTypeID=1</link><pubDate>Wed, 08 Jul 2020 07:33:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:643f7cd9-37e4-4d80-a590-e3df7816c9a5</guid><dc:creator>Gabriele</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;I have a custom board based on nRF5340. I have SDA connected to pin P1.02 and SCL connected to pin P1.03.&lt;br /&gt;I&amp;#39;ve made some progress following your suggestions.&lt;/p&gt;
&lt;p&gt;1. The DTS section of the board looks like this&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp;&amp;amp;i2c1 {&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; compatible = &amp;quot;nordic,nrf-twim&amp;quot;;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; status = &amp;quot;okay&amp;quot;;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; clock-frequency = &amp;lt;100000&amp;gt;;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; sda-pin = &amp;lt;33&amp;gt;;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; scl-pin = &amp;lt;34&amp;gt;;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; dac: dacx0501@48 {&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;compatible = &amp;quot;ti,dacx0501&amp;quot;;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;label = &amp;quot;DAC80501&amp;quot;;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reg = &amp;lt;0x48&amp;gt;;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; };&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp;};&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;2. For the binding part I&amp;#39;ve added file /ncs/zephyr/dts/bindings/sensor/ti,dacx0501.yaml with content&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp;description: Texas Instruments 12/14/16-bit DAC (e.g. DAC80501)&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp;compatible: &amp;quot;ti,dacx0501&amp;quot;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp;include: i2c-device.yaml&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;(You might wander why to put a DAC into sensor branch. This is just a temporary measure.)&lt;/p&gt;
&lt;p&gt;3. For the driver part I&amp;#39;ve added files under /ncs/zephyr/drivers/sensors/dacx0501/&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp;dacx0501.c&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp;dacx0501.h&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp;Kconfig&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;At the very first I2C reading from device&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp;if (i2c_read(drv_data-&amp;gt;i2c, buf, 4, DT_INST_REG_ADDR(0)) &amp;lt; 0) {&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; LOG_ERR(&amp;quot;Failed to read sample data&amp;quot;);&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return -EIO;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; &amp;nbsp;}&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I get an error log message&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;&lt;strong&gt;&lt;em&gt;E: Error 195952641 occurred for message 0&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;which correspondes to error number 0xBAE0000, or &amp;quot;NRFX_ERROR_DRV_TWI_ERR_ANACK&amp;quot;.&lt;/p&gt;
&lt;p&gt;Can you figure out how to fix this ?&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;br /&gt;Gabriele&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - DAC driver in Zephyr</title><link>https://devzone.nordicsemi.com/thread/258872?ContentTypeID=1</link><pubDate>Tue, 07 Jul 2020 17:56:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8b290d3-a940-4762-a136-955b225f2b8e</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Do you have any more specific questions regarding 1 and 2? How far have you come with the implementation?&lt;/p&gt;
&lt;p&gt;I would recommend reading&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/reference/drivers/index.html#device-driver-model"&gt;Device Driver Model&lt;/a&gt;&amp;nbsp;and understand that, which will give you a great starting point. Then I would look at the already present Sensor drivers and try to&amp;nbsp;mirror them. E.g. if you use the adxl362 as a reference, look at the yaml file&amp;nbsp;&lt;em&gt;zephyr\dts\bindings\sensor\adi,adxl362.yaml,&amp;nbsp;&lt;/em&gt;the driver in&amp;nbsp;zephyr\drivers\sensor\adxl362 and the sample&amp;nbsp;zephyr\samples\sensor\adxl362 which shows how to use that driver. The sample doesn&amp;#39;t interract with the adxl362 driver directly but uses the &lt;a href="https://docs.zephyrproject.org/latest/reference/peripherals/sensor.html"&gt;Sensor Subsystem&lt;/a&gt; on top of that. Take a look at the figure&amp;nbsp;below to see all the abstraction layers included:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/500x350/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-6eb632b257ff490b8385ffb58cfaa453/pastedimage1594144495687v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;There may be some step-by-step tutorials on how to do this, but I couldn&amp;#39;t find it after a quick search.&lt;/p&gt;
&lt;p&gt;Since this is a more Zephyr related question, you may get better help here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues"&gt;https://github.com/zephyrproject-rtos/zephyr/issues&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://lists.zephyrproject.org/g/devel/topics"&gt;https://lists.zephyrproject.org/g/devel/topics&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>