<?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=30&amp;t=15578&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2016-06-13T19:25:18+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=30&amp;t=15578&amp;mode</id>
<entry>
<author><name><![CDATA[icer_cmg]]></name></author>
<updated>2016-06-13T19:25:18+01:00</updated>
<published>2016-06-13T19:25:18+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15578&amp;p=162175#p162175</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15578&amp;p=162175#p162175"/>
<title type="html"><![CDATA[Re: Uruchomienie ATMega8 Próbuję uruchomić komunikacjz nrf24]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15578&amp;p=162175#p162175"><![CDATA[
Na forum już było:<br /><a href="http://forum.atnel.pl/topic11377.html?hilit=nrf24l01"  class="postlink">http://forum.atnel.pl/topic11377.html?hilit=nrf24l01</a><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1636">icer_cmg</a> — 13 cze 2016, o 19:25</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[fgfd]]></name></author>
<updated>2016-06-13T19:17:25+01:00</updated>
<published>2016-06-13T19:17:25+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15578&amp;p=162173#p162173</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15578&amp;p=162173#p162173"/>
<title type="html"><![CDATA[Uruchomienie ATMega8 Próbuję uruchomić komunikacjz nrf24l01+]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15578&amp;p=162173#p162173"><![CDATA[
Próbuję uruchomić komunikację na modułach nrf24l01+. W tym celu wykorzystałem najpierw 2 Arduino Uno i korzystając z tej strony: <a href="http://blog.nettigo.pl/post/100531579628/modem-radiowy-nrf24l01-programowanie"  class="postlink">http://blog.nettigo.pl/post/100531579628/modem-radiowy-nrf24l01-programowanie</a> udało mi się przesyłać dane. Ostatecznie chcę komunikować się między dwoma AVRami. Teraz chcę aby odbiornik był dalej na Arduino, a nadajnik chcę uruchomić na ATMega8. Korzystam z tego poradnika dla AVRów: <a href="http://gizmosnack.blogspot.com/2013/04/tutorial-nrf24l01-and-avr.html"  class="postlink">http://gizmosnack.blogspot.com/2013/04/tutorial-nrf24l01-and-avr.html</a>. Ustawiłem chyba wszystkie parametry przesyłu na takie same po stronie AVRa i Arduino, jednak transmisja nie chce dojść do skutku. I moja prośba jest taka czy ktoś by mi pomógł rozwiązać ten problem. Może ma ktoś gotowy program na Atmegę8. Sporo szukałem w sieci, jednak nie znalazłem odpowiadających mi informacji.<br /><br />W załączniku znajduje się pełny kod programu AVRa. Projekt w Atmel Studio.<br /><br />Program dla Atmegi8:<br />[syntax=c]#include &lt;avr/io.h&gt;<br />#include &lt;stdio.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br /><br />#include &quot;nRF24L01.h&quot;<br />#include &quot;uart.h&quot;<br /><br />void InitSPI(void)<br />{<br />DDRB |= (1&lt;&lt;DDB5) | (1&lt;&lt;DDB3) | (1&lt;&lt;DDB2) |(1&lt;&lt;DDB1);//ustawienie wyjść<br />SPCR |= (1&lt;&lt;SPE) | (1&lt;&lt;MSTR);//włączanie SPI, jako master<br /><br />SETBIT(PORTB, 2);//CSN IR_High to start with, nothing to be sent to the nRF yet!<br />CLEARBIT(PORTB, 1);//CE low to start with, nothing to send/receive yet!<br />}<br /><br />char WriteByteSPI(unsigned char cData)<br />{<br />SPDR = cData;<br />while(!(SPSR &amp; (1&lt;&lt;SPIF)));//odczekanie na przesłanie danych<br /><br />return SPDR;<br />}<br /><br />uint8_t GetReg(uint8_t reg)<br />{<br />_delay_us(10);//make sure last command was a while ago...<br />CLEARBIT(PORTB, 2); //CSN low - nRF starts to listen for command<br />_delay_us(10);<br />WriteByteSPI(R_REGISTER + reg); //R_Register = set the nRF to reading mode, &quot;reg&quot; = this registry will be read back<br />_delay_us(10);<br />reg = WriteByteSPI(NOP);//Send NOP (dummy byte) once to receive back the first byte in the &quot;reg&quot; register<br />_delay_us(10);<br />SETBIT(PORTB, 2);//CSN Hi - nRF goes back to doing nothing<br />return reg;<br />}<br /><br />uint8_t *WriteToNrf(uint8_t ReadWrite, uint8_t reg, uint8_t *val, uint8_t antVal)<br />{<br />//&quot;ReadWrite&quot; (&quot;W&quot; or &quot;R&quot;), &quot;reg&quot; (the register), &quot;*val&quot; (an array with the package) &amp; &quot;antVal&quot; (number of integers in the package)<br /><br />if (ReadWrite == W) //if &quot;W&quot; then you want to write to the nRF (read mode &quot;R&quot; == 0x00, so skipping that one)<br />{<br />reg = W_REGISTER + reg; // Add the &quot;write&quot; bit to the &quot;reg&quot;<br />}<br /><br />//Create an array to be returned at the end<br />//Static uint8_t is needed to be able to return an array (notice the &quot;*&quot; to the left of the function: *WriteToNrf())<br />static uint8_t ret&#91;32&#93;;<br /><br />_delay_us(10);//make sure last command was a while ago...<br />CLEARBIT(PORTB, 2);//CSN low - nRF starts to listen for command<br />_delay_us(10);<br />WriteByteSPI(reg);//set the nRF to Write or read mode of &quot;reg&quot;<br />_delay_us(10);<br /><br />for(int i=0; i&lt;antVal; i++)<br />{<br />if (ReadWrite == R &amp;&amp; reg != W_TX_PAYLOAD) //Did you want to read a registry?<br />{<br />ret&#91;i&#93;=WriteByteSPI(NOP);//Send dummy bytes to read out the data<br />_delay_us(10);<br />}<br />else<br />{<br />WriteByteSPI(val&#91;i&#93;);//Send the commands to the nRF once at a time<br />_delay_us(10);<br />}<br />}<br />SETBIT(PORTB, 2);//CSN Hi - nRF goes back to doing nothing<br /><br />return ret;//return the array<br />}<br /><br />void nrf24L01_init(void)<br />{<br />_delay_ms(100); //allow radio to reach power down if shut down<br /><br />uint8_t val&#91;5&#93;; //An array av integers to send to the *WriteToNrf function<br /><br />//EN_AA - (enable auto-acknowledgments) - Transmitter gets automatic response from receiver when successful transmission!<br />//Only works if Transmitter has identical RF_Adress on its channel ex: RX_ADDR_P0 = TX_ADDR<br />val&#91;0&#93; = 0x01;//set value<br />WriteToNrf(W, EN_AA, val, 1);//W=write mode, EN_AA=register to write to, val=data to write, 1=number of data bytes<br /><br />val&#91;0&#93; = 0x2F;//0b0010 1111 &quot;2&quot; sets it up to 750uS delay between every retry (at least 500us at 250kbps and if payload &gt;5bytes in 1Mbps,<br />//and if payload &gt;15byte in 2Mbps) &quot;F&quot; is number of retries (1-15, now 15)<br />WriteToNrf(W, SETUP_RETR, val, 1);<br /><br />//Choose number of enabled data pipes (1-5)<br />val&#91;0&#93; = 0x01;<br />WriteToNrf(W, EN_RXADDR, val, 1); //enable data pipe 0<br /><br />//RF_Adress width setup (how many bytes is the receiver address, the more the merrier 1-5)<br />val&#91;0&#93; = 0x03;//0b0000 0011 = 5 bytes RF_Adres<br />WriteToNrf(W, SETUP_AW, val, 1);<br /><br />//RF channel setup - choose frequency 2,400-2,527GHz 1MHz/step<br />val&#91;0&#93; = 0x01;//0b0000 0001 = 2,401GHz (same on TX and RX)<br />WriteToNrf(W, RF_CH, val, 1);<br /><br />//RF setup - choose power mode and data speed<br />val&#91;0&#93; = 0x07;//0000 0111 bit 3=&quot;0&quot; 1Mbps=longer range, bit 2-1 power mode (&quot;11&quot;=-0dB ; &quot;00&quot;=-18dB)<br />WriteToNrf(W, RF_SETUP, val, 1);<br /><br />//RX RF_Adress setup 5 byte - Set Receiver address (set RX_ADDR_P0 = TX_ADDR if EN_AA is enabled!!!)<br />for(uint8_t i=0; i&lt;5; i++)<br />{<br />val&#91;i&#93; = 0x12;//0x12 x 5 to get a long and secure address<br />}<br />WriteToNrf(W, RX_ADDR_P0, val, 5); //since we choose pipe 0 on EN_RXADDR we give this address to that channel<br />//Here you can give different addresses to different channels(if they are enabled in EN_RXADDR) to listen on several different transmitters)<br /><br />//TX RF_Adress setup 5 byte - Set Transmitter address (not used in a receiver but can be set anyway)<br />for(uint8_t i=0; i&lt;5; i++)<br />{<br />val&#91;i&#93; = 0x12;//0x12 x 5 - same on the Receiver chip and the RX-RF_Address above if EN_AA is enabled!<br />}<br />WriteToNrf(W, TX_ADDR, val, 5);<br /><br />//Payload Width Setup - 1-32byte (how many bytes to send per transmission)<br />val&#91;0&#93; = 32;//Send 32 bytes per package this time (same on receiver and transmitter)<br />WriteToNrf(W, RX_PW_P0, val, 1);<br /><br />//CONFIG reg setup - Now it's time to boot up the nrf and choose if it's suppose to be a transmitter or receiver<br />val&#91;0&#93; = 0x1E;//0b0001 1110 - bit 0=&quot;0&quot;:transmitter bit 0=&quot;1&quot;:receiver, bit 1=&quot;1&quot;:power up,<br />//bit 4=&quot;1&quot;:mask_Max_RT i.e. IRQ-interrupt is not triggered if transmission failed.<br />WriteToNrf(W, CONFIG, val, 1);<br /><br />//device need 1.5ms to reach standby mode (CE=low)<br />_delay_ms(100);<br />}<br /><br />void transmit_payload(uint8_t * W_buff)<br />{<br />WriteToNrf(R, FLUSH_TX, W_buff, 0);//Sends 0xE1 to flush the  registry from old data! W_buff&#91;&#93; is only there because an array has to be called with an array...<br />WriteToNrf(R, W_TX_PAYLOAD, W_buff, 5); //Sends the data in W_buff to the nrf<br />//Why Flush_TX and W_TX_Payload is sent with an &quot;R&quot; instead of &quot;W&quot; is because they are on the highest byte-level in the nRF (see datasheet below)!<br /><br />//sei(); //Enable global interrupt (if interrupt is used)<br /><br />_delay_ms(10);//needs a 10ms delay to work after loading the nrf with the payload for some reason<br />SETBIT(PORTB, 1);//CE high - transmit the data!<br />_delay_us(20);//delay at least 10us!<br />CLEARBIT(PORTB, 1);//CE low - stop transmitting<br />_delay_ms(10);//long delay again before proceeding.<br />}<br /><br />int main(void)<br />{<br />    uart_init();<br />InitSPI();<br />nrf24L01_init();<br /><br />uint8_t W_buffer&#91;32&#93;;<br /><br />for (int i=0; i&lt;32; i++)<br />{<br />W_buffer&#91;i&#93;=0x93;<br />}<br /><br />    while (1) <br />    {<br />uart_putc(GetReg(STATUS));<br />transmit_payload(W_buffer);<br /><br />_delay_ms(1000);<br />    }<br />}[/syntax]<br /><br /><br />Program Arduino:<br />[syntax=cpp]#include &lt;SPI.h&gt;<br />#include &lt;nRF24L01.h&gt;<br />#include &lt;RF24.h&gt;<br /><br />RF24 radio(9, 10);<br /><br />byte rxAddr&#91;5&#93;;<br /><br />void setup() {<br />  for(int i=0; i&lt;5; i++)<br />  {<br />    rxAddr&#91;i&#93; = 0x12;<br />  }<br />  <br />  while (!Serial);<br />  Serial.begin(9600);<br /><br />  radio.begin();<br />  radio.setChannel(1);<br />  radio.openReadingPipe(0, rxAddr);<br />  radio.startListening();<br />}<br /><br />void loop() {<br />  if (radio.available())<br />  {<br />    char text&#91;32&#93; = {0};<br />    radio.read(&amp;text, sizeof(text));<br /><br />    Serial.println(text);<br />  }<br /><br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3992">fgfd</a> — 13 cze 2016, o 19:17</p><hr />
]]></content>
</entry>
</feed>