2022-03-13 01:21 PM
I have the following :
HAL_SPI_Transmit(&hspi2, &txBuf[0], 1, 50);
HAL_SPI_Receive(&hspi2, &rxBuf[0], 1, 50);
I have the following code .... STM32L476 is a spi 3 wire master. The Transmit appears (logic analyzer) to be working fine, however I am having much grief trying to read from the sensor (LSM6DSM33)....If I transmit two bytes with the second being a dummy byte of 0x00, the device responds with the appropriate response on the 3 wire connection. Unfortunately this method does not write anything into an rx buffer hence I THEN change to what you see above. The issue I am having is the above receive command puts 5 bytes worth of clocks out on the bus EVEN with a 1 as a parameter. If I put a 0 I get no clocks (as expected) and if I put a 2 I get (7 bytes worth of clocks). Can someone please explain what is going on????
Solved! Go to Solution.
2022-03-13 01:29 PM
RX only in bidirectional mode sends out clocks continuously. By the time the code catches up to realize a byte has already come in, a few more bytes have already been clocked.
Use four-wire mode if you can, or a lower clock speed.
2022-03-13 01:29 PM
RX only in bidirectional mode sends out clocks continuously. By the time the code catches up to realize a byte has already come in, a few more bytes have already been clocked.
Use four-wire mode if you can, or a lower clock speed.
2022-03-13 01:34 PM
Thank you
I have to use 3 wire as the end product is a sensorTile already wired up....Can you tell me is there ANY way to clock out 2 bytes with the TX command where the first is the register (with the Read bit set) and the second is a dummy to produce clocks with 0x00 from the STM. I seem to always see the sensor driving the MOSI line with the correct information when I do this BUT I just don't think there is a way to capture what it is sending in this mode???
2022-03-13 01:59 PM
With HAL and at very fast baud rates? Probably not. With your own code, or lower speeds, almost certainly.
If you can set the SPI to 16-bit mode then sending a word and immediately disabling RX mode will receive exactly one word.
The SPI RXONLY hardware implementation is awkward at best.