📄 无线nrf905(ptr8000模块)源程序+原理图ddb.htm
字号:
<BR>------------------------------------------------*/
<BR>#define WC 0x00 // Write configuration register command
<BR>#define RC 0x10 // Read configuration register command
<BR>#define WTP 0x20 // Write TX Payload command
<BR>#define RTP 0x21 // Read TX Payload command
<BR>#define WTA 0x22 // Write TX Address command
<BR>#define RTA 0x23 // Read TX Address command
<BR>#define RRP 0x24 // Read RX Payload command
<BR> <BR><BR>//配置nRF905 <BR>void nrf905_Config(void) <BR>{
<BR> CLR(PORTB,CSN); // Spi 片选开
<BR> nrf905_SpiRW(WC); // Write config command
<BR> nrf905_SpiRW(CH_NO_BYTE); //中心频率低8位
<BR> nrf905_SpiRW(PA_PWR_10dBm | HFREQ_PLL_433MHz); //发射+10dBm,发射频率433MHz,中心频率第9位=0
<BR> nrf905_SpiRW(TX_AFW_4BYTE | RX_AFW_4BYTE); //接收地址宽度4字节,发送地址宽度4字节
<BR> nrf905_SpiRW(RX_PW_32BYTE); //接收数据宽度32字节
<BR> nrf905_SpiRW(TX_PW_32BYTE); //发送数据宽度32字节
<BR> nrf905_SpiRW(RX_ADDRESS_0); //接收有效地址第1字节
<BR> nrf905_SpiRW(RX_ADDRESS_1); //接收有效地址第2字节
<BR> nrf905_SpiRW(RX_ADDRESS_2); //接收有效地址第3字节
<BR> nrf905_SpiRW(RX_ADDRESS_3); //接收有效地址第4字节
<BR> nrf905_SpiRW(CRC16_EN | XOF_16MHz); //CRC16模式使能,晶体振荡器频率16MHz
<BR> SET(PORTB,CSN); // Disable Spi
<BR>} <BR><BR>uchar nrf905_SpiRW(uchar val)
<BR>{uchar temp; <BR><BR> SPDR=val;
<BR> while ((SPSR&(1<<SPIF))==0);
<BR> temp=SPDR; <BR> return temp;
<BR>} <BR><BR>//PwrDown->StandBy <BR>void nrf905_StandBy() <BR>{
<BR> SET(PORTB,PWR);
<BR> CLR(PORTB,TRXCE);
<BR> CLR(PORTB,TX_EN); <BR>} <BR><BR>//->PwrDown
<BR>void nrf905_Off() <BR>{ <BR> CLR(PORTB,PWR); <BR>}
<BR><BR>//->ShockBurst Send <BR>void nrf905_TxOn() <BR>{
<BR> SET(PORTB,PWR); <BR> SET(PORTB,TX_EN);
<BR> CLR(PORTB,TRXCE); <BR>}
<BR><BR>//->ShockBurst Send <BR>void nrf905_TxSend() <BR>{
<BR> SET(PORTB,TRXCE); <BR> DelayUs(20);//>10us
<BR> CLR(PORTB,TRXCE);//只发送一次 <BR>}
<BR><BR>//->ShockBurst Recv <BR>void nrf905_RxOn() <BR>{
<BR> SET(PORTB,PWR);
<BR> CLR(PORTB,TX_EN);//maybe first
<BR> SET(PORTB,TRXCE); <BR>} <BR><BR>//初始化nrf905
<BR>void nrf905_Init() <BR>{ <BR> nrf905_StandBy();
<BR> DelayMs(10);//!!!must >3ms
<BR> nrf905_Config(); <BR>
<BR> nrf905_SpiTest();//test...
<BR> nrf905_RxOn(); <BR>} <BR><BR>//测试:通过读配置,判断SPI操作是否正确
<BR>void nrf905_SpiTest() <BR>{uchar i;
<BR> CLR(PORTB,CSN);
<BR> nrf905_SpiRW(RC); //读配置
<BR> for (i=0;i<10;i++) <BR> {
<BR> RxBuf[i]= nrf905_SpiRW(0);//read from nrf905
<BR> } <BR> SET(PORTB,CSN); <BR>}
<BR><BR>//写Tx地址 <BR>void nrf905_SetTxAddr() <BR>{
<BR> CLR(PORTB,CSN);
<BR> nrf905_SpiRW(WTA); //写Tx地址
<BR> nrf905_SpiRW(TX_ADDRESS_0);
<BR> nrf905_SpiRW(TX_ADDRESS_1);
<BR> nrf905_SpiRW(TX_ADDRESS_2);
<BR> nrf905_SpiRW(TX_ADDRESS_3);
<BR> SET(PORTB,CSN); <BR>} <BR><BR>//写Tx数据
<BR>void nrf905_SetData() <BR>{uchar i;
<BR><BR> CLR(PORTB,CSN);
<BR> nrf905_SpiRW(WTP); //写TxPayload
<BR> for (i=0;i<SIZE;i++) <BR> {
<BR> nrf905_SpiRW(TxBuf[i]); <BR> }
<BR> <BR> SET(PORTB,CSN); <BR>}
<BR><BR>//等待发送结束 <BR>void nrf905_WaitSended() <BR>{
<BR> while ((PIND&(1<<DR))==0); <BR>}
<BR><BR>//发送TxBuf中的数据 <BR>void nrf905_SendData() <BR>{
<BR> nrf905_TxOn();//切换到发送模式
<BR> nrf905_SetTxAddr();//写发送地址
<BR> nrf905_SetData();//写数据
<BR> nrf905_TxSend();//启动发送
<BR> nrf905_WaitSended();//等待发送结束 <BR>
<BR>} <BR><BR>//测试直接重新发送上次写入的数据 <BR>void nrf905_SendAgain() <BR>{
<BR> nrf905_TxOn();
<BR> nrf905_TxSend();
<BR> nrf905_WaitSended(); <BR> <BR>}
<BR><BR>//读出接收到的数据 <BR>void nrf905_ReadData() <BR>{
<BR> uchar i;
<BR><BR> CLR(PORTB,CSN);
<BR> nrf905_SpiRW(RRP); //读RxPayload
<BR> for (i=0;i<SIZE;i++) <BR> {
<BR> RxBuf[i]=nrf905_SpiRW(0);//read...
<BR> } <BR>
<BR> SET(PORTB,CSN); <BR><BR>} <BR><BR>-----<FONT
color=blue>此内容被pei99888于2006-04-05,12:28:28编辑过</FONT><BR></FONT></TD></TR>
<TR>
<TD bgColor=#e8e8e8 class=f03
style="BORDER-BOTTOM: #bbbbbb 0.5pt solid; BORDER-LEFT: medium none; BORDER-RIGHT: #bbbbbb 0.5pt solid; BORDER-TOP: medium none"
vAlign=bottom> </TD></TR>
<TR>
<TD align=left bgColor=#e8e8e8 class=f03
style="BORDER-BOTTOM: #bbbbbb 0.5pt solid; BORDER-LEFT: #bbbbbb 0.5pt solid; BORDER-RIGHT: #bbbbbb 0.5pt solid; BORDER-TOP: medium none"
width="19%"><IMG height=1
src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF"
width=7>2006-04-05,12:27:13 </TD>
<TD bgColor=#e8e8e8 class=f03
style="BORDER-BOTTOM: #bbbbbb 0.5pt solid; BORDER-LEFT: medium none; BORDER-RIGHT: #bbbbbb 0.5pt solid; BORDER-TOP: medium none"
vAlign=top width="81%" ?>
<TABLE width="100%">
<TBODY>
<TR>
<TD align=left><IMG height=1
src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF" width=7> <A
class=tt4
href="http://www.ouravr.com/bbs/user_information.jsp?user_name=pei99888"
target=_blank>资料</A> <IMG height=1
src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF" width=7> <A
class=tt4 href="mailto:pei99888@126.com">邮件</A> <IMG height=1
src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF" width=7> </TD>
<TD align=right><IMG height=1
src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF" width=2> <IMG
height=1 src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF"
width=2> <IMG height=1
src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF" width=2> <IMG
height=1 src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF"
width=2> <IMG height=1
src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF" width=2> <IMG
height=1 src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF"
width=2> <SPAN class=f01>编辑</SPAN> <IMG height=1
src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF" width=7> <SPAN
class=f01>删除</SPAN> <IMG height=1
src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF" width=7> <IMG
height=1 src="无线nrf905(PTR8000模块)源程序+原理图DDB.files/pixel.GIF"
width=7> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=6 cellSpacing=0
style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all" width="100%">
<TBODY>
<TR>
<TD align=left bgColor=#d1d9e2 class=f03 rowSpan=2
style="BORDER-BOTTOM: #ffffff 0.5pt solid; BORDER-LEFT: #bbbbbb 0.5pt solid; BORDER-RIGHT: #ffffff 0.5pt solid; BORDER-TOP: #ffffff 0.5pt solid"
vAlign=top width="19%">【2楼】 <FONT color=#000000>mutoudonggua
</FONT><BR>积分:<FONT color=#000000>91</FONT><BR>派别:<FONT
color=#000000></FONT><BR>等级:<FONT color=#000000>------</FONT><BR>来自:<FONT
color=#000000>湖南长沙</FONT><BR></TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -