头文件
/*************************************************************************************************************
* 文件名: A7139.h
* 功能: STM32 A7139驱动
* 作者: cp1300@139.com
* 创建时间: 2015-07-19
* 最后修改时间:2015-07-19
* 详细: A7139驱动
*************************************************************************************************************/
#ifndef __A7139_H__
#define __A7139_H__
#include "system.h"
#if(BOARD_SUPPORT) //需要板级支持
#include "board.h"
#else //默认支持
//三线spi
#define A7139_DIO_OUT PBout(10)
#define A7139_DIO_IN() PBin(10)
#define A7139_CS PBout(0)
#define A7139_CLK PBout(11)
#define A7139_OutMode() GPIOx_OneInit(GPIOB,10,OUT_PP,SPEED_50M)
#define A7139_InMode() GPIOx_OneInit(GPIOB,10,IN_IPU,IN_IN)
#define A7139_GIO1 PBin(1)
#define A7139_IO_INIT() \
DeviceClockEnable(DEV_GPIOB,ENABLE);/*使能GPIOA时钟*/\
GPIOx_Init(GPIOB,BIT0|BIT10|BIT11, OUT_PP, SPEED_50M);\
GPIOx_Init(GPIOB,BIT1, IN_IPT, IN_IN);\
#define A7139_IO_POWER_DOWN() \
DeviceClockEnable(DEV_GPIOB,ENABLE);/*使能GPIOA时钟*/\
GPIOx_Init(GPIOB,BIT0|BIT10|BIT11, IN_IPT, IN_IN);\
//接口
//DIO
#define A7139_DIO_H() (A7139_DIO_OUT=1) //输出1
#define A7139_DIO_L() (A7139_DIO_OUT=0) //输出0
#define A7139_CS_H() (A7139_CS=1)
#define A7139_CS_L() (A7139_CS=0)
#define A7139_CLK_H() (A7139_CLK=1)
#define A7139_CLK_L() (A7139_CLK=0)
#define A7139_GIO1_IN() (A7139_GIO1)
//中断
#define A7139_EnableNVIC() NVIC_IntEnable(IRQ_EXTI1,ENABLE) //总中断开启
#define A7139_DisableNVIC() NVIC_IntEnable(IRQ_EXTI1,DISABLE) //总中断关闭
#define A7139_EnableInt() EXTI_IntConfig(GPIO_B,1,PosEdge) //上升沿触发中断
#define A7139_DisableInt() EXTI_IntConfig(GPIO_B,1,OFF_INT) //关闭接收中断
//清除接收中断
#define A7139_ClearRxInt() EXTI_ClearInt(1) //清除中断
#endif
//控制寄存器
typedef enum
{
A7139_SCLOCK = 0x00, //系统时钟寄存器
A7139_PLL1 = 0x01, //PLL1
A7139_PLL2 = 0x02, //PLL2
A7139_PLL3 = 0x03, //PLL3
A7139_PLL4 = 0x04, //PLL4
A7139_PLL5 = 0x05, //PLL5
A7139_PLL6 = 0x06, //PLL6
A7139_CRYSTAL = 0x07, //晶振设置
A7139_PREG8S = 0x08, //寄存器组,由CRYSTAL控制切换
A7139_PREG9S = 0x09, //寄存器组,由CRYSTAL控制切换
A7139_RX1 = 0x0A, //接收设置1
A7139_RX2 = 0x0B, //接收设置2
A7139_ADC = 0x0C, //ADC
A7139_PIN = 0x0D, //PIN
A7139_CALIB = 0x0E, //Calibration
A7139_MODE = 0x0F, //模式控制
}A7139_CREG;
//控制寄存器组A
typedef enum
{
//寄存器8
A7139_REG8_TX1 = 0, //addr8 page0,
A7139_REG8_WOR1 = 1, //addr8 page1,
A7139_REG8_WOR2 = 2, //addr8 page2,
A7139_REG8_RF = 3, //addr8 page3,
A7139_REG8_POWER = 4, //addr8 page4,
A7139_REG8_AGCRC = 5, //addr8 page5,
A7139_REG8_AGCCON1 = 6, //addr8 page6,
A7139_REG8_AGCCON2 = 7, //addr8 page7,
A7139_REG8_GPIO = 8, //addr8 page8,
A7139_REG8_CKO = 9, //addr8 page9,
A7139_REG8_VCO = 10, //addr8 page10,
A7139_REG8_CHG1 = 11, //addr8 page11,
A7139_REG8_CHG2 = 12, //addr8 page12,
A7139_REG8_FIFO = 13, //addr8 page13,
A7139_REG8_CODE = 14, //addr8 page14,
A7139_REG8_WCAL = 15, //addr8 page15,
}A7139_PAGE_A;
//控制寄存器组B
typedef enum
{
//寄存器9
A7139_REG9_TX2 = 0, //addr9 page0,
A7139_REG9_IF1 = 1, //addr9 page1,
A7139_REG9_IF2 = 2, //addr9 page2,
A7139_REG9_ACK = 3, //addr9 page3,
A7139_REG9_ART = 4, //addr9 page4,
}A7139_PAGE_B;
//Strobe命令
typedef enum
{
A7139_WCR_CMD = 0x00, //写控制寄存器
A7139_RCR_CMD = 0x80, //读控制寄存器
A7139_WID_CMD = 0x20, //写ID
A7139_RID_CMD = 0xA0, //读ID
A7139_WFIFO_CMD = 0x40, //写FIFO
A7139_RFIFO_CMD = 0xC0, //读FIFO
A7139_RESRF_CMD = 0x70, //复位RF
A7139_RESTFIFO_CMD = 0x60, //复位发送FIFO
A7139_RESRFIFO_CMD = 0xE0, //复位接收FIFO
A7139_SLEEP_CMD = 0x10, //SLEEP模式
A7139_IDLE_CMD = 0x12, //IDLE模式
A7139_STBY_CMD = 0x14, //Standby模式
A7139_PLL_CMD = 0x16, //PLL模式
A7139_RX_CMD = 0x18, //RX模式
A7139_TX_CMD = 0x1A, //TX模式
A7139_TSLEEP_CMD = 0x1C, //Deep sleep 模式 三态
A7139_PSLEEP_CMD = 0x1F, //Deep sleep 模式 上拉
}A7139_STROBE_CMD;
//宏定义接口
#ifdef _UCOS_II_
#include "ucos_ii.h"
#define A7139_DelayMS(x) OSTimeDlyHMSM(0,0,0,x) //ms延时,最大999ms
#else
#include "delay.h"
#define A7139_DelayMS(x) Delay_MS(x)
#endif
//相关函数
void A7139_SoftReset(void); //A7139软复位
bool A7139_Init(u8 Channel, u16 RfID, u8 PowerSupply, u8 Rate); //A7139 初始化
void A7139_WriteReg(A7139_CREG RegAddr, u16 data); //写入控制寄存器
u16 A7139_ReadReg(A7139_CREG RegAddr); //读取控制寄存器
u32 A7139_ReadID(void); //读取A7139 ID
void A7139_WriteID(u32 ID); //设置A7139 ID
u16 A7139_ReadPageA(A7139_PAGE_A RegAddr); //读取控制寄存器组寄存器A
void A7139_WritePageA(A7139_PAGE_A RegAddr, u16 data);//写入控制寄存器组寄存器A
u16 A7139_ReadPageB(A7139_PAGE_B RegAddr); //读取控制寄存器组寄存器B
void A7139_WritePageB(A7139_PAGE_B RegAddr, u16 data);//写入控制寄存器组寄存器B
void A7139_RestRxFIFO(void); //A7139复位接收FIFO指针
void A7139_RestTxFIFO(void); //A7139复位发送FIFO指针
void A7139_ReadFIFO(u8 *pData, u8 DataLen); //A7139读取FIFO
void A7139_WriteFIFO(u8 *pData, u8 DataLen); //A7139写FIFO
void A7139_StrobeCmd(A7139_STROBE_CMD StrobeCmd); //A7139发送Strobe命令
void A7139_Config(void); //配置A7139
void A7139_SetFreq(float RfFreq); //A7139 配置RF频率
bool A7139_WaitRxData(u8 pData[64], u16 TimeOut); //等待接收数据
int A7139_GetRxLen(void);
bool A7139_SetRev(u8 *pRevBuff, u16 RevBuffSize);
bool A7139_SendData(u8 *pData, u16 DataLen); //A7139发送数据
void A7139_SetTxPowerSupply(u8 PowerSupply); //发射功率设置
#define A7139_ReadDeverID() (A7139_ReadPageB(A7139_REG9_TX2)) //读取设备硬件ID,只读
#define A7139_RestRxFIFO() A7139_StrobeCmd(A7139_RESRFIFO_CMD) //A7139复位接收FIFO指针
#define A7139_RestTxFIFO() A7139_StrobeCmd(A7139_RESTFIFO_CMD) //A7139复位发送FIFO指针
#define A7139_SoftReset() A7139_StrobeCmd(A7139_RESRF_CMD) //A7139软复位
#endif //A7139
|