I am struggling with SPI in master mode.
I want to send address plus buffer with help of function spi_device_queue_trans but SPI does not send address and send only data.
SPI device is configured like this:
Code: Select all
spi_device_interface_config_t sx1276_config = {
.clock_speed_hz = (SPI_SX1276_BUS_CLOCK_MHZ), //Clock out at 10 MHz.
.mode=0, //SPI mode 0 (CPOL=0, CPHA=0)
.spics_io_num = PIN_NUM_SX1276_CS, //CS pin
.queue_size = 1, //Transaction queue size.
.address_bits = 8,
.cs_ena_pretrans = 1, //one clock delay prior CS line is active
.cs_ena_posttrans= 1, //one clock delay after CS line is released
};
//Initialise the SPI bus for both devices
spi_error_ret=spi_bus_initialize(HSPI_HOST, &spi_bus_config, NO_SPI_DMA_CHANNEL);
ESP_ERROR_CHECK(spi_error_ret); //SPI bus error handling
//Attach to SPI bus
spi_error_ret = spi_bus_add_device(HSPI_HOST, &sx1276_config, &spi_sx1276_handle);
ESP_ERROR_CHECK(spi_error_ret); //SPI bus error handling
Code: Select all
static void spi1_Send_Data_To_SX1276_Device(spi_device_handle_t spi_sx1276_handle, uint8_t addr, uint8_t *buffer, uint16_t size)
{
static spi_transaction_t spi_transaction;
memset(&spi_transaction, 0, sizeof(spi_transaction_t));
[Codebox=c file=Untitled.c][Codebox=c file=Untitled.c][/Codebox][/Codebox]
spi_transaction.flags = SPI_DEVICE_HALFDUPLEX; //SPI_TRANS_USE_TXDATA,
spi_transaction.addr = (uint8_t) addr;
spi_transaction.length = 8 + (size * 8); // data length is in bits
spi_transaction.tx_buffer = buffer;
spi_transaction.rx_buffer = NULL;
spi_error_ret = spi_device_queue_trans(spi_sx1276_handle, &spi_transaction, SPI_SX1276_TICKS_TIMEOUT_MS); //queue data to send
ESP_ERROR_CHECK(spi_error_ret); //SPI bus error handling
}
Target is to send address plus data.
Do you have any idea what could be wrong in my code, please?
Thank you