SPI Read

KanyeKanye
Posts: 54
Joined: Mon Dec 05, 2016 12:34 am

SPI Read

Postby KanyeKanye » Sat Jan 12, 2019 9:15 pm

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

Who is online

Users browsing this forum: No registered users and 108 guests