SPI Master Read only still sets data on MOSI line

rfleming
Posts: 37
Joined: Tue Oct 09, 2018 12:30 am

SPI Master Read only still sets data on MOSI line

Postby rfleming » Thu Apr 08, 2021 1:52 am

Hi All,

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;
}

chegewara
Posts: 1449
Joined: Wed Jun 14, 2017 9:00 pm

Re: SPI Master Read only still sets data on MOSI line

Postby chegewara » Thu Apr 08, 2021 11:39 am

Did you try:

Code: Select all

        t.length = 0;
	t.rxlength = 8 * read_len;  //length is in bits.

rfleming
Posts: 37
Joined: Tue Oct 09, 2018 12:30 am

Re: SPI Master Read only still sets data on MOSI line

Postby rfleming » Fri Apr 09, 2021 2:50 am

No i haven't. Reading documentation for those fields though, looking at spi_master.h

Code: Select all

size_t length;                  ///< Total data length, in bits
    size_t rxlength;                ///< Total data length received, should be not greater than ``length`` in full-duplex mode (0 defaults this to the value of ``length``).
Just based on the comment, I didn't want to touch it at all :cry:

Who is online

Users browsing this forum: Bing [Bot] and 60 guests