SPI on ESP32 module - No clock signal

aaantonkaaa
Posts: 9
Joined: Tue Nov 17, 2020 12:19 am

SPI on ESP32 module - No clock signal

Postby aaantonkaaa » Tue Nov 17, 2020 12:34 am

Hi there
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);
    

}



becorey
Posts: 92
Joined: Sat Mar 28, 2020 4:18 pm

Re: SPI on ESP32 module - No clock signal

Postby becorey » Thu Nov 19, 2020 5:55 am

It looks like you have initialized everything, but not sent any transfer over SPI. The clock signal will only be present during the transfer. Try to spi read or write to the adc and probe sclk during that time.

aaantonkaaa
Posts: 9
Joined: Tue Nov 17, 2020 12:19 am

Re: SPI on ESP32 module - No clock signal

Postby aaantonkaaa » Fri Nov 20, 2020 7:38 pm

yes :) you are right :) I have added some code ( copy-paste from LCD example)

Code: Select all

void lcd_cmd(spi_device_handle_t spi, const uint8_t cmd)
{
    esp_err_t ret;
    spi_transaction_t t;
    memset(&t, 0, sizeof(t));       //Zero out the transaction
    t.length=8;                     //Command is 8 bits
    t.tx_buffer=&cmd;               //The data is the cmd itself
    t.user=(void*)0;                //D/C needs to be set to 0
    ret=spi_device_polling_transmit(spi, &t);  //Transmit!
    assert(ret==ESP_OK);            //Should have had no issues.
}
and then in main

lcd_cmd(spi, 0x06);

I can see the clock signal :) but not aby data are sent to ADC. MOSI has not changed :/
Maybe I have to solve the data ready signal first.

Thanks a lot
Best regards
Roman
Attachments
Screenshot_6.png
Screenshot_6.png (34.42 KiB) Viewed 5190 times

aaantonkaaa
Posts: 9
Joined: Tue Nov 17, 2020 12:19 am

Re: SPI on ESP32 module - No clock signal

Postby aaantonkaaa » Fri Nov 20, 2020 7:59 pm

hmm, data ready pin is normally at high level .. no that is ok ... but no outgoing data on data lines :/

aaantonkaaa
Posts: 9
Joined: Tue Nov 17, 2020 12:19 am

Re: SPI on ESP32 module - No clock signal

Postby aaantonkaaa » Fri Nov 20, 2020 9:15 pm

I wrote a small program which has to test the MOSI(IO13 pin in my case) pin and I can see there is not ticking on IO13

Code: Select all


#define PIN_NUM_MOSI 13

void app_main() {
    gpio_reset_pin(PIN_NUM_MOSI);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(PIN_NUM_MOSI, GPIO_MODE_OUTPUT);
    while(1) {
        /* Blink off (output low) */
	printf("Turning off the LED\n");
        gpio_set_level(PIN_NUM_MOSI, 0);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        /* Blink on (output high) */
	printf("Turning on the LED\n");
        gpio_set_level(PIN_NUM_MOSI, 1);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
      

}


becorey
Posts: 92
Joined: Sat Mar 28, 2020 4:18 pm

Re: SPI on ESP32 module - No clock signal

Postby becorey » Sat Nov 21, 2020 6:07 am

Check if your GPIO library refers to the physical pin numbers or the IO numbers, that's always something that can be mixed up. (If you were telling it to toggle physical pin 13 and you're probing on IO13, they're different pins).

Maybe search for some other SPI examples, see if you can get MOSI to work maybe with a different approach or different GPIO library.

aaantonkaaa
Posts: 9
Joined: Tue Nov 17, 2020 12:19 am

Re: SPI on ESP32 module - No clock signal

Postby aaantonkaaa » Sat Nov 21, 2020 11:14 pm

becorey wrote:
Sat Nov 21, 2020 6:07 am
Check if your GPIO library refers to the physical pin numbers or the IO numbers, that's always something that can be mixed up. (If you were telling it to toggle physical pin 13 and you're probing on IO13, they're different pins).

Maybe search for some other SPI examples, see if you can get MOSI to work maybe with a different approach or different GPIO library.
you are right with the idea about the issue with pin mapping :)
I changed IO13 to another pin and now it WORKS perfectly :)

THANKS a lot

Best regards

Who is online

Users browsing this forum: No registered users and 75 guests