spi_bus_add_device() causes CS glitch

PeterR
Posts: 166
Joined: Mon Jun 04, 2018 2:47 pm

spi_bus_add_device() causes CS glitch

Postby PeterR » Mon Sep 02, 2019 1:52 pm

I communicate with another processor using SPI.

When I call pi_bus_add_device() I note that CS goes low for 5uS or so. CS goes low even if I add a device on another SPI host e.g. adding a device to VSPI causes a glicth on HSPI.

These glitches upsets the remote slave as the slave and our life tests. We have written test software looking for bus issues when temperature, emi, etc testing - CS without data is a fault.

How do I stop CS glitching?

v4.0-dev-562-g2b301f53e

mikemoy
Posts: 355
Joined: Fri Jan 12, 2018 9:10 pm

Re: spi_bus_add_device() causes CS glitch

Postby mikemoy » Tue Sep 03, 2019 4:36 pm

you might want to give more information. Are you using Arduino or esp-idf ?
you might want to share your code for the rest to check to see if your doing things right.

PeterR
Posts: 166
Joined: Mon Jun 04, 2018 2:47 pm

Re: spi_bus_add_device() causes CS glitch

Postby PeterR » Thu Sep 05, 2019 5:38 pm

esp-idf as posted version.

Code: Select all

void _can_spi_initialise()
{
    esp_err_t ret;
    spi_bus_config_t hwciCANSpiBusCfg={};
    
    //-- SPI BUS
    hwciCANSpiBusCfg.mosi_io_num = GPIO_CAN_MOSI;
    hwciCANSpiBusCfg.miso_io_num = GPIO_CAN_MISO;
    hwciCANSpiBusCfg.sclk_io_num = GPIO_CAN_SCLK;
    hwciCANSpiBusCfg.quadwp_io_num = -1;              // Not used
    hwciCANSpiBusCfg.quadhd_io_num = -1;              // Not used
    hwciCANSpiBusCfg.max_transfer_sz = 16;
    hwciCANSpiBusCfg.flags  =  0;

    //-- Initialise the SPI bus
    ret=spi_bus_initialize(SPI_HOST_CAN, &hwciCANSpiBusCfg, DMA_CAN_CHANNEL);
    ESP_ERROR_CHECK(ret);    
        
    //-- SPI CAN DEVICES
    spi_device_interface_config_t hwciDevCfgCAN0={};

    hwciDevCfgCAN0.clock_speed_hz=CAN_SPI_CLOCK;        // Limited to 10MHz by the MCP2515 (Full duplex via GPIO matrix otherwise 26MHz)
    hwciDevCfgCAN0.mode=CAN_SPI_MODE;                   // SPI mode 0 (MCP2515 supports modes 0,0 & 1,1)
    hwciDevCfgCAN0.queue_size=5;                        // Can queue upto 5 transactions at a time
    //hwciDevCfgCAN0.input_delay_ns = 50;                 // Allows us to work at 10MHz but also reduces CAN throughput (extra setup?)
   
#if CAN1 == CAN_MCP2515
    spi_device_interface_config_t hwciDevCfgCAN1={};    
        
    hwciDevCfgCAN1 = hwciDevCfgCAN0;
    hwciDevCfgCAN1.spics_io_num = GPIO_CAN_CS1;

    ret=spi_bus_add_device(SPI_HOST_CAN, &hwciDevCfgCAN1, &spiCANDeviceHandle[1]);   
    ESP_ERROR_CHECK(ret);    
#endif    
      
    return;
} //-- endfn _can_spi_initialise() --//

mikemoy
Posts: 355
Joined: Fri Jan 12, 2018 9:10 pm

Re: spi_bus_add_device() causes CS glitch

Postby mikemoy » Sat Sep 07, 2019 1:44 pm

Question, in your code, why are you not adding hwciDevCfgCAN0 ?
spi_bus_add_device(SPI_HOST_CAN, &hwciDevCfgCAN0, &spiCANDeviceHandle[1]);

PeterR
Posts: 166
Joined: Mon Jun 04, 2018 2:47 pm

Re: spi_bus_add_device() causes CS glitch

Postby PeterR » Tue Sep 10, 2019 6:46 pm

CAN0 SPI was used in an earlier hardware configuration. Now I use ESP CAN. Its auto so no worries.

WiFive
Posts: 2622
Joined: Tue Dec 01, 2015 7:35 am

Re: spi_bus_add_device() causes CS glitch

Postby WiFive » Wed Sep 11, 2019 2:40 am

Have you tried setting the gpio high before you call spi_bus_add_device? Also this will set the cs to gpio0 if you don't set it to -1

Code: Select all

spi_device_interface_config_t hwciDevCfgCAN0={}

PeterR
Posts: 166
Joined: Mon Jun 04, 2018 2:47 pm

Re: spi_bus_add_device() causes CS glitch

Postby PeterR » Fri Sep 13, 2019 10:01 am

Thanks all. Turns out to be a typo in board configuration settings #if #elif. Essentially this resulted in VSPI and HSPI channels being given the same CS pin.
All working now.

Who is online

Users browsing this forum: No registered users and 27 guests