SPI Tx & Rx Buffer Sizes

NevynSelby
Posts: 34
Joined: Thu Dec 24, 2015 12:04 pm

SPI Tx & Rx Buffer Sizes

Postby NevynSelby » Mon Aug 12, 2019 8:22 am

I have the ESP32 set up as a slave device using SPI as the communication protocol. As such the ESP32 listens for commands from the controller and sends responses to the controller. This means that the ESP is either in receive only mode (when listening) or send only mode (when responding). The clock is of course generated by the controller.

So lets say that the controller wants to send 40 bytes of command data to the ESP32. I obviously need a rx_buffer setting up but do I need a tx_buffer as well?

Similarly, when the ESP is responding, do I need both buffers or can I just supply a tx_buffer?

I am trying to keep heap usage as low as possible and some messages could be large. I do not want to allocate say 10K for a rx_buffer when I am not going to receive anything other than 0x00 when the ESP is sending 10K of data to the controller.

Thanks in advance,
Mark

mikemoy
Posts: 627
Joined: Fri Jan 12, 2018 9:10 pm

Re: SPI Tx & Rx Buffer Sizes

Postby mikemoy » Mon Aug 12, 2019 12:33 pm

A option would be to create two functions. One for when the rx_buffer is minimal and another when the rx_buffer is using the 10k

Code: Select all

void SPI_ReadMinimal(void)
{
	uint8_t tx_data[10000];

	transmitter.tx_buffer = tx_data;	
	transmitter.rx_buffer = NULL;
	transmitter.length = ?;
}
void SPI_ReadMaximal(void)
{
	uint8_t tx_data[10000];
	uint8_t rx_data[10000];

	transmitter.tx_buffer = tx_data;	
	transmitter.rx_buffer = rx_data;
	transmitter.length = ?;
}

NevynSelby
Posts: 34
Joined: Thu Dec 24, 2015 12:04 pm

Re: SPI Tx & Rx Buffer Sizes

Postby NevynSelby » Tue Aug 13, 2019 10:24 am

Thank you for taking the time to respond. The essence of the question is not how to code this but what does the SDK expect.

So, if the ESP32 is only sending data to the SPI master does the SDK need the rx_buffer field to be pointing to a valid buffer?

Regards,
Mark

mikemoy
Posts: 627
Joined: Fri Jan 12, 2018 9:10 pm

Re: SPI Tx & Rx Buffer Sizes

Postby mikemoy » Wed Aug 14, 2019 10:48 am

So, if the ESP32 is only sending data to the SPI master does the SDK need the rx_buffer field to be pointing to a valid buffer?
The answer is in the coding example i gave. The answer is no.

Who is online

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