|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2011-4-28 10:59:33
|
显示全部楼层
/**************************************************
功能:RF初始化
**************************************************/
void rf_init(void) {
RFCE = 0; // RF关闭
RFCKEN = 1; // 启动RF时钟
RF = 1; // 允许RF中断
delay(1000);
SPI_RW_Reg(WRITE_REG + SETUP_AW, 0x01); //设置地址长度0~1位[00:无效 01:3字节长度 10:4字节长度 11:5字节长度]
SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH); // 设置发射地址
SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH); // 设置接收地址长度
SPI_RW_Reg(WRITE_REG + FEATURE, 0x06); //1位允许,使能动态载荷长度,使能带载荷ACK
SPI_RW_Reg(WRITE_REG + DYNPD, 0x01); //使能数据通道0动态载荷长度
SPI_Write_Buf(W_ACK_PAYLOAD, TX_ADD, 4);
SPI_RW_Reg(WRITE_REG + EN_AA, 0x01); // 启动自动应答功能 数据通道0
SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01); // PIPE0接收数据
SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x10); // 自动重传10次
SPI_RW_Reg(WRITE_REG + RF_CH, 0x40); // RF频率2440MHz
SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07); // 发射功率0dBm, 传输速率2Mbps,
SPI_RW_Reg(WRITE_REG + RX_PW_P0, TX_PLOAD_WIDTH); // PIPE0 接收数据包长度
} |
|