nRF24L01 AVR 发送接收驱动程序
#include
#include"
12864.h"
//------------------------------------------------------------------------------
//spi标志
#define DDR_SPI DDRB
#define DD_MOSI 5
#define DD_MISO 6
#define DD_SCK 7
#define DD_SS 4
#define CE PB3
#define IRQ PB2
//--------------------------------NRF24L01
接口定义--------------------------------
//------------------------------------------------------------------------------
//#define NRF24L01_MISO
PB6
//输入0
#define
Hign_24L01_MISO
PORTB|=(1 << PB6)
#define
Low_24L01_MISO
PORTB &= ~(1 << PB6)
#define
Read_24L01_MISO
PINB & (1 << PB6)
//#define NRF24L01_MOSI
PB5
//输出1
#define
Hign_24L01_MOSI
PORTB |= (1 << PB5)
#define
Low_24L01_MOSI
PORTB &= ~(1 << PB5)
#define
Read_24L01_MOSI
PINB & (1 << PB5)
//#define NRF24L01_SCK
PB7
//输出1
#define
Hign_24L01_SCK
PORTB |= (1 << PB7)
#define
Low_24L01_SCK
PORTB &= ~(1 << PB7)
#define
Read_24L01_SCK
PINB & (1 << PB7);
//#define NRF24L01_CSN
PB4
//输出1
#define
Low_24L01_CSN
PORTB &= ~(1 << PB4)
#define
Hign_24L01_CSN
PORTB |= (1 << PB4)
//#define NRF24L01_CE
PB3
//输出1
#define
Hign_24L01_CE
PORTB |= (1 << PB3)
#define
Low_24L01_CE
PORTB &= ~(1 << PB3)
#define
Read_24L01_CE
PINB & (1 << PB3)
//*********************************************NRF24L01*************************************
#define TX_ADR_WIDTH
5
// 发送地址长度,最大长度为5 5*8=40 bit
#define RX_ADR_WIDTH
5
// 接收地址长度
#define TX_PLOAD_WIDTH
32
// 发送字节长度,
#define RX_PLOAD_WIDTH
32
// 接收字节长度
//***************************************NRF24L01寄存器指令*******************************************************
#define READ_REG
0x00
// 读寄存器指令
#define WRITE_REG
0x20
// 写寄存器指令
#define RD_RX_PLOAD
0x61
// 读取接收数据指令
#define WR_TX_PLOAD
0xA0
// 写待发数据指令
#define FLUSH_TX
0xE1
// 冲洗发送 FIFO指令
#define FLUSH_RX
0xE2
// 冲洗接收 FIFO指令
#define REUSE_TX_PL
0xE3
// 定义重复装载数据指令
#define NOP
0xFF
// 保留
//*************************************SPI(
nRF24L01)寄存器地址****************************************************
#define CONFIG
0x00
// 配置收发状态,CRC校验模式以及收发状态响应方式
#define EN_AA
0x01
// 自动应答功能设置
#define EN_RXADDR
0x02
// 可用信道设置
#define SETUP_AW
0x03
// 收发地址宽度设置
#define SETUP_RETR
0x04
// 自动重发功能设置
#define RF_CH
0x05
// 工作频率设置
#define RF_SETUP
0x06
// 发射速率、
功耗功能设置
#define STATUS
0x07
// 状态寄存器
#define OBSERVE_TX
0x08
// 发送监测功能
#define CD
0x09
// 地址检测
#define RX_ADDR_P0
0x0A
// 频道0接收数据地址
#define RX_ADDR_P1
0x0B
// 频道1接收数据地址
#define RX_ADDR_P2
0x0C
// 频道2接收数据地址
#define RX_ADDR_P3
0x0D
// 频道3接收数据地址
#define RX_ADDR_P4
0x0E
// 频道4接收数据地址
#define RX_ADDR_P5
0x0F
// 频道5接收数据地址
#define TX_ADDR
0x10
// 发送地址寄存器
#define RX_PW_P0
0x11
// 接收频道0接收数据长度
#define RX_PW_P1
0x12
// 接收频道0接收数据长度
#define RX_PW_P2
0x13
// 接收频道0接收数据长度
#define RX_PW_P3
0x14
// 接收频道0接收数据长度
#define RX_PW_P4
0x15
// 接收频道0接收数据长度
#define RX_PW_P5
0x16
// 接收频道0接收数据长度
#define FIFO_STATUS
0x17
// FIFO栈入栈出状态寄存器设置
//*************************************************************
//*************************************************
//*******
void spi_init()
初始化SPI
//**************************************************
void spi_init()
{
}
//**************************************************
//*******
uchar SPI_RW(uchar date)
读写SPI
//**************************************************
uchar SPI_RW(uchar date)
{
}
//**************************************************
//*******uchar SPI_Read(uchar reg)
读24L01寄存器
//**************************************************
uchar SPI_Read(uchar reg)
{
}
//**************************************************
//*******
uchar SPI_RW_Reg(uchar reg, uchar value)
//
写24L01寄存器
//**************************************************
uchar SPI_RW_Reg(uchar reg, uchar value)
{
}
//**************************************************
//*******
uchar SPI_Read_Buf(uchar reg, uchar *pBuf, uchar bites)
//
读24L01 寄存器BUFF
//**************************************************
uchar SPI_Read_Buf(uchar reg, uchar *pBuf, uchar bites)
{
}
//**************************************************
//*******
uchar SPI_Write_Buf(uchar reg, uchar *pBuf, uchar bites)
//
写24L01 寄存器BUFF
//**************************************************
uchar SPI_Write_Buf(uchar reg, uchar *pBuf, uchar bites)
{
}
//**************************************************
//*******
void SetRX_Mode(void)
//
接收模式设置
//**************************************************
void SetRX_Mode(void)
{
}
//**************************************************
//*******
uchar nRF24L01_RxPacket(uchar* rx_buf)
//
接收数据包
//**************************************************
uchar nRF24L01_RxPacket(uchar* rx_buf)
{
}
//**************************************************
//*******
void nRF24L01_TxPacket(uchar * tx_buf)
//
发送数据包
//**************************************************
void nRF24L01_TxPacket(
uchar * tx_buf)
{
}
void init_NRF24L01(void)
{
}
评论