I am trying loopback in SPI in STM32F411RE, using the STM32 HAL Library. The output in the serial terminal is distorted (Just boxes) I have connected the MOSI, MISO pins of the micro-controller. Could someone help me point out the problem. Thanks:).
void SPI_call()
{
int i = 0, size = 3;
uint8_t tx_buffer[3] = {0x10, 0x20, 0x30};
uint8_t rx_buffer[3] = {0x00, 0x00, 0x00};
for (i = 0; i < size; i++) {
HAL_SPI_Receive(&hspi1, &rx_buffer[i], 1, 100);
HAL_SPI_Transmit(&hspi1, &tx_buffer[i], 1, 100);
HAL_UART_Transmit(&huart2, &rx_buffer[i], 1, HAL_MAX_DELAY);
}
}
EDIT: Tried using the API HAL_UART_TransmitReceive(), but I was not able to receive the data.
void SPI_call()
{
uint8_t tx_buffer = 0x20;
uint8_t rx_buffer;
HAL_SPI_TransmitReceive(&hspi1, &tx_buffer, &rx_buffer, 1, 1000);
HAL_UART_Transmit(&huart2, &rx_buffer, 1, HAL_MAX_DELAY);
}