[SPI master] Wait some bit time??

wosayttn
Posts: 1
Joined: Tue Jan 30, 2018 11:27 am

[SPI master] Wait some bit time??

Postby wosayttn » Tue Jan 30, 2018 11:34 am

We use DMA engine of SPI Master of ESP32 within other SPI slave device. Due to slave limitation, is it possible to wait some delay bit between words? How to do it?

vonnieda
Posts: 145
Joined: Tue Nov 07, 2017 3:42 pm

Re: [SPI master] Wait some bit time??

Postby vonnieda » Tue Feb 27, 2018 3:12 am

If you need extra clocks between command and address, or address and data, you can just extend the command or address fields. If you need extra time between bytes during the data phase, the only way I know of is to slow your clock rate.

User avatar
Vader_Mester
Posts: 300
Joined: Tue Dec 05, 2017 8:28 pm
Location: Hungary
Contact:

Re: [SPI master] Wait some bit time??

Postby Vader_Mester » Wed Feb 28, 2018 10:37 am

If I understand correctly, you use the ESP32 as master connected to some slave device.
If the slave is a programabble device, other microcontroller, or whatever, then you should have a GPIO pin on a slave to pull low/hig to tell the master to suspend communication, and resume it, once the signal is deactivated.
Or if it is duplex communication, the slave can echo received data back to the master, on the MISO line, so the master will verify that the data is correctly received by the slave.

If it is a slave periferial, sensor, or whatever, usually the datasheet tells you the timing to be used, to make it work correctly.

Also you can just determine the amount of data to be sent, and write the driver in a way, that the master will disable the CS pin after sending a patch of data, so the slave has some time to process it.

Normally if you set a slower clock speed on the SPI, that should give time for the slave to receive data. Since SPI send 1bit/clk edge, this should be straight forward.
If you program the slave yourself, you should measure the time it takes on the slave to process 1 word of data, and set the SPI clock slow enough, so while 1 data word is clocked into the slave, the slave can finish handling the previous data.

Again if you know, the amount of data to be sent, and the slave is programmable, you can program the slave to first receive the entire amount of data (just a routine emptiing the SPI receive FIFO into memory array), then wait for the CS pin to disable, then process the received data. If the master want to send new command, then the slave should handle it with an interrupt, and if busy, the it can send to the slave a busy status.

So, lots of possibilities....

Code: Select all

task_t coffeeTask()
{
	while(atWork){
		if(!xStreamBufferIsEmpty(mug)){
			coffeeDrink(mug);
		} else {
			xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
			xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
		}
	}
	vTaskDelete(NULL);
}

andymosi
Posts: 3
Joined: Fri Mar 16, 2018 9:45 am

Re: [SPI master] Wait some bit time??

Postby andymosi » Mon Apr 16, 2018 10:13 pm

Found drivers/spi_master_utils.c

Anyone has any idea what miso_delay_mode does and how to set it?

Code: Select all

            //Configure polarity
            //SPI interface needs to be configured for a delay in some cases.
            int nodelay=0;
            if (host->no_gpio_matrix) {
                if (effclk >= apbclk/2) {
                    nodelay=1;
                }
            } else {
                uint32_t delay_limit = apbclk/4;
                if (effclk >= delay_limit) {
                    nodelay=1;
                }
            }

            if (handle->cfg.mode==0) {
                host->hw->pin.ck_idle_edge=0;
                host->hw->user.ck_out_edge=0;
                host->hw->ctrl2.miso_delay_mode=nodelay?0:2;
            } else if (handle->cfg.mode==1) {
                host->hw->pin.ck_idle_edge=0;
                host->hw->user.ck_out_edge=1;
                host->hw->ctrl2.miso_delay_mode=nodelay?0:1;
            } else if (handle->cfg.mode==2) {
                host->hw->pin.ck_idle_edge=1;
                host->hw->user.ck_out_edge=1;
                host->hw->ctrl2.miso_delay_mode=nodelay?0:1;
            } else if (handle->cfg.mode==3) {
                host->hw->pin.ck_idle_edge=1;
                host->hw->user.ck_out_edge=0;
                host->hw->ctrl2.miso_delay_mode=nodelay?0:2;
            }

Who is online

Users browsing this forum: kaxx1975 and 139 guests