SPI Read
Posted: 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.
Setting:
Fixes assert error, but still won't work- rxBuffer is empty and in few repeats esp is crashed by kernel panic
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);
}
Code: Select all
transaction.length = transaction.rxlength;