STM32 驱动无线NRF24L01 完成串口数据传输
// SPI(nRF24L01) registers(addresses)
#define CONFIG 0x00 // Config register address
#define EN_AA 0x01 // Enable Auto Acknowledgment register address
#define EN_RXADDR 0x02 // Enabled RX addresses register address
#define SETUP_AW 0x03 // Setup address width register address
#define SETUP_RETR 0x04 // Setup Auto. Retrans register address
#define RF_CH 0x05 // RF channel register address
#define RF_SETUP 0x06 // RF setup register address
#define STATUS 0x07 // Status register address
#define OBSERVE_TX 0x08 // Observe TX register address
#define CD 0x09 // Carrier Detect register address
#define RX_ADDR_P0 0x0A // RX address pipe0 register address
#define RX_ADDR_P1 0x0B // RX address pipe1 register address
#define RX_ADDR_P2 0x0C // RX address pipe2 register address
#define RX_ADDR_P3 0x0D // RX address pipe3 register address
#define RX_ADDR_P4 0x0E // RX address pipe4 register address
#define RX_ADDR_P5 0x0F // RX address pipe5 register address
#define TX_ADDR 0x10 // TX address register address
#define RX_PW_P0 0x11 // RX payload width, pipe0 register address
#define RX_PW_P1 0x12 // RX payload width, pipe1 register address
#define RX_PW_P2 0x13 // RX payload width, pipe2 register address
#define RX_PW_P3 0x14 // RX payload width, pipe3 register address
#define RX_PW_P4 0x15 // RX payload width, pipe4 register address
#define RX_PW_P5 0x16 // RX payload width, pipe5 register address
#define FIFO_STATUS 0x17 // FIFO Status Register register address
#endif /* _API_DEF_ */
#ifndef HAL_H
#define HAL_H
//硬件初始化
extern void ChipHalInit(void);
extern void ChipOutHalInit(void);
extern void delay_ms(u16 dly_ms);
extern void USART_Configuration(void);
extern void RF_SPI_Config(void);
extern volatile u16 Timer1,Timer2;
//RF_2401
extern void init_io(void);
extern void test (void);
extern u8 tran;//中断进入标志
extern u8 SPI_Read(u8 reg);
extern u8 SPI_RW(u8 byte);
#define TX_ADR_WIDTH 5 // 5字节宽度的发送/接收地址
#define TX_PLOAD_WIDTH 32 // 接收字节数32个字
#define uchar u8
/*控制引脚*/
#define CE_HGPIOC->BSRR=GPIO_Pin_4
#define CE_LGPIOC->BRR=GPIO_Pin_4
#define CSN_HGPIOB->BSRR=GPIO_Pin_2
#define CSN_LGPIOB->BRR=GPIO_Pin_2
#define IRQ(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0))
#define IRQ_HGPIOB->BSRR=GPIO_Pin_0
#define LED1GPIOB->BSRR=GPIO_Pin_12
#define LED0GPIOB->BRR=GPIO_Pin_12
#define LED GPIOB->ODR=((GPIOD->ODR)^GPIO_Pin_12)
#define RX_DR ((sta>>6)&0X01)
#define TX_DS ((sta>>5)&0X01)
#define MAX_RT ((sta>>4)&0X01)
//USART
extern void USART2_Putc(unsigned char c);
extern void USART2_Puts(char * str);
extern u16 Uart2_Get_Flag;//串口2接收到数据长度
extern u8 Uart2_Get_Data;//串口2接收的数据
#endif
中断用前注意优先级的设置
#include "STM32Lib\\stm32f10x.h"
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* 配置中断使用组合1*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* EXTI0*/
NVIC_InitStructure.NVIC_IRQChannel =EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/*UART2*/
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
STM32驱动无线NRF24L01串口数据传 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)