<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=4&amp;t=17079&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2016-12-15T21:46:24+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=17079&amp;mode</id>
<entry>
<author><name><![CDATA[Jatsekku]]></name></author>
<updated>2016-12-15T21:46:24+01:00</updated>
<published>2016-12-15T21:46:24+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=17079&amp;p=177604#p177604</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=17079&amp;p=177604#p177604"/>
<title type="html"><![CDATA[SPI - odczyt, zapis, transfer]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=17079&amp;p=177604#p177604"><![CDATA[
Witam, <br />Mam pewną zagwozdkę. Mam sobie takie 3 funkcje:<br />[syntax=c]#if USE_HW_SPI_SEND_BYTE == 1<br />void SPI_HwSendByte(uint8_t SPI_byte)<br />{<br />SPDR = SPI_byte;<br />while(!(SPSR &amp; (1&lt;&lt;SPIF)));<br />}<br />#endif<br /><br />#if USE_HW_SPI_RECEIVE_BYTE == 1<br />uint8_t SPI_HwReceiveByte(void)<br />{<br />while(!(SPSR &amp; (1&lt;&lt;SPIF)));<br />return SPDR;<br />}<br />#endif<br /><br />#if USE_HW_SPI_TRANSFER_BYTE == 1<br />uint8_t SPI_HwTransferByte(uint8_t SPI_byte)<br />{<br />SPDR = SPI_byte;<br />while(!(SPSR &amp; (1&lt;&lt;SPIF)));<br />return SPDR;<br />}<br />#endif[/syntax]<br /><br />I teraz pytanie czy transmisje do nRF'a lepiej realizować tak:<br /><br />[syntax=c]uint8_t nRF_ReceiveByte(uint8_t nRF_register)<br />{<br />register uint8_t nRF_data;<br />nRF_CSN_LOW;<br />SPI_SendByte(nRF_register);<br />nRF_data = SPI_ReceiveByte();<br />nRF_CSN_HIGH;<br />return nRF_data;<br />}<br /><br />void nRF_SendByte(uint8_t nRF_register, uint8_t nRF_data)<br />{<br />nRF_CSN_LOW;<br />SPI_SendByte(nRF_register);<br />SPI_SendByte(nRF_data);<br />nRF_CSN_HIGH;<br />}[/syntax]<br /><br />czy tak:<br /><br />[syntax=c]uint8_t nRF_ReceiveByte(uint8_t nRF_register)<br />{<br />register uint8_t nRF_data;<br />nRF_CSN_LOW;<br />SPI_TransferByte(nRF_register);<br />nRF_data = SPI_TransferByte(0xFF);<br />nRF_CSN_HIGH;<br />return nRF_data;<br />}<br /><br />void nRF_SendByte(uint8_t nRF_register, uint8_t nRF_data)<br />{<br />nRF_CSN_LOW;<br />SPI_TransferByte(nRF_register);<br />SPI_TransferByte(nRF_data);<br />nRF_CSN_HIGH;<br />}[/syntax]<br /><br />2 opcja pozwala mi na wyeliminowanie dwóch funkcji, lecz zastanawiam się czy funkcja SPI_TransferByte nie wykonuje się dłużej niż np SPI_SendByte. Czasem zależy mi tylko na odczycie, czasem tylko na zapisie, ale mam też funkcje, która wykonuje obydwie operacje. I nie wiem czy lepiej kosztem zaoszczędzenia miejsca zrezygnować z w/w funkcji.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3920">Jatsekku</a> — 15 gru 2016, o 21:46</p><hr />
]]></content>
</entry>
</feed>