⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 send.c

📁 A7125无线模块
💻 C
📖 第 1 页 / 共 2 页
字号:
        _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;
}


/*********************************************************************
** Strobe Command
*********************************************************************/
void StrobeCmd(Uint8 src)
{
    Uint8 i;

    SCS = 0;
    for(i = 0; i < 8; i++)
    {
        if(src & 0x80)
            SDIO = 1;
        else
            SDIO = 0;

        _nop_();
        SCK = 1;
        _nop_();
        SCK = 0;
        src = src << 1;
    }
    SCS = 1;
}

/************************************************************************
**  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;
    }
}

/************************************************************************
**  WriteID
************************************************************************/
void A7125_WriteID(void)
{
    Uint8 i;
    Uint8 addr;

    addr = IDCODE_REG; //send address 0x06, bit cmd=0, r/w=0
    SCS = 0;
    ByteSend(addr);
    for (i=0; i < 4; i++)
        ByteSend(ID_Tab[i]);
    SCS = 1;
}

/************************************************************************
**  Reset_RF
************************************************************************/
void A7125_Reset(void)
{
    A7125_WriteReg(MODE_REG, 0x00); //reset RF chip
}
/*********************************************************************
** 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<=0x38; i++ )
    {
        if ( (i==0x05) || (i==0x06) || (i==0x24) )
            continue;

        A7125_WriteReg( i, A7125Config[i] );
    }
}

/*********************************************************************
** initRF
*********************************************************************/
void initRF(void)
{
    //init io pin
    SCS = 1;
    SCK = 0;
    SDIO = 1;
    GIO1 = 1;
    GIO2 = 1;

    A7125_Reset();      //reset A7125 RF chip
    A7125_WriteID();    //write ID code
    A7125_Config();     //config A7125 chip
    A7125_Cal();        //calibration IF,vco, vcoc
}

//**********************************************************************
//  WriteFIFO
//**********************************************************************
void WriteFIFO(Uint8 length)
{
    Uint8 i;
    A7125_WriteReg( FIFO1_REG, length-1);   // set FIFO length
    StrobeCmd(CMD_TFR);                     // Reset TX FIFO point
    
    SCS=0;
    ByteSend(FIFO_REG);
    for(i=0; i <length; i++)
        ByteSend(PN9_Tab[i]);
    SCS=1;
}
//**********************************************************************
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;
}
//**********************************************************************
//  ReadFIFO
//**********************************************************************
void ReadFIFO(Uint8 length)
{
    Uint8 i;

    SCS = 0;
    ByteSend(FIFO_REG | 0x40);
    for(i = 0; i <length; i++)
        RfBuf[i] = ByteRead();
    SCS=1;
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
//                      DELAY 1MS FUNCTION                          //
//           USER NEED CHANGE THIS FUNCTION TO FIT SYSTEM.          //
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void Delay1ms(Uint16 n)
{
    Uint8 i, j;
    while(n--)
    {
        for(j = 0; j < 6; j ++)
        {
            for(i = 0; i < 235; i ++)
            {
                _nop_();
                _nop_();
                _nop_();
                _nop_();
            }
        }
    }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -