SPI 在 STM32F103ZE 中读取数据为零
我使用的是STM32F103ZE 我没有正确获取 SPI 数据。 主机正在正确传输。 但在发送非零值时始终读取为零。
主配置:(MSP430)
The master configuration is correct. (I tested it.) Master Mode, MSB First, 8-bit SPI, Inactive state is high, SS grounded, 1 MHz clock, no dividers
从配置(STM32F103ZE)
Using SPI2. SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Rx SPI_InitStructure.SPI_Mode = SPI_Mode_Slave SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b SPI_InitStructure.SPI_CPOL = SPI_CPOL_High SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge SPI_InitStructure.SPI_NSS = SPI_NSS_Soft SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB SPI_InitStructure.SPI_CRCPolynomial = 7
任何人都有答案,
谢谢 哈里
I am using STM32F103ZE
I am not getting SPI data correctly.
Master is transmitting correctly.
But always read as zero where a non zero value has been sent.
Master config: (MSP430)
The master configuration is correct. (I tested it.) Master Mode, MSB First, 8-bit SPI, Inactive state is high, SS grounded, 1 MHz clock, no dividers
Slave Config (STM32F103ZE)
Using SPI2. SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Rx SPI_InitStructure.SPI_Mode = SPI_Mode_Slave SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b SPI_InitStructure.SPI_CPOL = SPI_CPOL_High SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge SPI_InitStructure.SPI_NSS = SPI_NSS_Soft SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB SPI_InitStructure.SPI_CRCPolynomial = 7
Anybody have an ANSWER,
Thanks
Hari
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道,这个问题很老了。不过,由于我最近几天也遇到了同样的问题,我会尽力为未来的读者提供答案。
以下代码适用于 STM32F407,该代码用于 STM32 发现板。从数据表中我可以看到,SPI外设与STM32F103上的相同,所以
我希望代码无需修改即可在另一个微控制器上运行。
此初始化过程与问题中发布的代码有两点不同:
不要为具有 3 条线 SCK、MISO 和 MOSI 的普通 SPI 选择双向模式。
MISO和MOSI都是单向线。
我使用硬件从机选择管理,即未设置位
SSM
。这样,SPI 外设可以自动检测设备何时被置位(引脚
NSS 变低)并将
将 MOSI 位存储在移位寄存器中。当读取了足够的位(8 或
16 取决于所选的数据格式),
标志
RXNE
被设置在状态寄存器中并且可以读取传输的值来自寄存器
DR
。希望有帮助。
I know, the question is quite old. Still, since I have faced the same problem the last days, I'll try to give an answer for future readers.
The following code works on the STM32F407, which is used on the STM32 discovery board. What I can see from the datasheet, the SPI peripheral is the same as on the STM32F103, so
I expect the code to run on the other microcontroller without modifications.
Two things are different in this initialization procedure from the code posted in the question:
Do not select bidirectional mode for ordinary SPI with the 3 lines SCK, MISO and MOSI.
Both MISO and MOSI are unidirectional lines.
I use hardware slave select management, i.e. the bit
SSM
is not set. This way, theSPI peripheral can automatically detect when the device has been asserted (the pin
NSS goes low) and will
store the MOSI bits in a shift register. When enough bits have been read (8 or
16 depending on the selected data format),
the flag
RXNE
is set in the status register and the transmitted value can be readfrom the register
DR
.Hope that helps.
我在从数据寄存器获取 0x00 值时遇到了完全相同的问题。
就我而言,问题是 MISO 线被设置为浮动输入。改成OType_PP后就可以了。这是我的STM32F429的配置代码:
和发送功能:
I had exactly the same problem of getting 0x00 value from data register.
In my case the problem was that MISO line was set as floating input. It works after changing it to OType_PP. Here is my configuration code for STM32F429:
And sending function: