<?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>Getting started with SPI</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/34003/getting-started-with-spi</link><description>Hello. I have a nRF52832 DK and I&amp;#39;m trying to modify the SPI example code found here: 
 /nRF5_SDK_15.0.0/nRF5_SDK_15.0.0_a53641a/examples/peripheral/spi 
 I&amp;#39;m using the nRF52832 DK as the master and a digital potentiometer (MCP4131) as the slave, and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 07 May 2018 09:06:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/34003/getting-started-with-spi" /><item><title>RE: Getting started with SPI</title><link>https://devzone.nordicsemi.com/thread/131150?ContentTypeID=1</link><pubDate>Mon, 07 May 2018 09:06:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c38ed2f-acff-43dc-99cc-99e7b7d9a504</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Hey Payton,&lt;/p&gt;
&lt;p&gt;I was convinced that we were talking about UART for some reason, but now I realize it&amp;#39;s SPI.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;We&amp;#39;re gonna start by reading the status register:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint16_t MOSI; //TX buffer
uint16_t MISO; //RX buffer

MOSI = 0b0101111111111111; //4 bits address (0x5) + 2 control bits (0x3=read) +    \
//10 bits data. 
//The data bits on MOSI are called the Over Read Character and is used to let the  \
//slave continue to send even though the master has sent want it needs for the     \
//current transfer. Most SPI slaves needs an ORC of 0xFF/0b11111111 to function    \
//properly.

//After the transfer is complete you need to extract the data bits out of MISO:
uint16_t DATA = MISO &amp;amp; 0b0000001111111111; // The mask of actual data bits. 

------------------------------------------------------------------------------------
To make things more readable you can do the following:
# define DATA_MSK 0b0000001111111111 
// Now you can extract the bits in a more human-readable form
uint16_t DATA = MISO &amp;amp; DATA_MSK;

More advanced:
#define WIPER0_ADDR 0x00 
#define TCON_ADDR   0x04
#define STATUS_ADDR 0x05

#define WRITE_CMD   0x00
#define INCR_CMD    0x01
#define DECR_CMD    0x02
#define READ_CMD    0x03

#define ADDR_POS    12
#define CMD_POS     10

uint16_t encode_tx_buffer(uint8_t addr, uint8_t cmd)
{
    return ((addr &amp;lt;&amp;lt; ADDR_POS)|(cmd &amp;lt;&amp;lt; CMD_POS) | DATA_MSK);
}
// To read the status register now:
uint16_t MOSI = encode_tx_buffer(STATUS_ADDR, READ_CMD); 
// Should be equal to 0b0101111111111111. &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I wrote&amp;nbsp;the code in this text editor so there might be some unwanted &amp;quot;features&amp;quot; present, just a heads-up.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Håkon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting started with SPI</title><link>https://devzone.nordicsemi.com/thread/131103?ContentTypeID=1</link><pubDate>Sun, 06 May 2018 19:11:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:35607f82-b159-4e7a-8528-d075c82f3663</guid><dc:creator>Payton Grenich</dc:creator><description>&lt;p&gt;Thanks for the response! No error is given because&amp;nbsp;a variable&amp;nbsp;in quotes is seen as a string and saved as ASCII in the register, similar to how &amp;quot;Nordic&amp;quot; is saved (apologies, I should have said &amp;quot;various issues&amp;quot; not &amp;quot;various errors&amp;quot;). Replacing &amp;quot;Nordic&amp;quot; with &amp;quot;0x80&amp;quot; in the code sends the ASCII &amp;#39;version&amp;#39; of 0x80 on MOSI. ie, using&amp;nbsp;&lt;a href="https://www.rapidtables.com/convert/number/ascii-to-binary.html"&gt;a conversion tool&lt;/a&gt;, one can see that 0x80 is saved as&amp;nbsp;00110000 01111000 00111000 00110000 0001010. This binary value is exactly what is transmitted on MOSI, as I can see from using an oscilloscope. My issue is that some 8-bit binary values cannot be accessed by ASCII characters (eg, see binary values 10000000-10011111 on an &lt;a href="https://www.rapidtables.com/code/text/ascii-table.html"&gt;extended ASCII table&lt;/a&gt;). So basically I need a way to save these and other values to&amp;nbsp;&lt;span&gt;static uint8_t m_tx_buf[] without using quotes and strings.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting started with SPI</title><link>https://devzone.nordicsemi.com/thread/130963?ContentTypeID=1</link><pubDate>Fri, 04 May 2018 08:54:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:992323ef-e291-4c69-ac01-51805553477a</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Hey Payton,&lt;/p&gt;
[quote user=""]I&amp;#39;ve tried modifying the value of TEST_STRING from &amp;quot;Nordic&amp;quot; to various hexadecimal formats such as 0x80, %80x, 0X80, &amp;quot;0x80&amp;quot;, etc. but I get&amp;nbsp;various errors when I try to do this.[/quote]
&lt;p&gt;What error do you get when you replace &amp;quot;Nordic&amp;quot; with &amp;quot;0x80&amp;quot; ?&lt;/p&gt;
&lt;p&gt;Also I suggest you try Segger Embedded Studio for any embedded development with our devices as we do not support Netbeans in our SDK.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Håkon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>