我正在尝试使用SPI读取BMC150的ID寄存器。我正在使用STM32f103微控制器。串行时钟线正常,数据通过微控制器的MOSI正确发送。但没有通过MISO回复。我用示波器检查了信号。这是我的C代码的一部分。我该如何解决这个问题?谢谢。- while(1)
- {
- //Activate Slave
- SPI_GPIO->BRR = SPI_PIN_SS;
- // Go to active power mode
- SPI_I2S_SendData(SPIx, 0x4B01);
- while (!(SPIx->SR & (SPI_I2S_FLAG_TXE)));
- // delay for applying setting stably
- delay_ms(1);
- // Go to normal mode
- SPI_I2S_SendData(SPIx, 0x4C00);
- while (!(SPIx->SR & (SPI_I2S_FLAG_TXE)));
- delay_ms(1);
- // read request
- SPI_I2S_SendData(SPIx, 0xC000);
- while (!(SPIx->SR & (SPI_I2S_FLAG_RXNE)));
- while (SPIx->SR & (SPI_I2S_FLAG_BSY));
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
while1
{
//Activate Slave
SPI_GPIO->BRR = SPI_PIN_SS;
// Go to active power mode
SPI_I2S_SendData(SPIx, 0x4B01);
while (!(SPIx->SR & (SPI_I2S_FLAG_TXE)));
SPI_GPIO->BSRR = SPI_PIN_SS;
// delay for applying setting stably
delay_ms(1);
SPI_GPIO->BRR = SPI_PIN_SS;
// Go to normal mode
SPI_I2S_SendData(SPIx, 0x4C00);
while (!(SPIx->SR & (SPI_I2S_FLAG_TXE)));
SPI_GPIO->BSRR = SPI_PIN_SS;
delay_ms(1);
一周热门 更多>