<?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>How to send 1 byte via SPI from master to slave</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/21828/how-to-send-1-byte-via-spi-from-master-to-slave</link><description>Hello everyone, I&amp;#39;m trying to run my nrf51 with ADS1298 using SPI. nrf51 is master and ADS1298 is slave. 
 I configured SPI as 
 const nrf_drv_spi_config_t spi_config =
 {
 .sck_pin = 25,
 .mosi_pin = 24,
 .miso_pin = 23,
 .ss_pin = 30,
 //.irq_pin</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 29 Jun 2018 14:38:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/21828/how-to-send-1-byte-via-spi-from-master-to-slave" /><item><title>RE: How to send 1 byte via SPI from master to slave</title><link>https://devzone.nordicsemi.com/thread/138309?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 14:38:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df6e8ce9-e9c8-4138-9b05-48d9e6c9aa96</guid><dc:creator>IlyaM</dc:creator><description>&lt;p&gt;Use uint8_t instead of or&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send 1 byte via SPI from master to slave</title><link>https://devzone.nordicsemi.com/thread/138256?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 11:22:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5a10b3c-12fc-4c46-a107-e82831618174</guid><dc:creator>Markus Aerni</dc:creator><description>&lt;p&gt;i had this problem too&lt;/p&gt;
&lt;p&gt;if i enter the code like mentioned:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;nrf_drv_spi_transfer(&amp;amp;spi, 0x11, 1, NULL, 1);&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;i get the following error:&lt;/p&gt;
&lt;p&gt;Main.c(96): error: #167: argument of type &amp;quot;int&amp;quot; is incompatible with parameter of type &amp;quot;const uint8_t *&amp;quot;&lt;br /&gt; nrf_drv_spi_transfer(&amp;amp;spi, 0x11, 1, NULL, 1);&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send 1 byte via SPI from master to slave</title><link>https://devzone.nordicsemi.com/thread/85738?ContentTypeID=1</link><pubDate>Fri, 05 May 2017 13:34:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ea37ef5-8aeb-4d00-af6d-73c18a2cdeaf</guid><dc:creator>IlyaM</dc:creator><description>&lt;p&gt;thank you! Hope it helps&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send 1 byte via SPI from master to slave</title><link>https://devzone.nordicsemi.com/thread/85737?ContentTypeID=1</link><pubDate>Fri, 05 May 2017 13:03:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:89990e24-d953-48c0-8152-78fcd1e558f5</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Then you&amp;#39;ll have to use the last approach,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, 0x11, 1, NULL, 1));
APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, 0x20 | 0x00, 1, NULL, 1));
APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, 0x00, 1, rx_buf, 1));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;with nrf_delay_ms(5) in between the calls.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send 1 byte via SPI from master to slave</title><link>https://devzone.nordicsemi.com/thread/85736?ContentTypeID=1</link><pubDate>Fri, 05 May 2017 12:28:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:673d4deb-4e83-478c-bfa3-a712acd3f2fb</guid><dc:creator>IlyaM</dc:creator><description>&lt;p&gt;Yes, about 5ms.
From data sheet: &amp;quot;The ADS129x serial interface decodes commands in bytes, and requires 4 tCLK periods to decode and execute. Therefore, when sending multibyte commands, a 4 tCLK period must separate the end of one byte (or opcode) and the next.&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send 1 byte via SPI from master to slave</title><link>https://devzone.nordicsemi.com/thread/85735?ContentTypeID=1</link><pubDate>Fri, 05 May 2017 11:05:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1c62af7-d96a-4eea-9c5b-44155f59f191</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;No, the buffer length wil be ignored if the rx buffer pointer is NULL. Does it have to be exactly 5 microseconds between the transfers?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send 1 byte via SPI from master to slave</title><link>https://devzone.nordicsemi.com/thread/85734?ContentTypeID=1</link><pubDate>Fri, 05 May 2017 09:03:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:562439bf-e4ff-43d2-bce4-671ce97e9a95</guid><dc:creator>IlyaM</dc:creator><description>&lt;p&gt;Thanks for your reply. I found the solution of pin changes in examples of SDK.&lt;/p&gt;
&lt;p&gt;So, about SPI, yes I need to send some data without receiving from MISO&lt;/p&gt;
&lt;p&gt;According to your answer it looks like&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, &amp;amp;SDATAC, 1, NULL, 1));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Do I need to change rx_buffer_length to 0?&lt;/p&gt;
&lt;p&gt;So and how to implement the arduino code when I send each 1 byte after delay?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int out = 0;
digitalWrite(IPIN_CS, LOW);
SPI.transfer(0x20 | 0x00);
delayMicroseconds(5);
SPI.transfer(0);    // number of registers to be read/written – 1
delayMicroseconds(5);
out = SPI.transfer(0);
delayMicroseconds(1);
digitalWrite(IPIN_CS, HIGH);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What is the best way send like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint8_t tx[3] = {0x11, 0x20 | 0x00, 0x00};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, 0x11, 1, NULL, 1));
APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, 0x20 | 0x00, 1, NULL, 1));
APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, 0x00, 1, rx_buf, 1));
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send 1 byte via SPI from master to slave</title><link>https://devzone.nordicsemi.com/thread/85733?ContentTypeID=1</link><pubDate>Fri, 05 May 2017 08:43:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8400d552-6ef4-434d-9d24-ab038230de18</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;What is m_length set to? If you only want to send 1 byte then you have to set the rx_buffer_length 1 or p_rx_buffer to NULL if you do not need to receive any data.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, &amp;amp;SDATAC, 1, m_rx_buf, 1));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Otherwise you will just clock out &amp;quot;garbage data&amp;quot;. As for the pin read issue, I would recommend setting up the gpiote peripheral to generate an interrupt whenever there is a level change on the pin, like the pin_change_int example in the SDK.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_drv_gpiote.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;

#define PIN_OUT 8
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    nrf_drv_gpiote_out_toggle(PIN_OUT);
}
/**
 * @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output, 
 * and configures GPIOTE to give an interrupt on pin change.
 */
static void gpio_init(void)
{
    ret_code_t err_code;

    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);

    err_code = nrf_drv_gpiote_out_init(PIN_OUT, &amp;amp;out_config);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    in_config.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(PIN_IN, &amp;amp;in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(PIN_IN, true);
}

/**
 * @brief Function for application main entry.
 */
int main(void)
{
    gpio_init();

    while (true)
    {
        // Do nothing.
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>