I am starting with ESP32
I am trying to connect ESP32 with ADC1120 over SPI. But without success so far.
When I probe the SCLK pin with an oscilloscope I can see there is not any clock signal.
I am using a GPIO matrix to route the signals.
I have 5 LEDs on board so I use them as debug signals for stepping.
at the end of the code, all 5 LEDs are ON so that means SPI init and device registration pass without any problem.
Thanks for any advice
CODE:
Code: Select all
#include "driver/spi_common.h"
#include "driver/spi_master.h"
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "soc/gpio_struct.h"
#include "driver/gpio.h"
#define PIN_NUM_CS 25
#define DATA_READY_PIN 33
#define PIN_NUM_MOSI 13
#define PIN_NUM_MISO 32
#define PIN_NUM_CLK 14
void lcd_spi_pre_transfer_callback(spi_transaction_t *t)
{
}
void app_main() {
gpio_set_direction(16, GPIO_MODE_OUTPUT);
gpio_set_direction(17, GPIO_MODE_OUTPUT);
gpio_set_direction(5, GPIO_MODE_OUTPUT);
gpio_set_direction(18, GPIO_MODE_OUTPUT);
gpio_set_direction(19, GPIO_MODE_OUTPUT);
esp_err_t ret;
spi_device_handle_t spi;
spi_bus_config_t buscfg={
.miso_io_num=PIN_NUM_MISO,
.mosi_io_num=PIN_NUM_MOSI,
.sclk_io_num=PIN_NUM_CLK,
.quadhd_io_num=-1,
.quadwp_io_num=-1,
};
spi_device_interface_config_t devcfg={
.clock_speed_hz=10*1000*1000, //Clock out at 10 MHz
.mode=1, //SPI mode 0
.spics_io_num=PIN_NUM_CS, //CS pin
.queue_size=7, //We want to be able to queue 7 transactions at a time
.pre_cb=lcd_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line
};
ret=spi_bus_initialize(VSPI_HOST, &buscfg,0);
gpio_set_level(16, 1);
assert(ret==ESP_OK);
gpio_set_level(17, 1);
ret=spi_bus_add_device(VSPI_HOST, &devcfg, &spi);
gpio_set_level(5, 1);
assert(ret==ESP_OK);
gpio_set_level(18, 1);
}