Page 1 of 1

SPI Read

Posted: Sat Jan 12, 2019 9:15 pm
by KanyeKanye
How to read anything from SPI? /there is nothing about reading in spi_master example
Would send one byte and receive one byte of a response.
Code like below cause assert error because ESP_ERR_INVALID_ARG returned from spi_device_polling_transmit.

Code: Select all

void readSingleRegister(spi_device_handle_t spi, char * rxBuffer, uint8_t address) {
	spi_transaction_t transaction;
	memset(&transaction, 0, sizeof(transaction));
	transaction.cmd = RREG | (address<<2);
	transaction.rxlength = 8;
	transaction.rx_buffer = rxBuffer;
	assert(spi_device_polling_transmit(spi, &transaction) == ESP_OK);
	printf("Received (address %d): %s\n", address, rxBuffer);
}
Setting:

Code: Select all

	transaction.length = transaction.rxlength;
Fixes assert error, but still won't work- rxBuffer is empty and in few repeats esp is crashed by kernel panic