OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 8492|回复: 3

原子大! NRF24L01

[复制链接]

6

主题

18

帖子

0

精华

初级会员

Rank: 2

积分
62
金钱
62
注册时间
2011-11-12
在线时间
0 小时
发表于 2012-1-31 21:36:55 | 显示全部楼层 |阅读模式
這是ARDUINO的程式碼!&nbsp;<br />
&nbsp; /*********************************************************************<div>** &nbsp;Device: &nbsp;nRF24L01+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;File: &nbsp; EF_nRF24L01_TX.c &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;Copyright (C) 2011 ElecFraks. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; **</div>
<div>** &nbsp;This example code is in the public domain. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;Description: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;This file is a sample code for your reference. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;It's the v1.0 nRF24L01+ Hardware SPI by arduino &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; **</div>
<div>** &nbsp;Created by ElecFreaks. Robi.W,11 June 2011 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;http://www.elecfreaks.com &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; **</div>
<div>** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; SPI-compatible &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; **</div>
<div>** &nbsp; CS - to digital pin 8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; CSN - to digital pin 9 &nbsp;(SS pin) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; **</div>
<div>** &nbsp; MOSI - to digital pin 11 (MOSI pin) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; MISO - to digital pin 12 (MISO pin) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; CLK - to digital pin 13 (SCK pin) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>*********************************************************************/</div>
<div><br />
</div>
<div>#include &lt;SPI.h&gt;</div>
<div>#include "API.h"</div>
<div>#include "nRF24L01.h"</div>
<div><br />
</div>
<div>//***************************************************</div>
<div>#define TX_ADR_WIDTH &nbsp; &nbsp;5 &nbsp; // 5 unsigned chars TX(RX) address width</div>
<div>#define TX_PLOAD_WIDTH &nbsp;32 &nbsp;// 32 unsigned chars TX payload</div>
<div><br />
</div>
<div>unsigned char TX_ADDRESS[TX_ADR_WIDTH] &nbsp;=&nbsp;</div>
<div>{</div>
<div>&nbsp; 0x34,0x43,0x10,0x10,0x01</div>
<div>}; // Define a static TX address</div>
<div><br />
</div>
<div>unsigned char rx_buf[TX_PLOAD_WIDTH] = {0}; // initialize value</div>
<div>unsigned char tx_buf[TX_PLOAD_WIDTH] = {0};</div>
<div>//***************************************************</div>
<div>void setup()&nbsp;</div>
<div>{</div>
<div>&nbsp; Serial.begin(9600);</div>
<div>&nbsp; pinMode(CE, &nbsp;OUTPUT);</div>
<div>&nbsp; pinMode(CSN, OUTPUT);</div>
<div>&nbsp; pinMode(IRQ, INPUT);</div>
<div>&nbsp; SPI.begin();</div>
<div>&nbsp; delay(50);</div>
<div>&nbsp; init_io(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Initialize IO port</div>
<div>&nbsp; unsigned char sstatus=SPI_Read(STATUS);</div>
<div>&nbsp; Serial.println("*******************TX_Mode Start****************************");</div>
<div>&nbsp; Serial.print("status = "); &nbsp; &nbsp;</div>
<div>&nbsp; Serial.println(sstatus,HEX); &nbsp; &nbsp; // There is read the mode’s status register, the default value should be ‘E’</div>
<div>&nbsp; TX_Mode(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // set TX mode</div>
<div>}</div>
<div><br />
</div>
<div>void loop()&nbsp;</div>
<div>{</div>
<div>&nbsp; int k = 0;</div>
<div>&nbsp; for(;;)</div>
<div>&nbsp; {</div>
<div>&nbsp; &nbsp; for(int i=0; i&lt;32; i++)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; tx_buf = k++; &nbsp; &nbsp; &nbsp; &nbsp;</div>
<div>&nbsp; &nbsp; unsigned char sstatus = SPI_Read(STATUS); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // read register STATUS's value</div>
<div>&nbsp; &nbsp; if(sstatus&amp;TX_DS) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // if receive data ready (TX_DS) interrupt</div>
<div>&nbsp; &nbsp; {</div>
<div>&nbsp; &nbsp; &nbsp; SPI_RW_Reg(FLUSH_TX,0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
<div>&nbsp; &nbsp; &nbsp; SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH); &nbsp; &nbsp; &nbsp; // write playload to TX_FIFO</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; if(sstatus&amp;MAX_RT) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // if receive data ready (MAX_RT) interrupt, this is retransmit than &nbsp;SETUP_RETR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
<div>&nbsp; &nbsp; {</div>
<div>&nbsp; &nbsp; &nbsp; SPI_RW_Reg(FLUSH_TX,0);</div>
<div>&nbsp; &nbsp; &nbsp; SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH); &nbsp; &nbsp; &nbsp;// disable standy-mode</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; SPI_RW_Reg(WRITE_REG+STATUS,sstatus); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // clear RX_DR or TX_DS or MAX_RT interrupt flag</div>
<div>&nbsp; &nbsp; delay(1000);</div>
<div>&nbsp; }</div>
<div>}</div>
<div><br />
</div>
<div>//**************************************************</div>
<div>// Function: init_io();</div>
<div>// Description:</div>
<div>// flash led one time,chip enable(ready to TX or RX Mode),</div>
<div>// Spi disable,Spi clock line init high</div>
<div>//**************************************************</div>
<div>void init_io(void)</div>
<div>{</div>
<div>&nbsp; digitalWrite(IRQ, 0);</div>
<div>&nbsp; digitalWrite(CE, 0);<span class="Apple-tab-span" style="white-space:pre;">                        </span>// chip enable</div>
<div>&nbsp; digitalWrite(CSN, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Spi disable<span class="Apple-tab-span" style="white-space:pre;">        </span></div>
<div>}</div>
<div><br />
</div>
<div>/************************************************************************</div>
<div>** &nbsp; * Function: SPI_RW();</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* Description:</div>
<div>&nbsp;* Writes one unsigned char to nRF24L01, and return the unsigned char read</div>
<div>&nbsp;* from nRF24L01 during write, according to SPI protocol</div>
<div>************************************************************************/</div>
<div>unsigned char SPI_RW(unsigned char Byte)</div>
<div>{</div>
<div>&nbsp; return SPI.transfer(Byte);</div>
<div>}</div>
<div><br />
</div>
<div>/**************************************************/</div>
<div><br />
</div>
<div>/**************************************************</div>
<div>&nbsp;* Function: SPI_RW_Reg();</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* Description:</div>
<div>&nbsp;* Writes value 'value' to register 'reg'</div>
<div>/**************************************************/</div>
<div>unsigned char SPI_RW_Reg(unsigned char reg, unsigned char value)</div>
<div>{</div>
<div>&nbsp; unsigned char status;</div>
<div><br />
</div>
<div>&nbsp; digitalWrite(CSN, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // CSN low, init SPI transaction</div>
<div>&nbsp; SPI_RW(reg); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// select register</div>
<div>&nbsp; SPI_RW(value); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// ..and write value to it..</div>
<div>&nbsp; digitalWrite(CSN, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // CSN high again</div>
<div><br />
</div>
<div>&nbsp; return(status); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // return nRF24L01 status unsigned char</div>
<div>}</div>
<div>/**************************************************/</div>
<div><br />
</div>
<div>/**************************************************</div>
<div>&nbsp;* Function: SPI_Read();</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* Description:</div>
<div>&nbsp;* Read one unsigned char from nRF24L01 register, 'reg'</div>
<div>/**************************************************/</div>
<div>unsigned char SPI_Read(unsigned char reg)</div>
<div>{</div>
<div>&nbsp; unsigned char reg_val;</div>
<div><br />
</div>
<div>&nbsp; digitalWrite(CSN, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// CSN low, initialize SPI communication...</div>
<div>&nbsp; SPI_RW(reg); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Select register to read from..</div>
<div>&nbsp; reg_val = SPI_RW(0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ..then read register value</div>
<div>&nbsp; digitalWrite(CSN, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// CSN high, terminate SPI communication</div>
<div><br />
</div>
<div>&nbsp; return(reg_val); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // return register value</div>
<div>}</div>
<div>/**************************************************/</div>
<div><br />
</div>
<div>/**************************************************</div>
<div>&nbsp;* Function: SPI_Read_Buf();</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* Description:</div>
<div>&nbsp;* Reads 'unsigned chars' #of unsigned chars from register 'reg'</div>
<div>&nbsp;* Typically used to read RX payload, Rx/Tx address</div>
<div>/**************************************************/</div>
<div>unsigned char SPI_Read_Buf(unsigned char reg, unsigned char *pBuf, unsigned char bytes)</div>
<div>{</div>
<div>&nbsp; unsigned char sstatus,i;</div>
<div><br />
</div>
<div>&nbsp; digitalWrite(CSN, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set CSN low, init SPI tranaction</div>
<div>&nbsp; sstatus = SPI_RW(reg); &nbsp; &nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre;">        </span> &nbsp; &nbsp;// Select register to write to and read status unsigned char</div>
<div><br />
</div>
<div>&nbsp; for(i=0;i&lt;bytes;i++)</div>
<div>&nbsp; {</div>
<div>&nbsp; &nbsp; pBuf = SPI_RW(0); &nbsp; &nbsp;// Perform SPI_RW to read unsigned char from nRF24L01</div>
<div>&nbsp; }</div>
<div><br />
</div>
<div>&nbsp; digitalWrite(CSN, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set CSN high again</div>
<div><br />
</div>
<div>&nbsp; return(sstatus); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// return nRF24L01 status unsigned char</div>
<div>}</div>
<div>/**************************************************/</div>
<div><br />
</div>
<div>/**************************************************</div>
<div>&nbsp;* Function: SPI_Write_Buf();</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* Description:</div>
<div>&nbsp;* Writes contents of buffer '*pBuf' to nRF24L01</div>
<div>&nbsp;* Typically used to write TX payload, Rx/Tx address</div>
<div>/**************************************************/</div>
<div>unsigned char SPI_Write_Buf(unsigned char reg, unsigned char *pBuf, unsigned char bytes)</div>
<div>{</div>
<div>&nbsp; unsigned char sstatus,i;</div>
<div><br />
</div>
<div>&nbsp; digitalWrite(CSN, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set CSN low, init SPI tranaction</div>
<div>&nbsp; sstatus = SPI_RW(reg); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Select register to write to and read status unsigned char</div>
<div>&nbsp; for(i=0;i&lt;bytes; i++) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // then write all unsigned char in buffer(*pBuf)</div>
<div>&nbsp; {</div>
<div>&nbsp; &nbsp; SPI_RW(*pBuf++);</div>
<div>&nbsp; }</div>
<div>&nbsp; digitalWrite(CSN, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set CSN high again</div>
<div>&nbsp; return(sstatus); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// return nRF24L01 status unsigned char</div>
<div>}</div>
<div>/**************************************************/</div>
<div><br />
</div>
<div>/**************************************************</div>
<div>&nbsp;* Function: TX_Mode();</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* Description:</div>
<div>&nbsp;* This function initializes one nRF24L01 device to</div>
<div>&nbsp;* TX mode, set TX address, set RX address for auto.ack,</div>
<div>&nbsp;* fill TX payload, select RF channel, datarate &amp; TX pwr.</div>
<div>&nbsp;* PWR_UP is set, CRC(2 unsigned chars) is enabled, &amp; PRIM:TX.</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* ToDo: One high pulse(&gt;10us) on CE will now send this</div>
<div>&nbsp;* packet and expext an acknowledgment from the RX device.</div>
<div>&nbsp;**************************************************/</div>
<div>void TX_Mode(void)</div>
<div>{</div>
<div>&nbsp; digitalWrite(CE, 0);</div>
<div><br />
</div>
<div>&nbsp; SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH); &nbsp; &nbsp;// Writes TX_Address to nRF24L01</div>
<div>&nbsp; SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH); // RX_Addr0 same as TX_Adr for Auto.Ack</div>
<div><br />
</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + EN_AA, 0x01); &nbsp; &nbsp; &nbsp;// Enable Auto.Ackipe0</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01); &nbsp;// Enable Pipe0</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x1a); // 500us + 86us, 10 retrans...</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + RF_CH, 40); &nbsp; &nbsp; &nbsp; &nbsp;// Select RF channel 40</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07); &nbsp; // TX_PWR:0dBm, Datarate:2Mbps, LNA:HCURR</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e); &nbsp; &nbsp; // Set PWR_UP bit, enable CRC(2 unsigned chars) &amp; Prim:TX. MAX_RT &amp; TX_DS enabled..</div>
<div>&nbsp; SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH);</div>
<div><br />
</div>
<div>&nbsp; digitalWrite(CE, 1);</div>
<div>} &nbsp;&nbsp;<br />
===============================================================================================<br />
===============================================================================================<br />
===============================================================================================<br />
<br />
<div>/*********************************************************************</div>
<div>** &nbsp;Device: &nbsp;nRF24L01+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;File: &nbsp; EF_nRF24L01_RX.c &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;Copyright (C) 2011 ElecFraks. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; **</div>
<div>** &nbsp;This example code is in the public domain. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;Description: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;This file is a sample code for your reference. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;It's the v1.0 nRF24L01+ Hardware SPI by arduino &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; **</div>
<div>** &nbsp;Created by ElecFreaks. Robi.W,11 June 2011 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp;http://www.elecfreaks.com &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; **</div>
<div>** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; SPI-compatible &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; **</div>
<div>** &nbsp; CS - to digital pin 8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; CSN - to digital pin 9 &nbsp;(SS pin) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; **</div>
<div>** &nbsp; MOSI - to digital pin 11 (MOSI pin) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; MISO - to digital pin 12 (MISO pin) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>** &nbsp; CLK - to digital pin 13 (SCK pin) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**</div>
<div>*********************************************************************/</div>
<div><br />
</div>
<div><br />
</div>
<div>#include &lt;SPI.h&gt;</div>
<div>#include "API.h"</div>
<div>#include "nRF24L01.h"</div>
<div><br />
</div>
<div>//***************************************************</div>
<div>#define TX_ADR_WIDTH &nbsp; &nbsp;5 &nbsp; // 5 unsigned chars TX(RX) address width</div>
<div>#define TX_PLOAD_WIDTH &nbsp;32 &nbsp;// 32 unsigned chars TX payload</div>
<div><br />
</div>
<div>unsigned char TX_ADDRESS[TX_ADR_WIDTH] &nbsp;=&nbsp;</div>
<div>{</div>
<div>&nbsp; 0x34,0x43,0x10,0x10,0x01</div>
<div>}; // Define a static TX address</div>
<div><br />
</div>
<div>unsigned char rx_buf[TX_PLOAD_WIDTH] = {0}; // initialize value</div>
<div>unsigned char tx_buf[TX_PLOAD_WIDTH] = {0};</div>
<div>//***************************************************</div>
<div>void setup()&nbsp;</div>
<div>{</div>
<div>&nbsp; Serial.begin(9600);</div>
<div>&nbsp; pinMode(CE, &nbsp;OUTPUT);</div>
<div>&nbsp; pinMode(CSN, OUTPUT);</div>
<div>&nbsp; pinMode(IRQ, INPUT);</div>
<div>&nbsp; SPI.begin();</div>
<div>&nbsp; delay(50);</div>
<div>&nbsp; init_io(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Initialize IO port</div>
<div>&nbsp; unsigned char sstatus=SPI_Read(STATUS);</div>
<div>&nbsp; Serial.println("*******************RX_Mode Start****************************");</div>
<div>&nbsp; Serial.print("status = "); &nbsp; &nbsp;</div>
<div>&nbsp; Serial.println(sstatus,HEX); &nbsp; &nbsp; // There is read the mode’s status register, the default value should be ‘E’</div>
<div>&nbsp; RX_Mode(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// set RX mode</div>
<div>}</div>
<div><br />
</div>
<div>void loop()&nbsp;</div>
<div>{</div>
<div>&nbsp; for(;;)</div>
<div>&nbsp; {</div>
<div>&nbsp; &nbsp; unsigned char status = SPI_Read(STATUS); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // read register STATUS's value</div>
<div>&nbsp; &nbsp; if(status&amp;RX_DR) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // if receive data ready (TX_DS) interrupt</div>
<div>&nbsp; &nbsp; {</div>
<div>&nbsp; &nbsp; &nbsp; SPI_Read_Buf(RD_RX_PLOAD, rx_buf, TX_PLOAD_WIDTH); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // read playload to rx_buf</div>
<div>&nbsp; &nbsp; &nbsp; SPI_RW_Reg(FLUSH_RX,0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// clear RX_FIFO</div>
<div>&nbsp; &nbsp; &nbsp; for(int i=0; i&lt;32; i++)</div>
<div>&nbsp; &nbsp; &nbsp; {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Serial.print(" ");</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Serial.print(rx_buf,HEX); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// print rx_buf</div>
<div>&nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; &nbsp; Serial.println(" ");</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; SPI_RW_Reg(WRITE_REG+STATUS,status); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // clear RX_DR or TX_DS or MAX_RT interrupt flag</div>
<div>&nbsp; &nbsp; delay(1000);</div>
<div>&nbsp; }</div>
<div>}</div>
<div><br />
</div>
<div>//**************************************************</div>
<div>// Function: init_io();</div>
<div>// Description:</div>
<div>// flash led one time,chip enable(ready to TX or RX Mode),</div>
<div>// Spi disable,Spi clock line init high</div>
<div>//**************************************************</div>
<div>void init_io(void)</div>
<div>{</div>
<div>&nbsp; digitalWrite(IRQ, 0);</div>
<div>&nbsp; digitalWrite(CE, 0);<span class="Apple-tab-span" style="white-space:pre;">                        </span>// chip enable</div>
<div>&nbsp; digitalWrite(CSN, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Spi disable<span class="Apple-tab-span" style="white-space:pre;">        </span></div>
<div>}</div>
<div><br />
</div>
<div>/************************************************************************</div>
<div>** &nbsp; * Function: SPI_RW();</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* Description:</div>
<div>&nbsp;* Writes one unsigned char to nRF24L01, and return the unsigned char read</div>
<div>&nbsp;* from nRF24L01 during write, according to SPI protocol</div>
<div>************************************************************************/</div>
<div>unsigned char SPI_RW(unsigned char Byte)</div>
<div>{</div>
<div>&nbsp; return SPI.transfer(Byte);</div>
<div>}</div>
<div><br />
</div>
<div>/**************************************************/</div>
<div><br />
</div>
<div>/**************************************************</div>
<div>&nbsp;* Function: SPI_RW_Reg();</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* Description:</div>
<div>&nbsp;* Writes value 'value' to register 'reg'</div>
<div>/**************************************************/</div>
<div>unsigned char SPI_RW_Reg(unsigned char reg, unsigned char value)</div>
<div>{</div>
<div>&nbsp; unsigned char status;</div>
<div><br />
</div>
<div>&nbsp; digitalWrite(CSN, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // CSN low, init SPI transaction</div>
<div>&nbsp; SPI_RW(reg); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// select register</div>
<div>&nbsp; SPI_RW(value); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// ..and write value to it..</div>
<div>&nbsp; digitalWrite(CSN, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // CSN high again</div>
<div><br />
</div>
<div>&nbsp; return(status); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // return nRF24L01 status unsigned char</div>
<div>}</div>
<div>/**************************************************/</div>
<div><br />
</div>
<div>/**************************************************</div>
<div>&nbsp;* Function: SPI_Read();</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* Description:</div>
<div>&nbsp;* Read one unsigned char from nRF24L01 register, 'reg'</div>
<div>/**************************************************/</div>
<div>unsigned char SPI_Read(unsigned char reg)</div>
<div>{</div>
<div>&nbsp; unsigned char reg_val;</div>
<div><br />
</div>
<div>&nbsp; digitalWrite(CSN, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// CSN low, initialize SPI communication...</div>
<div>&nbsp; SPI_RW(reg); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Select register to read from..</div>
<div>&nbsp; reg_val = SPI_RW(0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ..then read register value</div>
<div>&nbsp; digitalWrite(CSN, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// CSN high, terminate SPI communication</div>
<div><br />
</div>
<div>&nbsp; return(reg_val); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // return register value</div>
<div>}</div>
<div>/**************************************************/</div>
<div><br />
</div>
<div>/**************************************************</div>
<div>&nbsp;* Function: SPI_Read_Buf();</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* Description:</div>
<div>&nbsp;* Reads 'unsigned chars' #of unsigned chars from register 'reg'</div>
<div>&nbsp;* Typically used to read RX payload, Rx/Tx address</div>
<div>/**************************************************/</div>
<div>unsigned char SPI_Read_Buf(unsigned char reg, unsigned char *pBuf, unsigned char bytes)</div>
<div>{</div>
<div>&nbsp; unsigned char sstatus,i;</div>
<div><br />
</div>
<div>&nbsp; digitalWrite(CSN, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set CSN low, init SPI tranaction</div>
<div>&nbsp; sstatus = SPI_RW(reg); &nbsp; &nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre;">        </span> &nbsp; &nbsp;// Select register to write to and read status unsigned char</div>
<div><br />
</div>
<div>&nbsp; for(i=0;i&lt;bytes;i++)</div>
<div>&nbsp; {</div>
<div>&nbsp; &nbsp; pBuf = SPI_RW(0); &nbsp; &nbsp;// Perform SPI_RW to read unsigned char from nRF24L01</div>
<div>&nbsp; }</div>
<div><br />
</div>
<div>&nbsp; digitalWrite(CSN, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set CSN high again</div>
<div><br />
</div>
<div>&nbsp; return(sstatus); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// return nRF24L01 status unsigned char</div>
<div>}</div>
<div>/**************************************************/</div>
<div><br />
</div>
<div>/**************************************************</div>
<div>&nbsp;* Function: SPI_Write_Buf();</div>
<div>&nbsp;*&nbsp;</div>
<div>&nbsp;* Description:</div>
<div>&nbsp;* Writes contents of buffer '*pBuf' to nRF24L01</div>
<div>&nbsp;* Typically used to write TX payload, Rx/Tx address</div>
<div>/**************************************************/</div>
<div>unsigned char SPI_Write_Buf(unsigned char reg, unsigned char *pBuf, unsigned char bytes)</div>
<div>{</div>
<div>&nbsp; unsigned char sstatus,i;</div>
<div><br />
</div>
<div>&nbsp; digitalWrite(CSN, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set CSN low, init SPI tranaction</div>
<div>&nbsp; sstatus = SPI_RW(reg); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Select register to write to and read status unsigned char</div>
<div>&nbsp; for(i=0;i&lt;bytes; i++) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // then write all unsigned char in buffer(*pBuf)</div>
<div>&nbsp; {</div>
<div>&nbsp; &nbsp; SPI_RW(*pBuf++);</div>
<div>&nbsp; }</div>
<div>&nbsp; digitalWrite(CSN, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set CSN high again</div>
<div>&nbsp; return(sstatus); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// return nRF24L01 status unsigned char</div>
<div>}</div>
<div>/**************************************************/</div>
<div><br />
</div>
<div>void RX_Mode(void)</div>
<div>{</div>
<div>&nbsp; digitalWrite(CE, 0);</div>
<div>&nbsp;&nbsp;</div>
<div>&nbsp; SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH); // Use the same address on the RX device as the TX device</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + EN_AA, 0x01); &nbsp; &nbsp; &nbsp;// Enable Auto.Ackipe0</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01); &nbsp;// Enable Pipe0</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + RF_CH, 40); &nbsp; &nbsp; &nbsp; &nbsp;// Select RF channel 40</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + RX_PW_P0, TX_PLOAD_WIDTH); // Select same RX payload width as TX Payload width</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07); &nbsp; // TX_PWR:0dBm, Datarate:2Mbps, LNA:HCURR</div>
<div>&nbsp; SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f); &nbsp; &nbsp; // Set PWR_UP bit, enable CRC(2 unsigned chars) &amp; Prim:RX. RX_DR enabled..</div>
<div>&nbsp; digitalWrite(CE, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set CE pin high to enable RX device</div>
<div>&nbsp; // &nbsp;This device is now ready to receive one packet of 16 unsigned chars payload from a TX device sending to address</div>
<div>&nbsp; // &nbsp;'3443101001', with auto acknowledgment, retransmit count of 10, RF channel 40 and datarate = 2Mbps.</div>
<div>}<br />
<br />
<br />
<br />
</div>
原子大!! 我想將上面ARDUINO的碼轉到您的板子上使用, 我想請教您有什麼需要特別注意的呢??<br />
<br />
那在請教一下 &nbsp;u8 和 unsigned char &nbsp;他們是一樣的嗎? &nbsp;<br />
<br />
我用您庫的方式將arduino的碼轉完 燒到板子上,,不能動作!!<br />
<br />
麻煩您看一下原子大...謝謝!!<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</div>
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165353
金钱
165353
注册时间
2010-12-1
在线时间
2108 小时
发表于 2012-1-31 22:54:43 | 显示全部楼层
ARDUINO是啥东西?没用过.
<br>u8和unsigned&nbsp;char本质上是一样.只是前面只需要2个字符,后面的需要12个字符.
<br>
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

6

主题

18

帖子

0

精华

初级会员

Rank: 2

积分
62
金钱
62
注册时间
2011-11-12
在线时间
0 小时
 楼主| 发表于 2012-2-1 15:25:14 | 显示全部楼层
謝謝原子大!!<br />
<br />
那在請教您,您的NRF24L01的例程<br />
<br />
我像要改成一次傳輸32byte的資料,您能指點一下那邊需要修改<br />
<br />
及主程式的方向!! &nbsp;謝謝<br />
<br />
<br />
<br />
<br />
<br />
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165353
金钱
165353
注册时间
2010-12-1
在线时间
2108 小时
发表于 2012-2-1 23:32:12 | 显示全部楼层
回复【3楼】rollin312018:
<br>---------------------------------
<br>只要在我的例程基础上稍作修改即可.把字节长度修改一下即可.
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-11-25 22:47

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表