<?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>Result of spi_transceive() isn&amp;#39;t correct</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103136/result-of-spi_transceive-isn-t-correct</link><description>I write the following code to read WHO_AM_I register of ST LIS2DH12 G-sensor. But result is incorrect. That is result is 0xFF but it should be 0x33. 
 
 The following are log messages of RTT Viewer. 
 
 Procedures to reproduce this issue are as follows</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 25 Aug 2023 04:37:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103136/result-of-spi_transceive-isn-t-correct" /><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443081?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 04:37:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92d342e9-a23c-4452-8ff2-325011c1b6cb</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/8233.custom_5F00_nrf52832.zip"&gt;devzone.nordicsemi.com/.../8233.custom_5F00_nrf52832.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443080?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 04:36:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f3191b8-35c1-425f-9757-ba688a59a347</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0763.minimal_5F00_log_5F00_gsensor.zip"&gt;devzone.nordicsemi.com/.../0763.minimal_5F00_log_5F00_gsensor.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443079?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 04:36:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f6df711-4827-4e86-9146-86f9d8e877ad</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/spitiming.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443078?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 04:33:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57ef3c1d-7fd0-4a41-8d97-43d3426591f0</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;Thanks for your great support! I can read WHO_AM_I register successfully after changed _lis2dh12RegRead() as follows.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static int _lis2dh12RegRead(const uint8_t regAddr, uint8_t* regVal) {
    int ret;
    uint8_t txBuf[1] = { regAddr | LIS2DH12_REG_READ_MSK };

    const struct spi_buf txSpiBuf = {
        .buf = txBuf,
        .len = sizeof(txBuf)
    };

    const struct spi_buf_set txSpiBufSet = {
        .buffers = &amp;amp;txSpiBuf,
        .count   = 1
    };

    uint8_t rxBuf[2];
    struct spi_buf rxSpiBuf = {
        .buf = rxBuf,
        .len = sizeof(rxBuf)
    };
    const struct spi_buf_set rxSpiBufSet = { .buffers = &amp;amp;rxSpiBuf, .count = 1 };
    ret = spi_transceive(_gSpiDev, &amp;amp;_gSpiCfg, &amp;amp;txSpiBufSet, &amp;amp;rxSpiBufSet);
    if (ret &amp;lt; 0) {
        printk(&amp;quot;Reading LIS2DH12 register failed, regAddr=0x%x, err=%d\n&amp;quot;, regAddr, ret);
        return ERROR_GSENSOR_READ_FAIL;
    }

    *regVal = rxBuf[1];

    return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;00&amp;gt; *** Booting Zephyr OS build v3.3.99-ncs1 ***
00&amp;gt; Starting gsensor test
00&amp;gt; Starting button Test example
00&amp;gt; device_is_ready() ok
00&amp;gt; gpio_pin_configure_dt() ok
00&amp;gt; gpio_pin_interrupt_configure_dt() ok
00&amp;gt; Set up button at gpio@50000000 pin 27
00&amp;gt; button state=1
00&amp;gt; start a timer
00&amp;gt; now-1-11-30 0:0:0
00&amp;gt; 0
00&amp;gt; lis2dh12 device is ready!
00&amp;gt; LIS2DH12 ID check ok, id=0x33
00&amp;gt; lis2dh12 ID check pass!&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443074?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 03:30:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7820f7aa-8ea5-4e4d-9d90-518e654c62b8</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I didn&amp;#39;t bother reading anything but this snippet (feeling lazy) but to read the LIS12DH12 whoami response 2 Rx bytes are required not just 1 byte: Change&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint8_t rxBuf[1];&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint8_t rxBuf[2];&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;and make sure the expected receive length is set to 2 not 1. Be aware the &amp;quot;I am LIS2DH12&amp;quot; response is in&amp;nbsp;rxBuf[1] not&amp;nbsp;rxBuf[0]. rxBuff[0] is a dummy byte clocked out while the command byte is being sent; until the LIS2DH12 receives that command byte it can&amp;#39;t respond with Iam as it doesn&amp;#39;t know what the command is until the command has been received.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443068?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 01:58:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d915c68e-e473-44f8-a33e-27deb774bb72</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/1715.cs.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443066?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 01:42:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:938ed28a-4641-4b9a-9e70-8564b087c815</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/gsensor.c"&gt;devzone.nordicsemi.com/.../gsensor.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443064?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 01:22:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b99355d9-5a51-47dc-9a60-3ba326f5e4e5</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/custom_5F00_nrf52832.overlay"&gt;devzone.nordicsemi.com/.../custom_5F00_nrf52832.overlay&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443061?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 01:10:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f04b609-7e8c-4dde-8d46-9b3ebd749876</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/1172.custom_5F00_nrf52832.zip"&gt;devzone.nordicsemi.com/.../1172.custom_5F00_nrf52832.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443060?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 01:09:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09a5ddae-3dee-452d-8b39-dbdf0368eeb2</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/3312.minimal_5F00_log_5F00_gsensor.zip"&gt;devzone.nordicsemi.com/.../3312.minimal_5F00_log_5F00_gsensor.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443059?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 00:57:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db1249a9-95bb-46b9-99dc-97fe1ce75861</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/6201.zephyr.dts"&gt;devzone.nordicsemi.com/.../6201.zephyr.dts&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/443058?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2023 00:57:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14e91dc6-9907-4785-a268-e19ad632ad5a</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;Thanks for your reply! I have uploaded &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/6201.zephyr.dts"&gt;zephyr.dts&lt;/a&gt; file. And I have three questions.&lt;/p&gt;
&lt;p&gt;1. I found cs-gpios = &amp;lt; &amp;amp;gpio0 0xf 0x1 &amp;gt;; in gsspi device node and interrupts = &amp;lt; 0xf 0x1 &amp;gt;; in ccm device node of zephyr.dts file. Does it mean pin 0xf conflict?&lt;/p&gt;
&lt;p&gt;2. I have specified cs-gpios = &amp;lt;&amp;amp;gpio0 15 GPIO_ACTIVE_LOW&amp;gt;; in gsspi device node. Why cs-gpios = &amp;lt; &amp;amp;gpio0 0xf 0x1 &amp;gt;; in gsspi device node of zephyr.dts file? Does 0x1 means active low? How can I change GPIO_ACTIVE_LOW mapping to 0x0? From p9 of &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/lis2dh12.pdf"&gt;lis2dh12.pdf&lt;/a&gt;, it should be 0x0 for SPI communication mode.&lt;/p&gt;
&lt;p&gt;3. I can&amp;#39;t find pinctrl of &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/custom_5F00_nrf52832.overlay"&gt;custom_nrf52832.overlay&lt;/a&gt; in &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/6201.zephyr.dts"&gt;zephyr.dts&lt;/a&gt; file. Which file can I check for pinctrl of custom_nrf52832.overlay?&lt;/p&gt;
&lt;p&gt;4. spim_cs of &lt;a class="ui-tip filename" title="Download gsensor.c" href="https://devzone.nordicsemi.com/cfs-filesystemfile/__key/communityserver-discussions-components-files/4/gsensor.c?_=638285245777157805"&gt;gsensor.c&lt;/a&gt; specified GPIO pin used by SPI chip select. How can I make sure it get correct GPIO pin for SPI chip select?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;struct spi_cs_control spim_cs = {
    .gpio = SPI_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(reg_gsspi)),
    .delay = 0,
};

