When using SPI, some instances I only need to do a read and parse through dummy data. While right now the external ICs I am working with disregard the dummy data that is transmitted, this could be an issue in the future, so I am trying to nut it out now. In the below read example, for some reason, when the read occurs, the TX sends through more than just 0xFF, or 0x00s. In a few different transactions it would send the same {0xDD, 0x35, 0x45, 0xFE} dummy characters through my various transactions. Is it possible to force this to be 0xFFs or even 0x00s?
Code: Select all
void ReadData(spi_device_handle_t handle, uint8_t* read_buf, uint32_t read_len) {
spi_transaction_t t;
memset(&t, 0, sizeof(t)); //Zero out the transaction
/* required since read_buf is unlikely aligned to 32bit carrier */
uint8_t* tmp_read = (uint8_t*)malloc(read_len);
if (tmp_read == NULL) {
puts("SPI: Couldn't malloc");
return false;
}
t.length = 8 * read_len; //length is in bits.
t.tx_buffer = NULL; // Pointer to transmit buffer, or NULL for no MOSI phase
t.rx_buffer = tmp_read;
t.rxlength = 0; //0 forces it to be the same as 'length'
t.user = (void*)0; //context or random pointer. Perhaps use for callback function if used for async?
esp_err_t ret = spi_device_transmit(handle, &t); //blocking
memcpy(read_buf, tmp_read, read_len);
free(tmp_read);
return ret;
}