Is it possible to change the clock speed of the SPI after initializing the interface?
Something like: write to the first device at 80Mhz, change to 40Mhz, write to a second device, then change back to 80Mhz...
Thanks!
Change SPI speed on the fly?
-
- Posts: 9017
- Joined: Thu Nov 26, 2015 4:08 am
Re: Change SPI speed on the fly?
The ESP-IDF way would be to initialize a bus and add the two devices to it; you can specify different speeds for each device and the driver will automatically handle the speed switch.
Re: Change SPI speed on the fly?
Thanks for the quick reply.
As I understood:
If I attach the 80Mhz first, it always uses the 40Mhz or, If I attach the 40Mhz first it´s always 80Mhz. How to point one or another at the transaction?
[EDIT] I just figured out, I need to create two handles.
It´s working, thanks for your help!
As I understood:
Code: Select all
void setupSPI()
{
esp_err_t ret;
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,
.max_transfer_sz=PARALLEL_LINES*320*2+8
};
spi_device_interface_config_t devcfg40=
{
.clock_speed_hz=40*1000*1000, //Clock out at 40 MHz ok (25ns)
.mode=0, //SPI mode 0
.spics_io_num=-1, //CS software controlled
.queue_size=1, //Transactions at a time
.pre_cb=NULL,
};
spi_device_interface_config_t devcfg80=
{
.clock_speed_hz=80*1000*1000, //Clock out at 80 MHz ok (12.5ns)
.mode=0, //SPI mode 0
.spics_io_num=-1, //CS software controlled
.queue_size=1, //Transactions at a time
.pre_cb=NULL,
};
//Initialize the SPI bus
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
ESP_ERROR_CHECK(ret);
//Attach the SPI bus (80mhz)
ret=spi_bus_add_device(HSPI_HOST, &devcfg80, &spi);
ESP_ERROR_CHECK(ret);
//Attach the SPI bus (40Mhz)
ret=spi_bus_add_device(HSPI_HOST, &devcfg40, &spi);
ESP_ERROR_CHECK(ret);
}
[EDIT] I just figured out, I need to create two handles.
Code: Select all
spi_device_handle_t spi40;
spi_device_handle_t spi80;
Who is online
Users browsing this forum: bushpulbek, djixon, steevke and 143 guests