0
\$\begingroup\$

I am trying to read ID register of BMC150 using SPI. I am using stm32f103 microcontroller. Serial clock line is OK and the data is sent properly over MOSI of microcontroller. But no response is sent back through MISO. I have checked signals using oscilloscope. Here is a part of my C code. How can I resolve this issue? Thanks.

    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));
    }
\$\endgroup\$
  • \$\begingroup\$ Is the CS pin low? \$\endgroup\$ – Turbo J Aug 24 '18 at 13:37
  • \$\begingroup\$ Did you measure this with the scope or a multimeter? That line says nothing since we don't see the value of SPI_PIN_SS. There is a really good chance this line does not do what you think it does. \$\endgroup\$ – Turbo J Aug 24 '18 at 17:40
  • \$\begingroup\$ Dear @TurboJ , You are right, I wil check it again. Thanks. \$\endgroup\$ – Mr. Nobody Aug 24 '18 at 21:30
1
\$\begingroup\$

I solved the problem by activating and deactivating slave (using chip or slave select pin) before and after writing process as follows:

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)));
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);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.