uint8_t address = 0x00;
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, &address, 1, 100);
HAL_SPI_Receive(&hspi1, &result, 1, 100);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
Since it is in the infinite while loop, for the first two loop cycles I am getting 0xFF in the result. Then in the next two loop cycles, I am getting the correct Chip Id which is 0xFA. Then I am getting 0xFF in the next two loop cycles and this pattern is alternating infinitely.
I am not able to understand why I am receiving 0xFF and then 0xFA.
Could there be a problem with the delay mismatch? I feel that 100ms should be fine.
I also feel that the SPI Receive is being incorrectly implemented. I am worrying because since SPI Read is an important function in retrieving the acceleration data, this function is the key.
I request anyone to please suggest me on what to do to get it working perfectly. Any help would be highly appreciated.
Thanks in advance.
Solved! Go to Solution.
Thanks for your inquiry. BMA253 supports SPI interface mode 0 and 3. The maximum SPI clock frequency is 10MHz. We have BMA253 shuttle board and APP2.0 base board availalbe in distributors such as Digikey, Mouser, Arrow and Future. You can purchase the eval. boards and then use logic analyzer to monitor the SPI bus to see how the waveforms look like. Then you can check the SPI communication on your own board.
Most likely the issue comes from STM32 MCU SPI controller. Please ask them for technical support.