完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
tica, Tahoma, Arial, sans-serif;font-size:14px;line-height:24px;background-color:#f5f5f5;">自己做的两个STM32F405RG的板子,想用NRF24L01进行无线通讯。
编写的代码在早上的时候用一个板子收一个板子发是能够发送且受到数据的,单步调试验证过。 但将板子的收发功能对调就不能传输成功。。 单步调试发现程序运行到while(NRF24L01_IRQ!=0);就一直在等待。。。 然后配置如下: SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; 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_16; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); void NRF24L01_RX_Mode(void) { NRF24L01_CE=0; NRF24L01_Write_Buf(WRITE_REG_NRF+RX_ADDR_P0,(u8*)RX_ADDRESS,RX_ADR_WIDTH); NRF24L01_Write_Reg(WRITE_REG_NRF+EN_AA,0x01); NRF24L01_Write_Reg(WRITE_REG_NRF+EN_RXADDR,0x01); NRF24L01_Write_Reg(WRITE_REG_NRF+RF_CH,40); NRF24L01_Write_Reg(WRITE_REG_NRF+RX_PW_P0,RX_PLOAD_WIDTH); NRF24L01_Write_Reg(WRITE_REG_NRF+RF_SETUP,0x0f); NRF24L01_Write_Reg(WRITE_REG_NRF+CONFIG, 0x0f); NRF24L01_CE = 1; } void NRF24L01_TX_Mode(void) { NRF24L01_CE=0; NRF24L01_Write_Buf(WRITE_REG_NRF+TX_ADDR,(u8*)TX_ADDRESS,TX_ADR_WIDTH); NRF24L01_Write_Buf(WRITE_REG_NRF+RX_ADDR_P0,(u8*)RX_ADDRESS,RX_ADR_WIDTH); NRF24L01_Write_Reg(WRITE_REG_NRF+EN_AA,0x01); NRF24L01_Write_Reg(WRITE_REG_NRF+EN_RXADDR,0x01); NRF24L01_Write_Reg(WRITE_REG_NRF+SETUP_RETR,0x1a); NRF24L01_Write_Reg(WRITE_REG_NRF+RF_CH,40); NRF24L01_Write_Reg(WRITE_REG_NRF+RF_SETUP,0x0f); NRF24L01_Write_Reg(WRITE_REG_NRF+CONFIG,0x0e); NRF24L01_CE=1; } |
|
相关推荐
7个回答
|
|
|
|
|
|
也不行了。它一直停在while(NRF24L01_IRQ!=0);这句上。 初始化的代码是用战舰的初始化 void NRF24L01_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC, ENABLE); //scn???ì???????? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB,GPIO_Pin_12); //CE pc11 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_SetBits(GPIOC,GPIO_Pin_11); //IRQ C12 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOC, &GPIO_InitStructure); SPI2_Init(); SPI_Cmd(SPI2, DISABLE); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; 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_16; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); SPI_Cmd(SPI2, ENABLE); NRF24L01_CE=0; NRF24L01_CSN=1; } void SPI2_Init(void)//??????SPI2 { GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOB, ENABLE ); RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; 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_DOWN; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2); GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2); GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2); GPIO_SetBits(GPIOB,GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); //PB13/14/15 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //high?2edge? SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); SPI_Cmd(SPI2, ENABLE); SPI2_ReadWriteByte(0xff); } 这代码早上还好使,现在即使换过来也不行。在调试的时候它出现过一次status寄存器的值为0x2e,之后就一直停在等待发送的循环语句了 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
找到问题了,忘了给IRQ,CS,CE管脚resetbits了。。加了这句以后就好了。。默默的还是不知道为什么
|
|
|
|
只有小组成员才能发言,加入小组>>
如何使用STM32+nrf24l01架构把有线USB设备无线化?
2574 浏览 7 评论
请问能利用51单片机和nRF24L01模块实现实时语音无线传输吗?
2368 浏览 5 评论
3225 浏览 3 评论
2842 浏览 8 评论
为什么ucosii上移植lwip后系统进入了HardFault_Handler?
2795 浏览 4 评论
请教各位大咖:有没有接收频率32M左右的芯片推荐的?先感谢啦!
678浏览 1评论
914浏览 0评论
1035浏览 0评论
677浏览 0评论
509浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 23:18 , Processed in 1.253774 second(s), Total 91, Slave 74 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号