IdeaMing·www.littlebutler.top
March 19, 2018 Version_1.0.0 1 / 8
STM32F030C8 配置 NRF24L01
前言:
虽然 STM32F103 会用了 NRF24L10,可是到了 STM32F030 还是有些配置上的区别,为了加快各位研发
人员的开发进度,避免浪费大量的时间在硬件平台上,写出个人代码调试的经验。个人水平有限,如有错
误,还请指正 mr.li.ming@qq.com。
提示:使用的内部 RC 时钟,最大速度 48MHz.
第一步:初始化端口
/*******************************************************************************
* @brief 初始化端口 因为 CSN 用的 PB12 CE 用的 PA11 所以两个时钟都要开
* @param None
* @retval None
****************************************************************Author:Liming**/
void NRF24L01_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB,ENABLE);//使能端口 A/B 时钟
GPIO_InitStructure.GPIO_Pin = SPI2_CE_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;
GPIO_Init(SPI2_CE_PORT,&GPIO_InitStructure); //CE 控制脚
GPIO_InitStructure.GPIO_Pin = SPI2_CSN_PIN;
GPIO_Init(SPI2_CSN_PORT,&GPIO_InitStructure); //CSN 控制脚
GPIO_ResetBits(SPI2_CE_PORT,SPI2_CE_PIN);
GPIO_SetBits(SPI2_CSN_PORT,SPI2_CSN_PIN);
GPIO_InitStructure.GPIO_Pin = SPI2_SCK_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
评论2