2015-01-04 11:33 PM
My project involves using a STM32L152 device as a SPI master that receives data from a slave (digital accelerometer). When I look at the SPI signals through a scope, I notice that the incoming SPI data is being interpreted incorrectly by the L1 device.
I use the STM32CubeMX GUI to generate the code for the project. I am wondering if
whether my usage of the tool is somehow causing this issue or
if there are known issues relating to the tool causing these issues. I have attached images showing the oscilloscope outputs for an example case where I am finding the error. The blue signal represents SPI clock and yellow is SPI Data In.The case involves two bytes being read from the SPI port (corresponding to 2 sets of 8 clock cycles in the SPI clock). The second byte clearly has ''data in'' line being zero throughout. Yet the data is being read as a 1.
I am consistently seeing these sort of errors where the LSB is being wrongly interpreted as a '1' sometimes when it should be a 0 and vice versa.
Here are the SPI initialization settings generated by Cube.
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
HAL_SPI_Init(&hspi1);
Here is the call I make to read the SPI port:HAL_SPI_TransmitReceive(&
hspi1, (uint8_t *)&data, (uint8_t *)&temp, 1, 5000);
I'd appreciate any inputs on helping me track the issue. Note that I am driving the CS logic using my own software logic using GPIO and not the hardware based NSS signal.
I'd appreciate any inputs on helping me track the issue.
Thanks,
Ben