2023-03-16 10:36 AM
Hello,
I am working on the SPI interfacing with STM32F4 microcontroller. I found an application which was written Zephyr. My aim is translating that code in to STM32CubeIDE format. Could you help me on this?
Here is the code,
static u16_t tx_buffer[1];
static u16_t rx_buffer[1];
const struct spi_buf tx_buf = {
.buf = tx_buffer,
.len = sizeof(tx_buffer)
};
const struct spi_buf_set tx = {
.buffers = &tx_buf,
.count = 1
};
struct spi_buf rx_buf = {
.buf = rx_buffer,
.len = sizeof(rx_buffer),
};
const struct spi_buf_set rx = {
.buffers = &rx_buf,
.count = 1
};
Thank you,
2023-03-16 03:43 PM
assert(tx_buf.len == rx_buf.len);
HAL_StatusTypeDef st;
st = HAL_SPI_TransmitReceive(hspi, (void*)tx_buf.buf, (void*)rx_buf.buf, tx_buf.len, timeout_in_ms);
And, of course, you need to call HAL_SPI_Init before, with suitable settings.
You can find a helper for your project here..