?? main.c
字號:
{
Uint8 i;
SCS = 0;
addr |= 0x00; //bit cmd=0,r/w=0
for(i = 0; i < 8; i++)
{
if(addr & 0x80)
SDIO = 1;
else
SDIO = 0;
SCK = 1;
_nop_();
SCK = 0;
addr = addr << 1;
}
_nop_();
//send data byte
for(i = 0; i < 8; i++)
{
if(dataByte & 0x80)
SDIO = 1;
else
SDIO = 0;
SCK = 1;
_nop_();
SCK = 0;
dataByte = dataByte<< 1;
}
SCS = 1;
}
/************************************************************************
** A7125_ReadReg
************************************************************************/
Uint8 A7125_ReadReg(Uint8 addr)
{
Uint8 i;
Uint8 tmp;
SCS = 0;
addr |= 0x40; //bit cmd=0,r/w=1
for(i = 0; i < 8; i++)
{
if(addr & 0x80)
SDIO = 1;
else
SDIO = 0;
_nop_();
SCK = 1;
_nop_();
SCK = 0;
addr = addr << 1;
}
_nop_();
SDIO = 1;
//read data
for(i = 0; i < 8; i++)
{
if(SDIO)
tmp = (tmp << 1) | 0x01;
else
tmp = tmp << 1;
SCK = 1;
_nop_();
SCK = 0;
}
SCS = 1;
return tmp;
}
/************************************************************************
** ByteSend
************************************************************************/
void ByteSend(Uint8 src)
{
Uint8 i;
for(i = 0; i < 8; i++)
{
if(src & 0x80)
SDIO = 1;
else
SDIO = 0;
_nop_();
SCK = 1;
_nop_();
SCK = 0;
src = src << 1;
}
}
/************************************************************************
** ByteRead
************************************************************************/
Uint8 ByteRead(void)
{
Uint8 i,tmp;
SDIO = 1; //sdio pull high
for(i = 0; i < 8; i++)
{
if(SDIO)
tmp = (tmp << 1) | 0x01;
else
tmp = tmp << 1;
SCK = 1;
_nop_();
SCK = 0;
}
return tmp;
}
/************************************************************************
** Send4Bit
************************************************************************/
void Send4Bit(Uint8 src)
{
Uint8 i;
for(i = 0; i < 4; i++)
{
if(src & 0x80)
SDIO = 1;
else
SDIO = 0;
_nop_();
SCK = 1;
_nop_();
SCK = 0;
src = src << 1;
}
}
/*********************************************************************
** SetCH
*********************************************************************/
void SetCH(Uint8 ch)
{
//RF freq = RFbase + (CH_Step * ch)
A7125_WriteReg(PLL1_REG, ch);
}
/*********************************************************************
** initRF
*********************************************************************/
void initRF(void)
{
//init io pin
SCS = 1;
SCK = 0;
SDIO = 1;
CKO = 1;
GIO1 = 1;
GIO2 = 1;
A7125_Reset(); //reset A7105 RF chip
A7125_WriteID(); //write ID code
A7125_Config(); //config A7105 chip
A7125_Cal(); //calibration IF,vco, vcoc
}
/*********************************************************************
** A7125_WriteFIFO
*********************************************************************/
void A7125_WriteFIFO(void)
{
Uint8 i;
Uint8 cmd;
cmd = FIFO_REG; //send address 0x05, bit cmd=0, r/w=0
SCS=0;
ByteSend(cmd);
for(i=0; i <64; i++)
ByteSend(PN9_Tab[i]);
SCS=1;
}
/*********************************************************************
** Strobe Command
*********************************************************************/
void StrobeCmd(Uint8 cmd)
{
SCS = 0;
Send4Bit(cmd);
SCS = 1;
}
/*********************************************************************
** RxPacket
*********************************************************************/
void RxPacket(void)
{
Uint8 i;
Uint8 recv;
Uint8 tmp;
Uint8 cmd;
RxCnt++;
cmd = FIFO_REG | 0x40; //address 0x05, bit cmd=0, r/w=1
SCS=0;
ByteSend(cmd);
for(i=0; i <64; i++)
{
recv = ByteRead();
tmpbuf[i]=recv;
if((recv ^ PN9_Tab[i])!=0)
{
tmp = recv ^ PN9_Tab[i];
Err_BitCnt += (BitCount_Tab[tmp>>4] + BitCount_Tab[tmp & 0x0F]);
}
}
SCS=1;
}
/*********************************************************************
** Err_State
*********************************************************************/
void Err_State(void)
{
//ERR display
//Error Proc...
//...
while(1);
}
/*********************************************************************
** CHGroupCal
*********************************************************************/
void CHGroupCal(Uint8 ch)
{
Uint8 tmp;
Uint8 vb,vbcf;
Uint8 vcb,vccf;
A7125_WriteReg(PLL1_REG, ch);
A7125_WriteReg(CALIBRATION_REG, 0x1C);
do
{
tmp = A7125_ReadReg(CALIBRATION_REG);
tmp &= 0x1C;
}
while (tmp);
//for check
tmp = A7125_ReadReg(VCOCAL1_REG);
vb = tmp & 0x07;
vbcf = (tmp >>3) & 0x01;
tmp = A7125_ReadReg(VCOCCAL_REG);
vcb = tmp & 0x0F;
vccf= (tmp >> 4) & 0x01;
if (vbcf || vccf)
Err_State();//error
}
/*********************************************************************
** calibration
*********************************************************************/
void A7125_Cal(void)
{
Uint8 tmp;
Uint8 fb,fbcf,fcd;
Uint8 dvt;
//calibration RSSI,IF procedure
StrobeCmd(CMD_PLL);
A7125_WriteReg(CALIBRATION_REG, 0x03);
do
{
tmp = A7125_ReadReg(CALIBRATION_REG);
tmp &= 0x03;
}
while (tmp);
//calibration VCO dev,VBC,VCC procedure
CHGroupCal(30); //calibrate channel group Bank I
CHGroupCal(90); //calibrate channel group Bank II
CHGroupCal(150); //calibrate channel group Bank III
StrobeCmd(CMD_STBY); //return to STBY state
//for check
tmp = A7125_ReadReg(IFCAL1_REG);
fb = tmp & 0x0F;
fbcf = (tmp >>4) & 0x01;
tmp = A7125_ReadReg(IFCAL2_REG);
fcd = tmp & 0x1F;
tmp = A7125_ReadReg(VCOCAL2_REG);
dvt = tmp;
if (fbcf)
Err_State(); //error
}
/*********************************************************************
** A7125_Config
*********************************************************************/
void A7125_Config(void)
{
Uint8 i;
//0x00 mode register, for reset
//0x05 fifo data register
//0x06 id code register
//0x24 IF calibration II, only read
for (i=0x01; i<=0x04; i++)
A7125_WriteReg(i, A7125Config[i]);
for (i=0x07; i<=0x23; i++)
A7125_WriteReg(i, A7125Config[i]);
for (i=0x25; i<=0x38; i++)
A7125_WriteReg(i, A7125Config[i]);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -