Spi read write sample code stack over flow

Post by dev4all12358 » Mon Sep 06, 2021 2:18 pm

I try to do a simple read/write on SPI when my ESP is in master mode.

The write code seems to work properly:

 ESP_LOGI(TAG, "Sensor_IO_Write"); esp_err_t err; spi_transaction_t t = < .cmd = WriteAddr, .length = nBytesToWrite * 8, .flags = 0, .tx_buffer = pBuffer, .user = (void*) &sensor_ctx, >; ESP_LOGI(TAG, "Sensor_IO_Write: spi_device_transmit"); err = spi_device_transmit(sensor_ctx.spi, &t); 

I check with my spi analyser, an I get the proper data.

The read code doesn't seems to works:

 esp_err_t err; uint8_t pBuffer2[2]; spi_transaction_t t = < .cmd = ReadAddr, .length = 8 * nBytesToRead, .rxlength = 8 * nBytesToRead, .flags = SPI_TRANS_USE_RXDATA, .rx_buffer = pBuffer2, .user = (void*) &sensor_ctx, >; err = spi_device_polling_transmit(sensor_ctx.spi, &t); uint8_t data = ((uint8_t*) pBuffer2)[0];

On my analyser I see 0x11 ( my command) and 0x63 the read data. But my buffer is filled with 192.