nRF905问题,PTR8000收发双向调试

huxinhui 2010-08-29 03:15:22
小弟想要实现PTR8000收发功能,就是一个PTR8000具有收发功能,双向通信。发送总是比较好实现,但是接收数据上总出现问题,现在我的的单向是没什么问题,但是要实现双向,应该是逻辑上出现问题,总是在接受端卡死程序,还有DR(数据准备完成)标志位这个位的跳变不好掌握,好像跟PDF上有区别啊,这是我的理解,肯定不是正确的,想请教下有经验的大哥,对收发(主要是针对主函数上的编写)求教。。
...全文
153 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
maomao0258 2010-10-19
  • 打赏
  • 举报
回复
迅通科技0755-26804969是NORDIC代理商,专业供应NORDIC2.4G芯片和模块,433/868/915芯片和模块,供应nRF24LE1,nRF24L01,nRF24AP2,nRF24LU1,nRF905,nRF9E5, nRF24L01P,nRF2401A,nRF2402 nRF24E2,nRF24Z1, nRF24LU1P nRF24E1以及相关产品的模块和开发系统。
我们致力于将先进的无线技术集成于您的产品中,使您的设计更趋简单高效,有效地降低开发和生产成本。很多用户是因为缺少无线电路的设计或调试经验和手段而考虑采用我们的产品,从多方面讲这一选择都是明智的。我们的产品就在于很好的性能价格比,使您的产品只需最短的设计及生产时间,并且从一开始就拥有完美的性能。
durant 2010-09-20
  • 打赏
  • 举报
回复
友情up
祝你好运
huxinhui 2010-08-29
  • 打赏
  • 举报
回复
这是我所调试的程序,好久了,试过挺多办法,现在基本还原了程序。希望了解的大哥帮个忙!!
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"

/*-----------------------指令配置-----------------------------------------*/
#define WC 0x00
#define RC 0x10
#define WTP 0x20
#define RTP 0x21
#define WTA 0x22
#define RTA 0x23
#define RRP 0x24

/*------------------------状态响应IO口------------------------------------*/
#define AM PORTA_PA0
#define DR PTJ_PTJ0
#define MISO PORTA_PA2
#define CD PORTA_PA3

/*-------------------------时序响应IO口-----------------------------------*/
#define PWR_UP PORTB_PB7 //out
#define TX_EN PORTB_PB6 //out
#define TRX_CE PORTB_PB2 //out
#define CSN PORTB_PB3 //out
#define MOSI PORTB_PB4 //out
#define SCK PORTB_PB5 //out

/*----------------------按键定义------------------------------------------*/
#define KEY_OK PORTE_PE6

/*-----------液晶部分IO口定义及自定义----------------*/
#define LCDData PTT //lcd显示数据传送口
#define LCDData_D DDRT //数据口方向寄存器
#define LCDCtrl PTM //lcd控制信号传送口
#define LCDCtrl_D DDRM //控制口方向寄存器
#define LCDRS 0
#define LCDRW 1
#define LCDE 2
unsigned char Fourth,Third,Second,First;
unsigned char data;
char *table="Received Date Is";

/*-------------------------自定义函数-----------------------------------*/
void SetTxMode(void);
void SetRxMode(void);
void RxPacket(void);
void TxPacket(void);
void Config905(void);
void Dly_100us(byte ms);
void Dly_ms(int ms);
unsigned char nRF905TxBuf[3],nRF905RxBuf[3];
unsigned char RxBuf[3];

/*-------------------------PTR8000配置函数部分--------------------------*/
typedef struct RFConfig
{
byte n;
byte buf[10];
}RFConfig;

RFConfig RxTxConf =
{
10,
0x4c, 0x0c, 0x44, 0x03, 0x03, 0xcc, 0xcc, 0xcc,0xcc, 0x58 // 433Mhz
};

/*--------------------------延时约100微秒-------------------------------*/
void Dly_100us(byte ms)
{
int ii,jj;
for(ii=0;ii<ms;ii++)
for(jj=0;jj<135;jj++);
}

/*---------------------------延时约1毫秒 -------------------------------*/
void Dly_ms(int ms)
{
int ii,jj;
if (ms<1) ms=1;
for(ii=0;ii<ms;ii++)
for(jj=0;jj<1335;jj++);
}

/*----------------------------SPI写指令函数-----------------------------*/
void SpiWrite(byte tmch)
{
byte i;
for(i=0;i<8;i++)
{
if(tmch&0X80)
MOSI=1;
else
MOSI=0;
SCK=1;
tmch <<= 1;
SCK=0;
}
}

