<?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>Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/29253/using-the-spi-example-to-communicate-with-a-cr95hf</link><description>Good evening all,
I&amp;#39;m trying to get my DK52 communicating with a CR95HF (this is a NFC controller with serial and SPI control interfaces), I&amp;#39;m using a breakout board - BM019 
The CR95 requires a setup sequence to select the SPI interface
 
 So far</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 23 May 2018 07:30:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/29253/using-the-spi-example-to-communicate-with-a-cr95hf" /><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/132887?ContentTypeID=1</link><pubDate>Wed, 23 May 2018 07:30:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ce057a7-623f-47b9-b747-42007cde0006</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Please post your question in a new thread. You can link to this question and say it is related, but answering in this thread will make it harder for other users to find the information if they experience similar issues.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/132867?ContentTypeID=1</link><pubDate>Wed, 23 May 2018 06:36:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97ce53e7-07b4-42f3-9842-40650d3a4b8b</guid><dc:creator>eduardoescarti</dc:creator><description>&lt;p&gt;Hi I mistakenly replied to PaulP but maybe you can help me as well :) . Please see bottom most reply. Thanks a lot!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/132757?ContentTypeID=1</link><pubDate>Tue, 22 May 2018 12:23:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46d5ec1c-e019-418f-ac78-ea0211e228b3</guid><dc:creator>eduardoescarti</dc:creator><description>&lt;p&gt;Hi all! I am having exactly the same issue and don&amp;#39;t know how to continue. I have also spend 2 days with this.&lt;br /&gt;&lt;br /&gt;I&amp;#39;m using SDK 15.0&amp;nbsp;&lt;br /&gt;&lt;br /&gt;My SPI config is as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = NRF_SPI_PIN_NOT_CONNECTED;
    spi_config.miso_pin = SPI_MISO_PIN;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.sck_pin  = SPI_SCK_PIN;
    spi_config.orc      = 0xFF;
    spi_config.mode      = NRF_DRV_SPI_MODE_0;
    spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
    spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
    
    APP_ERROR_CHECK(nrf_drv_spi_init(&amp;amp;m_spi_master_0, &amp;amp;spi_config, spi_event_handler, NULL));
    
    nrf_gpio_pin_set(IRQ_PIN);
    nrf_gpio_pin_set(SPI_SS_PIN);

   // CR95HF Wake-Up Pulse
   nrf_delay_ms(10);                        // send a wake up
   nrf_gpio_pin_clear(IRQ_PIN);      // pulse to put the
   nrf_delay_us(100);   
   nrf_gpio_pin_set(IRQ_PIN);     // mode
   nrf_delay_ms(10); &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I know it might be overkill configuring SS manually but I&amp;#39;m porting code from arduino and it is done like that over there.&lt;br /&gt;&lt;br /&gt;The CR95HF SPI works in 3 steps:&lt;br /&gt;1. send command&lt;br /&gt;2. poll with 0x03 until SPI return bit 4 to 1&lt;br /&gt;3. send command 0x02 to read&lt;br /&gt;&lt;br /&gt;The corresponding arduino code of step 1 and 2 is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// step 1 send the command
  digitalWrite(SSPin, LOW);
  SPI.transfer(0x00);  // SPI control byte to send command to CR95HF
  SPI.transfer(0x02);  // Set protocol command
  SPI.transfer(0x02);  // length of data to follow
  SPI.transfer(0x01);  // code for ISO/IEC 15693
  SPI.transfer(0x0D);  // Wait for SOF, 10% modulation, append CRC
  digitalWrite(SSPin, HIGH);
  delay(1);
 
// step 2, poll for data ready

  digitalWrite(SSPin, LOW);
  while(RXBuffer[0] != 8)
    {
    RXBuffer[0] = SPI.transfer(0x03);  // Write 3 until
    RXBuffer[0] = RXBuffer[0] &amp;amp; 0x08;  // bit 3 is set
    }
  digitalWrite(SSPin, HIGH);
  delay(1);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So my ported code looks like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint8_t invcommand[5] = {0x00, 0x02, 0x02, 0x01,0x0D};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrf_gpio_pin_clear(SPI_SS_PIN);
spi_xfer_done = false;
APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;m_spi_master_0, &amp;amp;invcommand, 5, m_rx_buf, 5));
while (!spi_xfer_done)
{
  __WFE();
}
nrf_gpio_pin_set(SPI_SS_PIN);
nrf_delay_ms(1);

