Depending on the data frame format selection bit (DFF in SPI_CR1 register), the data sent or received is either 8-bit or 16-bit. This selection has to be made before enabling the SPI to ensure correct operation.
For an 8-bit data frame, the buffers are 8-bit and only the LSB of the register (SPI_DR[7:0]) is used for transmission/reception. When in reception mode, the MSB of the register (SPI_DR[15:8]) is forced to 0.
For a 16-bit data frame, the buffers are 16-bit and the entire register, SPI_DR[15:0] is used for transmission/reception.
而且,SPIx->DR本身的确是16-bit的寄存器。
-------------
如果能仔细阅读代码,在SPI初始化里,有设置SPI的位宽:
很明显。,它可以选择8-bit还是16-bit。
意思是,只要在SPI初始化里面设置为8位,即使读写是16位也只是使用其低8位是吗?
是的。第二个截图,已经说的很详细了,摘录如下:
谢谢,我只是不敢肯定,想有个准确回答!
一周热门 更多>