Doesn't work VSPI and I2C at same time.

akira.matsuda
Posts: 2
Joined: Sat Jul 28, 2018 8:41 pm

Doesn't work VSPI and I2C at same time.

Postby akira.matsuda » Sat Jul 28, 2018 8:55 pm

Hi, I got a problem and want to know the reason of this weird behavior of esp-idf or esp32.

The problem occurs when I connect sensors with SPI and I2C, VSPI and I2C both at same time.
When I assign these pins for SPI and I2C, esp32 could not read datas from I2C sensor because of I2C command time out (ESP_ERR_TIMEOUT).

Code: Select all

// I2C
gpio_num_t SDA = GPIO_NUM_21;
gpio_num_t SCL = GPIO_NUM_22;

// SPI
gpio_num_t sclk = GPIO_NUM_18;
gpio_num_t miso = GPIO_NUM_23;
gpio_num_t mosi = GPIO_NUM_19;
gpio_num_t cs = GPIO_NUM_5;
I'm using this library.
https://github.com/natanaeljr/esp32-MPU-driver for I2C sensor(MPU9250).

I try to change I2C pin assign to SCD = GPIO_NUM_26, SCL = GPIO_NUM_15, then it works.
Is anybody knows why these above configuration could not work?

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

Re: Doesn't work VSPI and I2C at same time.

Postby WiFive » Sun Jul 29, 2018 5:19 am

If you init vspi in quad mode with default pins it will use 21 & 22

akira.matsuda
Posts: 2
Joined: Sat Jul 28, 2018 8:41 pm

Re: Doesn't work VSPI and I2C at same time.

Postby akira.matsuda » Sun Aug 19, 2018 5:21 pm

Thank you for your reply.

I don't use quad mode.
The following code is my setting of spi_bus_config_t.

Code: Select all

bus_config.quadwp_io_num = -1; // Not used
bus_config.quadhd_io_num = -1; // Not used
bus_config.flags = (SPI_DEVICE_TXBIT_LSBFIRST | SPI_DEVICE_RXBIT_LSBFIRST | SPI_DEVICE_NO_DUMMY)

rsimpsonbusa
Posts: 124
Joined: Tue May 17, 2016 8:12 pm

Re: Doesn't work VSPI and I2C at same time.

Postby rsimpsonbusa » Thu Sep 06, 2018 12:38 am

Hi akiro.matsuda.

I ALMOST have the same config.
In a define.h include file I have

Code: Select all

#define FMOSI							23
#define FMISO							19
#define FCLK							18
#define FCS							5

vs your 

gpio_num_t sclk = GPIO_NUM_18; --same
gpio_num_t miso = GPIO_NUM_23; -- actually mosi
gpio_num_t mosi = GPIO_NUM_19; -- actually miso
gpio_num_t cs = GPIO_NUM_5; -- same

#define SDAW                			                21      // SDA
#define SCLW                			                22   // SCL
then in the main file

Code: Select all

int ret;
	spi_bus_config_t 				buscfg;
	spi_device_interface_config_t 	devcfg;
	memset(&buscfg,0,sizeof(buscfg));
	memset(&devcfg,0,sizeof(devcfg));
	buscfg.mosi_io_num=MOSI;
	buscfg .miso_io_num=MISO;
	buscfg.sclk_io_num=CLK;
	buscfg.quadwp_io_num=-1;
	buscfg .quadhd_io_num=-1;
	//Initialize the SPI bus
	ret=spi_bus_initialize(VSPI_HOST, &buscfg, 0);
	assert(ret == ESP_OK);

	devcfg .clock_speed_hz=40000000;              	//Clock out at 40 MHz
	devcfg.mode=0;                                	//SPI mode 0
	devcfg.spics_io_num=CS;               			//CS pin
	devcfg.queue_size=7;                         	//We want to be able to queue 7 transactions at a time
	devcfg.flags=SPI_DEVICE_HALFDUPLEX;

	ret=spi_bus_add_device(VSPI_HOST, &devcfg, &spi);
	if (ret==ESP_OK)
......

I dont know if the IOMUX pins are fixed and cannot be changed, but mine works great at 40MHZ the SPI bus and 700K the I2C (Oled).

Good luck

Who is online

Users browsing this forum: No registered users and 157 guests