static const struct spi_config _gSpiCfg = {
    .operation = SPI_WORD_SET(8)  |
                 SPI_TRANSFER_MSB |
                 SPI_MODE_CPOL    |
                 SPI_MODE_CPHA,
    .frequency = 8000000,
    .slave = 0,
    .cs = &amp;amp;spim_cs,
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        spi1: gsspi: spi@40004000 {
			compatible = &amp;quot;nordic,nrf-spi&amp;quot;;
			#address-cells = &amp;lt; 0x1 &amp;gt;;
			#size-cells = &amp;lt; 0x0 &amp;gt;;
			reg = &amp;lt; 0x40004000 0x1000 &amp;gt;;
			interrupts = &amp;lt; 0x4 0x1 &amp;gt;;
			max-frequency = &amp;lt; 0x7a1200 &amp;gt;;
			easydma-maxcnt-bits = &amp;lt; 0x8 &amp;gt;;
			status = &amp;quot;okay&amp;quot;;
			pinctrl-0 = &amp;lt; &amp;amp;spi1_default &amp;gt;;
			pinctrl-1 = &amp;lt; &amp;amp;spi1_sleep &amp;gt;;
			pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;
			cs-gpios = &amp;lt; &amp;amp;gpio0 0xf 0x1 &amp;gt;;
			reg_gsspi: spi-dev-a@0 {
				reg = &amp;lt; 0x0 &amp;gt;;
			};
		};
		ccm: ccm@4000f000 {
			compatible = &amp;quot;nordic,nrf-ccm&amp;quot;;
			reg = &amp;lt; 0x4000f000 0x1000 &amp;gt;;
			interrupts = &amp;lt; 0xf 0x1 &amp;gt;;
			length-field-length-8-bits;
			status = &amp;quot;okay&amp;quot;;
		};&lt;/pre&gt;&lt;pre class="ui-code" data-mode="text"&gt;gsspi: &amp;amp;spi1 {
    compatible = &amp;quot;nordic,nrf-spi&amp;quot;;
    status = &amp;quot;okay&amp;quot;;
    pinctrl-0 = &amp;lt;&amp;amp;spi1_default&amp;gt;;
    pinctrl-1 = &amp;lt;&amp;amp;spi1_sleep&amp;gt;;
    pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;
    cs-gpios = &amp;lt;&amp;amp;gpio0 15 GPIO_ACTIVE_LOW&amp;gt;;
    reg_gsspi: spi-dev-a@0 {
        reg = &amp;lt;0&amp;gt;;
    };
};&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/442959?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2023 11:38:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a63e6f92-c9fb-47f6-b7d4-203196955cd7</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Might be some overlapping GPIO assignment to different peripherals.&lt;/p&gt;
&lt;p&gt;Can you upload the compiled DTS file (found in&amp;nbsp;build\zephyr\zephyr.dts)?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/442933?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2023 10:24:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9510065-ce0b-4e70-b833-bcf13329b7c8</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/4431.custom_5F00_nrf52832.zip"&gt;devzone.nordicsemi.com/.../4431.custom_5F00_nrf52832.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/442931?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2023 10:23:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f01a3e65-b61c-4cd1-b1fd-3376887db37c</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/minimal_5F00_log_5F00_gsensor.zip"&gt;devzone.nordicsemi.com/.../minimal_5F00_log_5F00_gsensor.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/442930?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2023 10:22:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07405c75-2d10-427b-bc23-cb4a9189cbda</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/lis2dh12.pdf"&gt;devzone.nordicsemi.com/.../lis2dh12.pdf&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Result of spi_transceive() isn't correct</title><link>https://devzone.nordicsemi.com/thread/442929?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2023 10:22:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86cf0238-6ab4-45a1-ad82-8aeb1197e4ae</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/8055.whoami.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>