SPI Master Receive Data

bmo_801
Posts: 3
Joined: Fri Oct 20, 2017 6:29 pm

SPI Master Receive Data

Postby bmo_801 » Fri Oct 20, 2017 6:49 pm

Hello,

I am having some troubles extracting data from the receive buffer using spi_device_get_trans_result. I can see the response from the slave so I know that i am getting the correct response. I am wondering if someone can share an example of how to do this. Here is my test main from the spi master example:

Code: Select all

void app_main()
{
    	spi_transaction_t *rtrans;
	uint8_t data[2];
	uint8_t data1;

	esp_err_t ret;
    	spi_device_handle_t spi;
    	
    	spi_bus_config_t buscfg={
        .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
    };
    spi_device_interface_config_t devcfg={
        .clock_speed_hz=10000000,               //Clock out at 10 MHz
        .mode=0,                                //SPI mode 0
        .spics_io_num=PIN_NUM_CS,               //CS pin
        .queue_size=1,                          //We want to be able to queue 7 transactions at a time
        .pre_cb=ili_spi_pre_transfer_callback,  //Specify pre-transfer callback to handle D/C line
    };
    
    //Initialize the SPI bus
    ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
    assert(ret==ESP_OK);
    //Attach the device to the SPI bus
    ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
    assert(ret==ESP_OK);
    data[0] = 0x8f;
    data[1] = 0x00;
    printf("1\n");
    rtrans.flags=SPI_TRANS_USE_RXDATA;
    ili_data(spi, data, 2);
    
    spi_device_get_trans_result(spi, rtrans, 10);
    
    printf("%x\n",rtrans.rx_data[0]);
    printf("%x\n",rtrans.rx_data[1]);
    printf("%x\n",rtrans.rx_data[2]);
    printf("%x\n",rtrans.rx_data[3]);

    while(1)
    	{
    	ili_data(spi, data, 2);
    	vTaskDelay(1000 / portTICK_RATE_MS);
	}

}

Who is online

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