SPI Slave Issue - MOSI data being echoed onto MISO
Posted: Fri Oct 11, 2019 10:50 am
Hi all,
I've setup an ESP32 as an SPI slave communicating with another microcontroller along with 3 other SPI slaves. The master is communicating at a speed of 1MHz.
The problem is that the data on the MOSI line was being echoed on the MISO line, even with the tx_buffer of the SPI transaction struct being cleared. I tried setting the tx_buffer to NULL, but all data being received on the MOSI started being interpreted as garbage. The next step was to reset the tx_buffer of the transaction struct back to an actual allocated memory array, but setting the MISO to an input before making a call to the spi_slave_transmit function. This solved the issue with the MOSI/MISO echoing, but it doesn't strike me as proper operation.
I'm copying a code snippet of the SPI Slave setup and operation below. Note that the pins are defined as follows:
-MOSI: 39
-MISO: 15
-SCK: 13
-CS: 36
What could be causing the issue?
I've setup an ESP32 as an SPI slave communicating with another microcontroller along with 3 other SPI slaves. The master is communicating at a speed of 1MHz.
The problem is that the data on the MOSI line was being echoed on the MISO line, even with the tx_buffer of the SPI transaction struct being cleared. I tried setting the tx_buffer to NULL, but all data being received on the MOSI started being interpreted as garbage. The next step was to reset the tx_buffer of the transaction struct back to an actual allocated memory array, but setting the MISO to an input before making a call to the spi_slave_transmit function. This solved the issue with the MOSI/MISO echoing, but it doesn't strike me as proper operation.
I'm copying a code snippet of the SPI Slave setup and operation below. Note that the pins are defined as follows:
-MOSI: 39
-MISO: 15
-SCK: 13
-CS: 36
What could be causing the issue?
Code: Select all
//Configuration for the SPI bus
spi_bus_config_t buscfg =
{
.mosi_io_num = SPI_SLAVE_MOSI_PIN,
.miso_io_num = SPI_SLAVE_MISO_PIN,
.sclk_io_num = SPI_SLAVE_SCK_PIN,
.quadwp_io_num = -1,
.quadhd_io_num = -1
};
//Configuration for the SPI slave interface
spi_slave_interface_config_t slvcfg =
{
.mode = 0,
.spics_io_num = SPI_SLAVE_CS_PIN,
.queue_size = 7,
.flags = 0,
.post_setup_cb=NULL,
.post_trans_cb=NULL
};
spi_slave_transaction_t t;
esp_err_t rv = ESP_OK;
ESP_LOGI(TAG, "spiSlaveListenTask: Starting to listen on SPI Slave interface");
bzero(_shared_mem_recv_buffer, SPI_SLAVE_MAX_BUFER_SIZE); //initialize receivebuffer to all zeros
bzero(_shared_mem_send_buffer, SPI_SLAVE_MAX_BUFER_SIZE); //initialize transmitbuffer to all zeros
//Set up a transaction of bytes to send/receive
memset(&t, 0, sizeof(t));
//initialize spi slave interface
spi_slave_initialize(VSPI_HOST, &buscfg, &slvcfg, 0);
while(1)
{
t.length = 32*8;
t.tx_buffer = _shared_mem_send_buffer;
t.rx_buffer = _shared_mem_recv_buffer;
/*gpio_config_t io_conf;
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
io_conf.pin_bit_mask = 1ULL<<SPI_SLAVE_MISO_PIN;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pull_up_en = 0;
io_conf.pull_down_en = 0;
gpio_config(&io_conf);*/
rv = spi_slave_transmit(VSPI_HOST, &t, portMAX_DELAY);
if(ESP_OK != rv)
{
ESP_LOGE(TAG, "spiSlaveListenTask: Recevied error %d when setting up transaction!", rv);
}
t.trans_len = 0;
}