新手入门
- 积分
- 28
- 金钱
- 28
- 注册时间
- 2012-10-30
- 在线时间
- 0 小时
|
高手帮帮忙,我自己的板子上有nrf24l01芯片,但是现在和原子哥的开发板上面的nrf24l01通信无法进行,开始的硬件检查不能通过,经示波器测试,控制器的SPI引脚输出波形,但是就是不能定位到问题原因。<br />
听原子哥说可能是SPIS的初始化有问题。SPI的初始化代码(我用的是STM32F4的芯片)如下,检查很多次了,应该没问题的,<br />
<div>void SPI1_Init(u8 SpeedSet)<span class="Apple-tab-span" style="white-space:pre;"> </span> //nrf24l01</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>GPIO_InitTypeDef GPIO_InitStructure;</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_InitTypeDef SPI_InitStructure;</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); <span class="Apple-tab-span" style="white-space:pre;"> </span> //使能IO口时钟</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE );<span class="Apple-tab-span" style="white-space:pre;"> </span> //APB2</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span></div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>GPIO_PinAFConfig(GPIOA, GPIO_PinSource5|GPIO_PinSource6|GPIO_PinSource7, GPIO_AF_SPI1);<span class="Apple-tab-span" style="white-space:pre;"> </span> //启动复用功能</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span></div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //PA5(SCK)、PA6(MISO)、PA7(MOSI)</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> <span class="Apple-tab-span" style="white-space:pre;"> </span>GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> <span class="Apple-tab-span" style="white-space:pre;"> </span>GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> <span class="Apple-tab-span" style="white-space:pre;"> </span>GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;</div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>GPIO_Init(GPIOA, &GPIO_InitStructure);</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;<span class="Apple-tab-span" style="white-space:pre;"> </span>//PA4(CS)<span class="Apple-tab-span" style="white-space:pre;"> </span></div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;<span class="Apple-tab-span" style="white-space:pre;"> </span> //输出</div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span> GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;<span class="Apple-tab-span" style="white-space:pre;"> </span> //推挽</div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;<span class="Apple-tab-span" style="white-space:pre;"> </span> //50Hz</div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span> GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;<span class="Apple-tab-span" style="white-space:pre;"> </span> //上拉</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>GPIO_Init(GPIOA, &GPIO_InitStructure);</div>
<div><br />
</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> <span class="Apple-tab-span" style="white-space:pre;"> </span>GPIO_SetBits(GPIOA,GPIO_Pin_4);<span class="Apple-tab-span" style="white-space:pre;"> </span> //强制输出高电平,不选中芯片</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span></div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> SPI_I2S_DeInit(SPI1);</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //设置SPI单向或者双向的数据模式:SPI设置为双线双向全双工</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_InitStructure.SPI_Mode = SPI_Mode_Master;<span class="Apple-tab-span" style="white-space:pre;"> </span>//设置SPI工作模式:设置为主SPI</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;<span class="Apple-tab-span" style="white-space:pre;"> </span>//设置SPI的数据大小:SPI发送接收8位帧结构</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;<span class="Apple-tab-span" style="white-space:pre;"> </span>//选择了串行时钟的稳态:时钟悬空高</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;<span class="Apple-tab-span" style="white-space:pre;"> </span>//数据捕获于第二个时钟沿</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;<span class="Apple-tab-span" style="white-space:pre;"> </span>//NSS信号由硬件(NSS管脚)还是软件(使用SSI位)管理:内部NSS信号由SSI位控制</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_InitStructure.SPI_BaudRatePrescaler = SpeedSet ;<span class="Apple-tab-span" style="white-space:pre;"> </span>//定义波特率预分频的值:波特率预分频值为256</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;<span class="Apple-tab-span" style="white-space:pre;"> </span>//指定数据传输从MSB位还是LSB位开始:数据传输从MSB位开始</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_InitStructure.SPI_CRCPolynomial = 7;<span class="Apple-tab-span" style="white-space:pre;"> </span>//CRC值计算的多项式</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_Init(SPI1, &SPI_InitStructure); //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>SPI_Cmd(SPI1, ENABLE); //使能SPI外设</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>}<br />
求助啊!!!会不会是nrf24l01芯片没有焊好啊!!!</div> |
|