SPI Master spi_transaction_t

User avatar
arunbm123
Posts: 96
Joined: Fri Feb 23, 2018 5:36 am

SPI Master spi_transaction_t

Postby arunbm123 » Wed May 22, 2019 3:18 am

hi friends

Please can any one explain memebers of struct spi_transaction_t

uint16_t cmd
uint64_t addr


I know they are command and address...but address of what ? is it address of peripheral ??

Kindly explain
Thanks

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: SPI Master spi_transaction_t

Postby ESP_Sprite » Wed May 22, 2019 6:38 am

'Command' and 'address' are just fields that are sent out in the same fashion as the data; the fact that they are separate is a remnant of the fact that the SPI peripherals are also designed to drive SPI flash, which has these conventions. We left support for it in the driver as there are other SPI devices where this also can come in handy.

User avatar
arunbm123
Posts: 96
Joined: Fri Feb 23, 2018 5:36 am

Re: SPI Master spi_transaction_t

Postby arunbm123 » Wed May 22, 2019 7:07 am

ok

hi,
I am using SPI to Send data to MAX7219 LED MATRIX

I am not understanding whats going wrong...kindly help

Code: Select all

void app_main()
{

	esp_err_t ret;

    spi_bus_config_t busconfig={
        .miso_io_num=PIN_NUM_MISO,
        .mosi_io_num=PIN_NUM_MOSI,
        .sclk_io_num=PIN_NUM_CLK,
        .quadwp_io_num=-1,
        .quadhd_io_num=-1,
        .max_transfer_sz=PARALLEL_LINES*320*1+8
    };

    spi_device_interface_config_t dev_config={
		 .address_bits = 0,
		 .command_bits = 0,
		 .dummy_bits = 0,
		 .mode = 0,
		 .duty_cycle_pos = 0,
		 .cs_ena_posttrans = 0,
		 .cs_ena_pretrans = 0,
		 .clock_speed_hz = 10000,
		 .spics_io_num = PIN_NUM_CS,
		 .flags = 0,
		 .queue_size = 1,
		 .pre_cb = NULL,
		 .post_cb = NULL
    };

    ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &busconfig, 1));

	ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &dev_config, &handle));

	uint8_t cmd[] = {0x05, 0x0A};

	spi_transaction_t t;
	memset(&t, 0, sizeof(t));       
	t.flags =SPI_TRANS_USE_TXDATA;
	t.length=2 * 8;                   
	t.tx_buffer=cmd;               
	t.user=(void*)0;               
	ret = spi_device_transmit(spi, &t);
	assert( ret == ESP_OK);

	ESP_ERROR_CHECK(spi_bus_remove_device(handle));
	ESP_ERROR_CHECK(spi_bus_free(HSPI_HOST));

}

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: SPI Master spi_transaction_t

Postby ESP_Sprite » Thu May 23, 2019 1:42 am

If anything, you're setting SPI_TRANS_USE_TXDATA, which means that the SPI peripheral will get the tx data from the tx_data member, but then you're feeding it a buffer through the tx_buffer member instead. Remove the SPI_TRANS_USE_TXDATA flag and you should be at least a bit closer to working code.

Who is online

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