/*----------------------------SPI读函数---------------------------------*/
byte SpiRead(void)
{
byte i,dat=0;
for (i=0;i<8;i++)
{
dat <<=1 ;
SCK=1;
if(MISO)
dat |= 0x01;
SCK=0;
}
return dat;
}

/*----------------------------IO及模块寄存器配置-------------------------*/
void Config905(void)
{
byte i;

DDRA=0XF0;
DDRJ_DDRJ0=0;
DDRB=0XFF;

DR=1; // Init DR for input
AM=1; // Init AM for input
PWR_UP=1; // nRF905 power on
TRX_CE=0; // Set nRF905 in standby mode
TX_EN=0; // set radio in Rx mode
CSN=0; //SPI使能
SpiWrite(WC);
for (i=0;i<RxTxConf.n;i++)
{
SpiWrite(RxTxConf.buf[i]);
}
CSN=1;
}

/*-----------------------------PTR发送函数-------------------------------*/
void TxPacket(void)
{
byte i;
CSN=0; // Spi enable for write a spi command
SpiWrite(WTP); // Write payload command
for (i=0;i<3;i++)
{
SpiWrite(nRF905TxBuf[i]); // Write 32 bytes Tx data
}
CSN=1; // Spi disable
Dly_100us(1);
CSN=0; // Spi enable for write a spi command
SpiWrite(WTA); // Write address command
for (i=0;i<4;i++) // Write 4 bytes address
{
SpiWrite(RxTxConf.buf[i+5]);
}
CSN=1; // Spi disable
TRX_CE=1; // Set TRX_CE high,start Tx data transmission
Dly_100us(1); // while (DR!=1);
TRX_CE=0; // Set TRX_CE low
}

/*------------------------------PTR接收函数-------------------------------*/
void RxPacket(void)
{
byte i;
TRX_CE=0; // Set nRF905 in standby mode
CSN=0; // Spi enable for write a spi command
SpiWrite(RRP); // Read payload command
for (i=0;i<3;i++)
{
nRF905RxBuf[i]=SpiRead(); // Read data and save to buffer
}
CSN=1; // Disable spi
while(DR||AM); // Dly_ms(10);
TRX_CE=1;
}

/*-----------------------------设置发送模式--------------------------------*/
void SetTxMode(void)
{
TX_EN=1;
TRX_CE=0;
Dly_ms(1); // Dly_100us for mode change(>=650us)
}

/*-----------------------------设置接收模式--------------------------------*/
void SetRxMode(void)
{
TX_EN=0;
TRX_CE=1;
Dly_ms(1); // Dly_100us for mode change(>=650us)
}

/*-----------------------------锁相环设置16M-------------------------------*/
void SET_PLL(void)
{
CLKSEL=0X00; // disengage PLL to system
PLLCTL_PLLON=1; // turn on PLL
SYNR =0x00 | 0x01;
REFDV=0x80 | 0x01; // pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
POSTDIV=0x00; // 4:0, fPLL= fVCO/(2xPOSTDIV)
// If POSTDIV = $00 then fPLL is identical to fVCO (divide by one).
_asm(nop); // BUS CLOCK=16M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;

DDRB=0XFF;
PORTB=0XFF;
DDRE = 0x3F; //KB
PORTE= 0xFF; //
}

/*
*********************************************************************
*语法格式:void PJI_init(void)
*实现功能:IOJ外部中断函数
*程序描述:
*********************************************************************
*/
void PJI_init(void)
{
DDRJ_DDRJ0=0;
PPSJ_PPSJ0=1;
PIEJ_PIEJ0=1;
}

/************************主函数***************************/
void main(void)
{
SET_PLL();
PJI_init();
Config905();
Dly_ms(100);
EnableInterrupts;
SetRxMode(); // Set nRF905 & nRF24L01 in Rx mode
for(;;)
{
nRF905TxBuf[0] = 4;
nRF905TxBuf[1] = 5;
nRF905TxBuf[2] = 6;
SetTxMode(); // Set Tx Mode
Dly_ms(1);
TxPacket();
SetRxMode();
while(!DR);
}
}

/*
*********************************************************************
*语法格式:void interrupt 24 PJI(void)
*实现功能:J口定时中断函数
*程序描述:
********************************************************************
*/
#pragma CODE_SEG NON_BANKED
void interrupt 24 PJI(void)
{
unsigned char i;
RxPacket();
for(i=0;i<3;i++)
RxBuf[i]=nRF905RxBuf[i]; //recive data
PIFJ_PIFJ0=1;
}


3,846

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 无线
社区管理员
  • 无线
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