Hello I am trying to create a device prototype that includes stm32f103c8t6 and bmx055 IMU sensor.
I am able to talk to IMU using I2C and SPI 4-wire interfaces. But I also interested in using SPI with reduced number of pins (aka 3-wire SPI). BMX055 supports 3-wire SPI, see https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMX055-DS000-02.pdf See section 11. My understanding is that master should provide 16 bits of CLK signal and 8 first bits of SISO signal, then master switches SISO into Hi-Z input mode and the last 8 bits are driven my slave. I am trying to use libopencm3 spi_bidirectional to implement something like this static uint8_t bmx_spi_read(uint8_t reg) { uint8_t out = 0x80 | (reg & 0x7f); // read flag gpio_clear(GPIOA, GPIO4); // slave select spi_set_bidirectional_transmit_only_mode(SPI1); while (!(SPI_SR(SPI1) & SPI_SR_TXE)); SPI_DR(SPI1) = out; while (!(SPI_SR(SPI1) & SPI_SR_TXE)); while ((SPI_SR(SPI1) & SPI_SR_BSY)); // wait until transmit is over and then switch to receive mode SPI_CR1(SPI1) &= ~SPI_CR1_BIDIOE; // receive while (!(SPI_SR(SPI1) & SPI_SR_RXNE)); uint8_t data = SPI_DR(SPI1); spi_set_unidirectional_mode(SPI1); gpio_set(GPIOA, GPIO4); return data; } but logic analyser shows weird results: - data at SISO appears before clock is provided - 8th bit of CLK is stretched, I wonder if calling "SPI_CR1(SPI1) &= ~SPI_CR1_BIDIOE" introduces the clock stretch Does anybody have a working example of bidirectional SPI communication example for STM32F1? ------------------------------------------------------------------------------ _______________________________________________ libopencm3-devel mailing list libopencm3-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libopencm3-devel