SPI Transmit with command phase only affects next rx transmission

Aeronautic
Posts: 11
Joined: Thu Jan 02, 2020 12:07 am

SPI Transmit with command phase only affects next rx transmission

Postby Aeronautic » Tue Jan 07, 2020 2:35 pm

I've noticed that using SPI transactions with CMD phase only eg:

Code: Select all

void fram_writeWREN() {
	spi_transaction_ext_t transaction;
	memset(&transaction, 0, sizeof(transaction));
	transaction.base.cmd = WREN;
	assert(spi_device_polling_transmit(fram_spi, (spi_transaction_t*) &transaction) == ESP_OK);
}
affects next RX transmissions, eg.:

Code: Select all

void fram_readData(uint16_t address, char * data, size_t length) {
	spi_transaction_ext_t transaction;
	memset(&transaction, 0, sizeof(transaction));
	transaction.base.cmd = READ;
	transaction.base.addr = address;
	transaction.base.flags = SPI_TRANS_VARIABLE_ADDR;
	transaction.base.rx_buffer = data;
	transaction.base.rxlength = length * 8;
	transaction.base.length = transaction.base.rxlength;
	transaction.address_bits = 16;
	assert(spi_device_polling_transmit(fram_spi, (spi_transaction_t*) &transaction) == ESP_OK);
}
Executing such code in a loop (fram_writeWREN them fram_readData and print buffer) results in receiving one byte less for each loop iteration.
Primarily I receive 512 bytes, than 510, then 510. After some time I receive only one byte, rest of a buffer is zero.
What is happening?

col135
Posts: 1
Joined: Sun Jan 12, 2020 8:50 am

Re: SPI Transmit with command phase only affects next rx transmission

Postby col135 » Tue Jan 14, 2020 4:20 am

Had the exact same issue with FRAM via SPI. The single command write enable is the culprit. Overriding the default and putting the command in the tx_data[0] buffer solved it for me. There must be an edge case in the drivers when DMA is enabled but both the RX and TX pointers are NULL?

Code: Select all

spi_transaction_ext_t trans = (spi_transaction_ext_t) {
	.base = {
	.flags = SPI_TRANS_USE_TXDATA | SPI_TRANS_VARIABLE_ADDR | SPI_TRANS_VARIABLE_CMD,	// override default
	.tx_data[0] = FRAM_WRITE_ENABLE,
	.length=1*8,
	},
	.address_bits = 0,
	.command_bits = 0,
};
ret=spi_device_polling_transmit(spiFramHandle, (spi_transaction_t*)&trans);  //Transmit Write enable

Aeronautic
Posts: 11
Joined: Thu Jan 02, 2020 12:07 am

Re: SPI Transmit with command phase only affects next rx transmission

Postby Aeronautic » Tue Jan 14, 2020 12:12 pm

Thanks for your reply. In fact I have found couple of strange errors (eating last bytes, corrupting when multiple devices some full, some half duplex). I decided writing own spi driver that fixed all issues.

Who is online

Users browsing this forum: Baidu [Spider], Sfeli32 and 20 guests