#include "24l01.h"
#include "lcd.h"
#include "delay.h"
#include "spi.h"
//
//NRF24L01驱动代码
//
const u8 TX_ADDRESS[TX_ADR_WIDTH]={0x34,0x43,0x10,0x10,0x01}; //发送地址
const u8 RX_ADDRESS[RX_ADR_WIDTH]={0x34,0x43,0x10,0x10,0x01}; //发送地址
//初始化24L01的IO口
void NRF24L01_Init(void)
{
RCC->APB2ENR|=1<<3; //使能PORTB时钟
RCC->APB2ENR|=1<<5; //使能PORTD时钟
RCC->APB2ENR|=1<<8; //使能PORTG时钟
//这里pb12和pd2拉高,是为了防止互相影响 .
//因为他们共用一个SPI口.
GPIOB->CRH&=0XFFF0FFFF;
GPIOB->CRH|=0X00030000; //PB12 推挽
GPIOB->ODR|=1<<12; //PB12上拉 防止W25X的干扰
GPIOD->CRL&=0XFFFFF0FF;
GPIOD->CRL|=0X00000300; //PD2 推挽
GPIOD->ODR|=1<<2; //PD2上拉 禁止SD卡的干扰
GPIOG->CRL&=0X00FFFFFF;
GPIOG->CRL|=0X33000000; //PG6 7 推挽
GPIOG->CRH&=0XFFFFFFF0;
GPIOG->CRH|=0X00000008; //PG8 输入
GPIOG->ODR|=7<<6; //PG6 7 8 上拉
SPI2_Init(); //初始化SPI
//针对NRF的特点修改SPI的设置
SPI2->CR1&=~(1<<6); //SPI设备失能
SPI2->CR1&=~(1<<1); //空闲模式下SCK为0 CPOL=0
SPI2->CR1&=~(1<<0); //数据采样从第1个时间边