<?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>I²C communication between a nrf5240 and a MCP3221</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79554/i2c-communication-between-a-nrf5240-and-a-mcp3221</link><description>Hello, 
 I would like to implement an I&amp;#178;C communication between a nrf52840 and a MCP3221 (which is an ADC). 
 The first 7-bit of the MCP3121 are 0b1001101. I guess the slave address is 0x4D. 
 I developed the following function in order to communication</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 13 Sep 2021 13:00:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79554/i2c-communication-between-a-nrf5240-and-a-mcp3221" /><item><title>RE: I²C communication between a nrf5240 and a MCP3221</title><link>https://devzone.nordicsemi.com/thread/329244?ContentTypeID=1</link><pubDate>Mon, 13 Sep 2021 13:00:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a55349a-3c82-49f0-bb06-4db0d49c33bd</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;In addition to Prasad&amp;#39;s comment I would like to ask: are you checking the error codes returned by I2C_register_read?&lt;br /&gt;The error codes returned by SDK functions should always be checked, for example by passing them to an APP_ERROR_CHECK.&lt;br /&gt;Are you getting any non-NRF_SUCCESS errors from either call to nrf_drv_twi_tx or nrf_drv_twi_rx? If so, which one?&lt;br /&gt;&lt;br /&gt;You should also try to run &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/twi_scanner_example.html"&gt;the TWI Scanner example from the SDK&lt;/a&gt;&amp;nbsp;to verify that your hardware connections is correct. The example will scan through all devices on the TWI bus and report any found devices in the log. If all your hardware connections are correct and the TWI Slave is operating as intended it will be found here.&lt;br /&gt;&lt;br /&gt;Please also make sure that you have DEBUG defined in your preprocessor defines, like shown in the included image.&lt;br /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/6646.enabling_5F00_debug_5F00_SES.PNG" /&gt;&lt;br /&gt;This will make a detailed error message be output by your logger in the case that a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK.&lt;br /&gt;&lt;br /&gt;For future reference, please use the&amp;nbsp;&lt;em&gt;Insert -&amp;gt; Code&amp;nbsp;&lt;/em&gt;option when sharing code here on DevZone.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I²C communication between a nrf5240 and a MCP3221</title><link>https://devzone.nordicsemi.com/thread/329114?ContentTypeID=1</link><pubDate>Sun, 12 Sep 2021 20:59:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d730484e-e14e-4b32-aa06-e5a7476f8eaf</guid><dc:creator>Prasad</dc:creator><description>&lt;p&gt;From the MCP3121 datasheet, &amp;quot;The eighth bit of the slave address determines if the&amp;nbsp;master device wants to read conversion data or write to&amp;nbsp;the MCP3021. When set to a 1, a read operation is&amp;nbsp;selected. When set to a 0, a write operation is selected.&amp;nbsp;There are no writable registers on the MCP3021, therefore,&amp;nbsp;this bit must be set to a 1 to initiate a conversion.&amp;quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote userid="108107" url="~/f/nordic-q-a/79554/i2c-communication-between-a-nrf5240-and-a-mcp3221"]ret_code = nrf_drv_twi_rx(p_twi_master,slave_addr, pdata, bytes);[/quote]
&lt;p&gt;should be sufficient.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>