ESP32 Spi master miso also ready pin from slave
Posted: Mon Jun 20, 2022 9:42 pm
Hey,
I'm trying to communicate with the MCP355x Datasheet, but the pin MISO also contains the READY function. If I just configure the SPI, I get communication. Only every second value is good. I think this is because the ADC takes time to convert the voltage level. If I only configure the GPIOs I get the switch until MCP355x is done converting. I use an oscilloscope to check the outputs.
To tell the ADC to start converting the CS pin needs to toggle between low and high (single conversation mode) and while CS in low needs to read MISO/READY pin and that's where the problem starts. I can't set MISO pin as input and use the SPI not sure, just set wrong or is not possible.
One idea to solve this is to connect two GPIOs with Slave MISO/READY, one for the normal SPI and the other to check the conversation readiness state. Bad idear or is this a proper solution.
Better if someone can find a problem in my code.
Initialization:
Toggle CS and Check MISO:
I'm trying to communicate with the MCP355x Datasheet, but the pin MISO also contains the READY function. If I just configure the SPI, I get communication. Only every second value is good. I think this is because the ADC takes time to convert the voltage level. If I only configure the GPIOs I get the switch until MCP355x is done converting. I use an oscilloscope to check the outputs.
To tell the ADC to start converting the CS pin needs to toggle between low and high (single conversation mode) and while CS in low needs to read MISO/READY pin and that's where the problem starts. I can't set MISO pin as input and use the SPI not sure, just set wrong or is not possible.
One idea to solve this is to connect two GPIOs with Slave MISO/READY, one for the normal SPI and the other to check the conversation readiness state. Bad idear or is this a proper solution.
Better if someone can find a problem in my code.
Initialization:
Code: Select all
spi_bus_config_t bus_cfg = {};
bus_cfg.mosi_io_num = -1;
bus_cfg.miso_io_num = MISO_PIN;
bus_cfg.sclk_io_num = SCLK_PIN;
bus_cfg.quadwp_io_num = -1;
bus_cfg.quadhd_io_num = -1;
bus_cfg.max_transfer_sz = 0;
spi_device_interface_config_t dev_cfg = {};
dev_cfg.command_bits = 0;
dev_cfg.address_bits = 0;
dev_cfg.mode = 0;
dev_cfg.clock_speed_hz = 5000000;
dev_cfg.spics_io_num = CS_PIN;
dev_cfg.queue_size = 2;
// Setup GPIO Pins
gpio_config_t cs_cfg;
cs_cfg.pin_bit_mask = 1ULL << CS_PIN;
cs_cfg.mode = GPIO_MODE_OUTPUT;
cs_cfg.pull_up_en = GPIO_PULLUP_DISABLE;
cs_cfg.pull_down_en = GPIO_PULLDOWN_DISABLE;
cs_cfg.intr_type = GPIO_INTR_DISABLE;
status |= gpio_config(&cs_cfg);
ESP_LOGI(TAG, "%i", status);
gpio_config_t miso_cfg;
miso_cfg.pin_bit_mask = 1ULL << MISO_PIN;
miso_cfg.mode = GPIO_MODE_INPUT;
miso_cfg.pull_up_en = GPIO_PULLUP_DISABLE;
miso_cfg.pull_down_en = GPIO_PULLDOWN_DISABLE;
miso_cfg.intr_type = GPIO_INTR_DISABLE;
status |= gpio_config(&miso_cfg);
ESP_LOGI(TAG, "%i", status);
// Inizalice SPI Bus
status = spi_bus_initialize(SPI2_HOST, &bus_cfg, SPI_DMA_DISABLED);
// Add Device to SPI Bus
status = spi_bus_add_device(SPI2_HOST, &dev_cfg, &this->device_handle);
Code: Select all
do
{
gpio_set_level(CS_PIN, 1);
vTaskDelay(15 / portTICK_PERIOD_MS);
gpio_set_level(CS_PIN, 0);
vTaskDelay(15 / portTICK_PERIOD_MS);
} while (gpio_get_level(MISO_PIN) == 1);