Hi I m using STM32H743 SPI to transmit and receive data from a sensor, the sensor return 3 bytes of data, SensorRXBuff[0], SensorRXBuff[1], and SensorRXBuff[2], i m gona use these 3 byte for indivual computation, i enclosed the function below, SPI transmit portion is working, i m able to receive 3 bytes from the sensor (ADC), the above code was modify to obtain the indiviual 3 received bytes, cos i need to compete the 2nd byte ie. SensorRXBuff[1].
enter code herecould anyone advise what should the code be to churn out the 2nd receive byte from the SensorRXBuff ? thx.
void Sensor(uint8_t *ch) { uint16_t SensorTxBuff[2] = {0x8, 0xAF}; HAL_GPIO_WritePin(..) // SPI CS low if (HAL_SPI_TransmitReceive(&hspi1, (uint8_t *)&SensorTXBuff, (uint8_t *)&SensorRXBuff, 3, 100) != HAL_OK) { Error_Handler(); } HAL_GPIO_WritePin(..); // SPI CS high
}
I don't exactly get the question but if you want to send 4 bytes on TX and then receive 3 bytes on RX you should use size 7 not 3 in
HAL_SPI_TransmitReceiveand make both the buffers size at least 7 bytes. Then your second byte from receive will be in SensorRXBuff[5] when u declared it with uin8_t.