stm32 32位 发射(硬件SPI 引脚重映射):
#include "stm32f10x_lib.h"
#include "sys_config.h"
#include "usart.h"
#include "nrf.h"
#include "delay.h"
extern u8 TX_ADDRESS[TX_ADR_WIDTH]; //调用外部变量,必须声明!!!!!!!
extern u8 RX_ADDRESS[RX_ADR_WIDTH];
#define uchar unsigned char
#define uint unsigned int
unsigned char TxBuf[32]=
{
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f
};
void Delayms(vu32 m)
{
u32 i;
for(; m != 0; m--)
for (i=0; i<10000; i++);
}
int main(void)
{
u8 status;
RCC_Configuration();
Delay_Init(72);
USART1_Configuration();
SPI_NRF_Init();
status=NRF_Check();
// while(status==0) //没有连接成功,灯一直闪烁
// {
// GPIO_ResetBits(GPIOA,GPIO_Pin_4); //至零灯灭
// Delayms(100);
// GPIO_SetBits(GPIOA,GPIO_Pin_4); //至一灯亮
// Delayms(100);
// status=NRF_Check();
// }
status=0;
NRF_TX_Mode();
while(1)
{
status=NRF_Tx_Dat(TxBuf) ;
if(status!=0);
Delayms(1000);
}
}
stm32 32位 接收(硬件SPI 引脚重映射):
#include "stm32f10x_lib.h"
#include "sys_config.h"
#include "usart.h"
#include "nrf.h"
#include "delay.h"
extern u8 TX_ADDRESS[TX_ADR_WIDTH]; //调用外部变量,必须声明!!!!!!!
extern u8 RX_ADDRESS[RX_ADR_WIDTH];
#define uchar unsigned char
#define uint unsigned int
void Delayms(vu32 m)
{
u32 i;
for(; m != 0; m--)
for (i=0; i<10000; i++);
}
int main(void)
{
u8 rxbuf[32];
u8 status;
u8 i;
RCC_Configuration();
Delay_Init(72);
USART1_Configuration();
SPI_NRF_Init();
status=NRF_Check();
// while(status==0) //没有连接成功,灯一直闪烁
// {
// USART1_SendData(0); //至零灯灭
// Delayms(100);
// status=NRF_Check();
// }
status=0;
NRF_RX_Mode();
while(1)
{
status=NRF_Rx_Dat(rxbuf);
if(status==1)
for(i=0;i<32;i++)
USART1_SendData(rxbuf[i]);
else
Delayms(1000);
}
}