?? radioinit.c
字號:
/*******************************************************************
*
* DESCRIPTION: 射頻NA5TR1的初始化程序
*
* AUTHOR:
*
* HISTORY:
*
* DATE:2008-6-14
*
*******************************************************************/
/** include files **/
#include "includes.h"
#include "radio.h"
/** local definitions **/
/* default settings */
/**
* 初始化射頻芯片的中斷口
*
*/
void RadioVectorInit(void);
/**
* 初始化射頻的SPI口
*
*/
void RadioSpiInit(void);
/**
* 初始化射頻芯片想關的GPIO
*
*/
void RadioGPIOInit(void);
/** external functions **/
/** external data **/
/** internal functions **/
/** public data **/
/** private data **/
/** public functions **/
/**
* 射頻芯片有關的初始化
*
*/
void RadioInit(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_SPI1|RCC_APB2Periph_AFIO, ENABLE);
RadioGPIOInit();
RadioSpiInit();
RadioVectorInit();
}
/** private functions **/
/**
* 初始化射頻的SPI口
*
*/
void RadioSpiInit(void)
{
SPI_InitTypeDef SPI_InitStructure;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1,ENABLE);
}
/**
* 初始化射頻芯片想關的GPIO
*
*/
void RadioGPIOInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure SPI1 pins: SCK, MISO and MOSI ---------------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//PA.2 中斷輸入腳
GPIO_InitStructure.GPIO_Pin = NANO_INT_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(NANO_INT_CTRL_PORT, &GPIO_InitStructure);
//PA.1 reset 腳
GPIO_InitStructure.GPIO_Pin = NANO_RESET_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(NANO_RST_CTRL_PORT, &GPIO_InitStructure);
//PB.11 SPI CS腳
GPIO_InitStructure.GPIO_Pin = NANO_CS_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(NANO_CS_CTRL_PORT, &GPIO_InitStructure);
}
/**
* 初始化射頻芯片的中斷口
*
*/
void RadioVectorInit(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource12);
/* Configure EXTI Line2 to generate an interrupt on falling edge */
EXTI_InitStructure.EXTI_Line = EXTI_Line2;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the EXTI2 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -