I have problem with SPI master on ESP32.
I compile and upload the example of spi-master https://github.com/espressif/esp-idf/tr ... spi_master
and get the follow picture: On this picture CLK is fine, and we can see that some data is transfer (red line).
I took this example as a basis:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "driver/spi_master.h"
#include "soc/gpio_struct.h"
#include "driver/gpio.h"
#define PIN_NUM_MISO 25
#define PIN_NUM_MOSI 23
#define PIN_NUM_CLK 19
#define PIN_NUM_CS 22
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
// ret=spi_device_transmit(spi, &t); //Transmit!
ret=spi_device_queue_trans(spi, &t, portMAX_DELAY);
assert(ret==ESP_OK); //Should have had no issues.
}
void app_main()
{
esp_err_t ret;
spi_device_handle_t spi;
spi_bus_config_t buscfg;
buscfg.miso_io_num = PIN_NUM_MISO;
buscfg.mosi_io_num=PIN_NUM_MOSI;
buscfg.sclk_io_num=PIN_NUM_CLK;
buscfg.quadwp_io_num=-1;
buscfg.quadhd_io_num=-1;
spi_device_interface_config_t devcfg;
devcfg.clock_speed_hz=100000; //Clock out
devcfg.mode=0; //SPI mode 0
devcfg.spics_io_num=PIN_NUM_CS; //CS pin
devcfg.queue_size=7; //We want to be able to queue 7 transactions at a time
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 0); // Initialize the SPI bus
printf("spi_bus_init = %d\n", ret);
ESP_ERROR_CHECK(ret);
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi); // Attach the MAX3421 to the SPI bus
printf("spi_bus_add_device = %d\n", ret);
ESP_ERROR_CHECK(ret);
while ( 1 )
{
printf("LED On\n");
lcd_cmd(spi, 0xA2);
vTaskDelay(1000 / portTICK_PERIOD_MS);
printf("LED OFF\n");
lcd_cmd(spi, 0xA2);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
"ret=spi_device_transmit(spi, &t); //Transmit!"
or
"ret=spi_device_queue_trans(spi, &t, portMAX_DELAY);"
However, I get very strange signal on CLK line: Also I don't use DMA
So, the main question - what I do wrong? I can't understand what else needs to be configured that signal on CLK line in SPI master mode will be correct.ret=spi_bus_initialize(HSPI_HOST, &buscfg, 0); // Initialize the SPI bus
Thank you