Showing results for 
Search instead for 
Did you mean: 

3 wire or half duplex implementation of SPI in STM32 MCU(using lsm303 agr)

Associate II

i am working with lsm303agr accelerometer and magnetometer sensor module with controller STM32WB , am using the library from the ST for the implementation of software. I can able to fetch data using the I2C protocol. But when I try to use the SPI 3 wire method I always getting some garbage values' tried 2 different method for the implementation of half duplex SPI

1) using the half duplex configuration available on CUBEMX (only used MOSI of controller).

2) making 4 wire SPI in configuration and shorting miso and MOSI together and controlling the pin direction using SPI_1LINE_TX(&hspi2); and SPI_1LINE_RX(&hspi2);

3) connected miso directly to data pin of LSM303AGR and MOSI connected to data pin using a 1 k ohm resistor .(providing impedance while receiving ).

in the first 2 cases I didn't got any correct data sometimes its reading 0 and sometimes its reading garbage values.

in the 3rd method I am able to get some data but its not consistent(device id is reading fine sometimes).

CAN ANYBODY HELP ME OUT FOR THE IMPLEMENTAION OF HALF DUPLEX SPI. i tried on internet i didn't got any reference on stm32 .and even while i downloading the LSM303 driver package from CUBEMX its only giving the option for selecting the I2C protocol. This must be done using SPI only customer is asking for it or we need a proper explanation to shift totally to I2C protocol.

this is the clock and data i probed