How to keep MOSI line high at idle?

gerard-hm
Posts: 3
Joined: Sun Aug 01, 2021 12:34 am

How to keep MOSI line high at idle?

Postby gerard-hm » Sun Aug 01, 2021 1:00 am

My SPI setup:

Code: Select all

SPI_DEVICE_NO_DUMMY
SPI_DEVICE_3WIRE
SPI_DEVICE_HALFDUPLEX
no DMA
no interrupts (I use polling instead)
no address, no command phases, just data phase for a custom protocol
I'm currently using multiple DATA phases one after another with all 1s to simulate idle logic high, but there is still a small gap between the 64 bytes worth of DATA phases.

Is there a better, another way to keep MOSI line high at idle?

Some other hardware architectures apparently seem to hold the idle MOSI line at whatever level the last bit was sent, is there a way to have that behavior for ESP32?

thanks

gerard-hm
Posts: 3
Joined: Sun Aug 01, 2021 12:34 am

Re: How to keep MOSI line high at idle?

Postby gerard-hm » Sat Aug 14, 2021 12:46 am

To answer my own question - the way to do it is to invert signal using:

Code: Select all

        esp_rom_gpio_connect_out_signal(mosi, spi_periph_signal[host_device].spid_out, invert, false);
        esp_rom_gpio_connect_in_signal(mosi, spi_periph_signal[host_device].spid_in, invert);
and then invert again all the data bytes:

Code: Select all

        buffer[i]  = ~data_byte; // invert

wintu.vogga
Posts: 2
Joined: Tue Mar 03, 2020 2:45 am

Re: How to keep MOSI line high at idle?

Postby wintu.vogga » Sat Feb 01, 2025 1:49 pm

Thanks for this info, It helped me a lot. I am using three BL0940 metering chips on a single SPI bus for a three phase AC board.
with IDF version v5.0.1 everything was ok. after I updated the IDF version to 5.3.2 and above SPI read could not work. When i checked on the oscilloscope SPI MOSI signal was held high during idle.

Code: Select all

esp_rom_gpio_connect_out_signal(PIN_BL0940_MOSI, spi_periph_signal[SPI2_HOST].spid_out, true, false);
esp_rom_gpio_connect_in_signal(PIN_BL0940_MOSI, spi_periph_signal[SPI2_HOST].spid_in, true);
and the

Code: Select all

transaction.cmd = ~(address | 0x5800);
Fixed the issue.

squire
Posts: 4
Joined: Tue Oct 15, 2024 8:25 pm

Re: How to keep MOSI line high at idle?

Postby squire » Thu Feb 13, 2025 8:23 pm

I had the same problem, but found spi_ll_set_mosi_free_level in hal/spi_ll.h
You have to call it after adding at lease one device to the bus:

Code: Select all

spi_bus_initialize(SPI2_HOST, &busCfg, SPI_DMA_DISABLED);
spi_bus_add_device(SPI2_HOST, &devCfg, &dev);

// esspressif driver doesn't nativley support this :/
spi_ll_set_mosi_free_level(&GPSPI2, 1);
spi_ll_apply_config(&GPSPI2);

Who is online

Users browsing this forum: No registered users and 41 guests