nrf_gpio_pin_clear(SPI_SS_PIN);        
while(m_rx_buf[0] != 8) {
  spi_xfer_done = false;
  m_tx_buf[0] = 0x03;
  APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;m_spi_master_0, m_tx_buf, 1, m_rx_buf, 1));
  while (!spi_xfer_done)
  {
    __WFE();
  }
  
  m_rx_buf[0] = m_rx_buf[0] &amp;amp; 0x08;
}
nrf_gpio_pin_set(SPI_SS_PIN);
nrf_delay_ms(1);
        &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But it never gets out of the STEP 2 while loop and the SPI keeps returning 0x06&lt;/p&gt;
&lt;p&gt;I&amp;#39;m hoping to get my hands on a logic analyser and see how the signals on arduino vs&amp;nbsp;&lt;span&gt;DK52&lt;/span&gt; look like.&lt;/p&gt;
&lt;p&gt;As for the sdk_config.h SPI data:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;NRFX_SPIM_ENABLED 1
NRFX_SPI_ENABLED 1
SPI_ENABLED 1
SPI0_ENABLED 1
SPI0_USE_EASY_DMA 1
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/116377?ContentTypeID=1</link><pubDate>Mon, 22 Jan 2018 23:27:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f646861-e564-4bf8-bca6-751a228289b3</guid><dc:creator>PaulP</dc:creator><description>&lt;p&gt;Hi, I thought I should come back and close this off!&lt;/p&gt;
&lt;p&gt;So after much faffing around I finally got the thing working! As expected user error was the major cause of issues.&lt;/p&gt;
&lt;p&gt;#1) User error - I misunderstood the data sheet - it said that the echo command only had one bit (0x55), that&amp;#39;s true, but you also need the control byte (0x00), then poll for answer as all other commands.&lt;/p&gt;
&lt;p&gt;#2) More user error - general messing about with things whilst fault finding.&lt;/p&gt;
&lt;p&gt;#3) ...Probably more user error, but changing the character used to clock stuff out of the CR95HF via SPI from 0xFF to 0x00 fixed 99% of the issues.&lt;/p&gt;
&lt;p&gt;Thanks again for your support :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/116373?ContentTypeID=1</link><pubDate>Fri, 12 Jan 2018 15:07:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f02b309-efcf-4e71-82b5-e9c3291c5f35</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;From the BM019 datasheet: &lt;em&gt;The SPI operates using Mode 0: clock is idle low and data shifted on the falling edge.&lt;/em&gt; From the CR95 datasheet, the SPI protocol expects a control byte at the start of every transfer. When sending a command, this seems to be 0x00:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/CR95_5F00_format.png" alt="image description" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/116376?ContentTypeID=1</link><pubDate>Thu, 11 Jan 2018 17:23:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e33b3c4-c6f9-4427-81db-0ee718e1ad19</guid><dc:creator>PaulP</dc:creator><description>&lt;p&gt;Changing modes made no difference - modes 0 and 3 worked the same, I read that both these modes are supported can&amp;#39;t find where  tho, (I have it in mode 0).
Modes 1 and 2 gave even more random results.... still with all zeros in the first half of each byte.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/116375?ContentTypeID=1</link><pubDate>Thu, 11 Jan 2018 13:23:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58aa46c8-cdd8-4232-9244-2588f5e5536d</guid><dc:creator>PaulP</dc:creator><description>&lt;p&gt;Sometimes when chasing a fault you end up down the wrong path... but..&lt;/p&gt;
&lt;p&gt;I was staring at the terminal window of crap data and noticed that all the first nibbles returned where zero, then I realised that the commands that have worked have all only required 0&amp;#39;s in the first nibbles (of each byte).
I don&amp;#39;t know what if anything this means, I have tried different SPI modes before... but I will try them again later, but can you think of any other reason for this... or am I just making things up now?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/116374?ContentTypeID=1</link><pubDate>Thu, 11 Jan 2018 12:30:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eda53770-ac16-4153-8998-8013d6d6fdae</guid><dc:creator>PaulP</dc:creator><description>&lt;p&gt;Hi Jørgen,&lt;/p&gt;
&lt;p&gt;Thanks for your continued support!&lt;/p&gt;
&lt;p&gt;I was making no progress so decided to take a step back for a few days.&lt;/p&gt;
&lt;p&gt;When re investigating I put together a test using a AVR and Arduino code, It worked reading data from a Tag, So I tried the Echo command in Arduino - it Failed!
At this point I decided to try a more complicated command on the nFR (Set Protocol)... It worked!!!
However sadly the next command failed (doing inventory).
I then tried the IDN command (it should return basic information about the CR95) - it sorta worked! - for example it returns:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;quot;00 0F&amp;quot; &amp;quot;00 00 00 00 00 00 00 00 03 06 07 07 03&amp;quot; 06 00
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And not something more like: (per the data sheet)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;quot;00 0F&amp;quot; 4E 46 43 20 46 53 32 4A 41 53 54 34 00&amp;quot; 2A CE
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Above you can see the first two bytes seem OK cmd-result and length of data returned.
Then the next 13 Bytes should be some ASCII text (it&amp;#39;s not - mostly zeros) then the checksum.. could be correct I don&amp;#39;t know!&lt;/p&gt;
&lt;p&gt;So very strange results - unless you have any more suggestions I think I&amp;#39;ll try and find some ST help :(&lt;/p&gt;
&lt;p&gt;Thanks again for your support.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/116372?ContentTypeID=1</link><pubDate>Tue, 09 Jan 2018 14:54:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fd2fcdd-d7ed-4180-9bfd-fca170bb1448</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Could you test with this spi_event_handler?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                       void *                    p_context)
{
    spi_xfer_done = true;
    NRF_LOG_INFO(&amp;quot;Transfer completed.&amp;quot;);
    NRF_LOG_INFO(&amp;quot; Received:&amp;quot;);
    NRF_LOG_HEXDUMP_INFO(p_event-&amp;gt;data.done.p_rx_buffer, p_event-&amp;gt;data.done.rx_length);
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/116371?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2018 14:10:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e39480f8-f023-421c-b9f4-1baaacda96eb</guid><dc:creator>PaulP</dc:creator><description>&lt;p&gt;Yup... had tried before..
I added this tho the event handler (above the if statement)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_LOG_INFO(&amp;quot;Not checked&amp;gt;&amp;quot;);
NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My output now looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;info&amp;gt; app: SPI example.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Not checked&amp;gt;
&amp;lt;info&amp;gt; app:  06 06 01               |...     
&amp;lt;info&amp;gt; app:  Received:
&amp;lt;info&amp;gt; app:  06 06 01               |...     
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Not checked&amp;gt;
&amp;lt;info&amp;gt; app:                         |        
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Not checked&amp;gt;
&amp;lt;info&amp;gt; app:                         |        
&amp;lt;info&amp;gt; app: Transfer completed.
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/116370?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2018 13:48:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ef6e4a4-9dc3-4a97-8d3c-858e71006613</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Have you tried removing the checking of the first byte in the callback handler (&lt;code&gt;if (m_rx_buf[0] != 0)&lt;/code&gt;)? You are checking the first byte, but this might actually be 0, as this will depend on what the peripheral clocks out. You seems to be getting multiple transfers where the buffer does not contain 06 in the first byte, but you are not printing the proceding bytes with your code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/116369?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2018 13:47:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9bc95174-853c-4f78-a2c1-47eb810601f1</guid><dc:creator>PaulP</dc:creator><description>&lt;p&gt;Hi Jørgen, Thanks for your answer. I have tried many buffer sizes - I realise the code I quoted ad the wrong value. As you suggest I changed the values - I added this to my declarations:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static const uint8_t m_rx_length = 2;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I changed my spi transfer call to this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, &amp;amp;hexdata, m_length, m_rx_buf, m_rx_length));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So my rx buffer size (and m_rx_length) are &amp;#39;2&amp;#39;. This is my output:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;info&amp;gt; app: SPI example.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app:  Received:
&amp;lt;info&amp;gt; app:  06 06 01               |...     
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see.. another 06! and nothing (or 0x00) on subsequent calls... confusion reigns :(&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the SPI example to communicate with a CR95HF</title><link>https://devzone.nordicsemi.com/thread/116368?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2018 12:28:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a14bea7-eb56-4038-9a97-fa6c94caa0f9</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please have a look at the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/spim.html?cp=2_1_0_30_2#concept_lhv_fx2_wr"&gt;timing diagrams&lt;/a&gt; of the SPI/SPIM peripheral of the nRF52832. When you start a transfer, both TX and RX buffer will be filled on every clocking of the SPI bus. In your code, you have set the length of RX buffer to 1, meaning this buffer will be filled while you transfer the control code to the peripheral (CR95). From the datasheet of CR95, you can see that the response will be sent after the control byte is received. You need to increase the RX buffer to the size of the expected TX+RX bytes, in your test case 2, and ignore the first received byte:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static const uint8_t m_rx_length = m_length + 1;
static uint8_t       m_rx_buf[m_rx_length];
...
void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                       void *                    p_context)
{
    ...
    if (m_rx_buf[1] != 0)
    ...
}

...
int main(void)
{
    ...
    while (1)
    {
        ...
        memset(m_rx_buf, 0, m_rx_length);
        ...
        APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, &amp;amp;hexdata, m_length, m_rx_buf, m_rx_length));
        ...
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>