完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
void NRF24L01_Configuration(void)
{ GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); // RCC_APB2PeriphClockCmd(RCC_NRF24L01_CE, ENABLE); //ʹÄÜGPIOµÄʱÖÓ GPIO_InitStructure.GPIO_Pin = NRF24L01_CE; //NRF24L01 Ä£¿éƬѡÐźŠGPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //ÍÆÍìÊä³ö GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIO_NRF24L01_CE, &GPIO_InitStructure); // RCC_APB2PeriphClockCmd(RCC_NRF24L01_CSN, ENABLE); //ʹÄÜGPIOµÄʱÖÓ GPIO_InitStructure.GPIO_Pin = NRF24L01_CSN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //ÍÆÍìÊä³ö GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIO_NRF24L01_CSN, &GPIO_InitStructure); Set_NRF24L01_CE; Set_NRF24L01_CSN; //ÅäÖÃNRF2401µÄIRQ GPIO_InitStructure.GPIO_Pin = NRF24L01_IRQ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN ; //ÉÏÀÊäÈë GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIO_NRF24L01_IRQ, &GPIO_InitStructure); GPIO_SetBits(GPIO_NRF24L01_IRQ,NRF24L01_IRQ); SPI1_Configuration(); //³õʼ»¯SPI Clr_NRF24L01_CE; //ʹÄÜ24L01 Set_NRF24L01_CSN; //SPIƬѡȡÏû } void SPI1_Configuration(void) { SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA,GPIO_PinSource5|GPIO_PinSource6|GPIO_PinSource7,GPIO_AF_0);//Á¬½Óµ½ÍâÉè // GPIO_SetBits(GPIOA,GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7); GPIO_ResetBits(GPIOA, GPIO_Pin_1); // SPI_I2S_DeInit(SPI1); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //ÉèÖÃSPIµ¥Ïò»òÕßË«ÏòµÄÊý¾Ýģʽ:SPIÉèÖÃΪ˫ÏßË«ÏòÈ«Ë«¹¤ SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //ÉèÖÃSPI¹¤×÷ģʽ:ÉèÖÃΪÖ÷SPI SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //ÉèÖÃSPIµÄÊý¾Ý´óС:SPI·¢ËͽÓÊÕ8λ֡½á¹¹ SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //Ñ¡ÔñÁË´®ÐÐʱÖÓµÄÎÈ̬:ʱÖÓÐü¿Õ¸ß SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //Êý¾Ý²¶»ñÓÚµÚ¶þ¸öʱÖÓÑØ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //NSSÐźÅÓÉÓ²¼þ£¨NSS¹Ü½Å£©»¹ÊÇÈí¼þ£¨Ê¹ÓÃSSI룩¹ÜÀí:ÄÚ²¿NSSÐźÅÓÐSSIλ¿ØÖÆ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; //¶¨Ò岨ÌØÂÊÔ¤·ÖƵµÄÖµ:²¨ÌØÂÊÔ¤·ÖƵֵΪ256 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //Ö¸¶¨Êý¾Ý´«Êä´ÓMSBλ»¹ÊÇLSBλ¿ªÊ¼:Êý¾Ý´«Êä´ÓMSBλ¿ªÊ¼ SPI_InitStructure.SPI_CRCPolynomial = 7; //CRCÖµ¼ÆËãµÄ¶àÏîʽ SPI_RxFIFOThresholdConfig(SPI1,SPI_RxFIFOThreshold_QF);//ÅäÖà SPI µÄ FIFO ½ÓÊÕãÐÖµ(½ÓÊÕ8bits¾ÍÖà SPI_I2S_FLAG_RXNE) SPI_Init(SPI1, &SPI_InitStructure); //¸ù¾ÝSPI_InitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèSPIx¼Ä´æÆ÷ SPI_Cmd(SPI1, ENABLE); //ʹÄÜSPIÍâÉè // SPI1_ReadWriteByte(0xff); GPIO_SetBits(GPIOA, GPIO_Pin_1); } u8 SPI1_ReadWriteByte(u8 TxData) //SPI¶ÁдÊý¾Ýº¯Êý { while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); SPI_SendData8(SPI1, TxData); // SPI_I2S_SendData16(SPI1, TxData); while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); return SPI_ReceiveData8(SPI1); // return SPI_I2S_ReceiveData16(SPI1); } 各位大神看看哪里出问题了啊! |
|
相关推荐
20个回答
|
|
出什么问题了,也没讲啊
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1276 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1209 浏览 3 评论
2288 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1372 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1799 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 06:31 , Processed in 0.401388 second(s), Total 42, Slave 36 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号