2020-10-15 04:19 AM
Hello,
I tried to configure the STM32G031K8 Nucleo Board using CubeMX to send a request to an attached sensor using SPI1.
To my request (2 bytes) the sensor should answer with 4 bytes. I configured the data size to 8 bits and the clock parameters corersponding to the sensor data sheet.
But when I try to receive the 4 byte response, I can see clock pulses for 5 not only 4 answer bytes on the oscilloscope. I attached an image where you can see, that one additional byte is clocked out.
Here is the code snippet of the corresponding request:
uint8_t sendData[2];
sendData[0] = 0x84;
sendData[1] = 0x21;
HAL_GPIO_WritePin(SPI1_CS_GMR_GPIO_Port, SPI1_CS_GMR_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, sendData, 2, HAL_TIMEOUT);
int8_t receivedValue[4];
if(HAL_SPI_Receive(&hspi1, receivedValue, 4, 1) == HAL_OK){
int16_t angleVal = (int16_t)receivedValue[0] << 8 | receivedValue[1];
}
HAL_GPIO_WritePin(SPI1_CS_GMR_GPIO_Port, SPI1_CS_GMR_Pin, GPIO_PIN_SET);
Does any one have an idea what I might have done wrong or how I can fix this?