ESP32 IDF SPI slave not receiving any data
Posted: Thu May 12, 2022 9:31 am
µC: ESP32-WROVER-E
Board: Custom board
IDF: v4.4.1
Hi, I'm currently trying to receive data via SPI on the ESP32 (Slave), sent by a STM32 (Master).
There's no CS and no Handshake available, so there are only CLK, MOSI and MISO.
The data sent by the master (0xAFFECAFE) seems correct to me:
D0 = CLK = GPIO18
D1 = MOSI = GPIO23
D2 = MISO = GPIO19
Source-Code for the ESP32:
(I can control the sending on the master by pressing a button)
What happens is, that spi_slave_transmit get's called and then spi_ex_setupCplt. After that I'm sending 0xAFFECAFE from the master by hand, but it seems like it hasn't any effect on the slave. spi_slave_transmit keeps blocking and neither spi_ex_setupCplt nor spi_ex_transactionCplt are getting called.
If I'm correct, I should also see 0x55555555 on the MISO line while sending, since I filled spi_ex_3txBuf with 0x55, but it's low during the transaction.
I've read the whole description (https://docs.espressif.com/projects/esp ... slave.html) and had a look at the example (https://github.com/espressif/esp-idf/bl ... app_main.c), but i cannot get it working.
Thanks in advance!
Board: Custom board
IDF: v4.4.1
Hi, I'm currently trying to receive data via SPI on the ESP32 (Slave), sent by a STM32 (Master).
There's no CS and no Handshake available, so there are only CLK, MOSI and MISO.
The data sent by the master (0xAFFECAFE) seems correct to me:
D0 = CLK = GPIO18
D1 = MOSI = GPIO23
D2 = MISO = GPIO19
Source-Code for the ESP32:
- #include "spi_ex.h"
- #include "gpio_ex.h"
- #include "com.h"
- #include "string.h"
- #define _SPI_EX_BUF_SIZE 128
- spi_bus_config_t spi_ex_config[SOC_SPI_PERIPH_NUM] = {
- [SPI3_HOST] = {
- .mosi_io_num = COM_SPI_MOSI_GPIO, // = 23
- .miso_io_num = COM_SPI_MISO_GPIO, // = 19
- .sclk_io_num = COM_SPI_CLK_GPIO, // = 18
- .quadwp_io_num = -1,
- .quadhd_io_num = -1
- }
- };
- spi_slave_interface_config_t spi_ex_slaveConfig[SOC_SPI_PERIPH_NUM] = {
- [SPI3_HOST] = {
- .mode = 0, //CPOL = 0, CPHA = 0
- .spics_io_num = -1,
- .queue_size = 3,
- .flags = 0,
- .post_setup_cb = spi_ex_setupCplt,
- .post_trans_cb = spi_ex_transactionCplt
- }
- };
- WORD_ALIGNED_ATTR uint8_t spi_ex_3txBuf[_SPI_EX_BUF_SIZE] = { 0 };
- WORD_ALIGNED_ATTR uint8_t spi_ex_3rxBuf[_SPI_EX_BUF_SIZE] = { 0 };
- spi_slave_transaction_t spi_ex_slaveTransaction[SOC_SPI_PERIPH_NUM] = {
- [SPI3_HOST] = {
- .length = _SPI_EX_BUF_SIZE * 8,
- .tx_buffer = spi_ex_3txBuf,
- .rx_buffer = spi_ex_3rxBuf
- }
- };
- bool spi_ex_isInitialized[SOC_SPI_PERIPH_NUM] = { false };
- void spi_ex_init(spi_host_device_t spi_num)
- {
- if (spi_ex_isInitialized[spi_num])
- {
- return;
- }
- ESP_ERROR_CHECK(spi_slave_initialize(spi_num, &spi_ex_config[spi_num], &spi_ex_slaveConfig[spi_num], SPI_DMA_CH_AUTO));
- memset(spi_ex_3txBuf, 0x55, sizeof(uint8_t) * _SPI_EX_BUF_SIZE);
- spi_ex_isInitialized[spi_num] = true;
- }
- void spi_ex_mainLoop(void)
- {
- ESP_ERROR_CHECK(spi_slave_transmit(SPI3_HOST, &spi_ex_slaveTransaction[SPI3_HOST], portMAX_DELAY));
- }
- void spi_ex_setupCplt(spi_slave_transaction_t *trans)
- {
- }
- void spi_ex_transactionCplt(spi_slave_transaction_t *trans)
- {
- }
(I can control the sending on the master by pressing a button)
What happens is, that spi_slave_transmit get's called and then spi_ex_setupCplt. After that I'm sending 0xAFFECAFE from the master by hand, but it seems like it hasn't any effect on the slave. spi_slave_transmit keeps blocking and neither spi_ex_setupCplt nor spi_ex_transactionCplt are getting called.
If I'm correct, I should also see 0x55555555 on the MISO line while sending, since I filled spi_ex_3txBuf with 0x55, but it's low during the transaction.
I've read the whole description (https://docs.espressif.com/projects/esp ... slave.html) and had a look at the example (https://github.com/espressif/esp-idf/bl ... app_main.c), but i cannot get it working.
Thanks in advance!