ESP32 SPI driver 4.2inc waveshare e-paper but can't refresh
Posted: Tue Mar 30, 2021 12:32 pm
I have designed a 4.2-inch E-paper(ink screen) driver board, and the control is ESP-WROOM-32. There is no problem in blink example by IDF-included. When I modify the driver from the official of the screen , it is unable to refresh . Because this is the first time I use ESP32, I suspect that my SPI setting has a problem. Can someone help me
spi devconfig.c
devconfig.h
[/img]
- /* Blink Example
- This example code is in the Public Domain (or CC0 licensed, at your option.)
- Unless required by applicable law or agreed to in writing, this
- software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
- CONDITIONS OF ANY KIND, either express or implied.
- */
- #include "freertos/FreeRTOS.h"
- #include <stdio.h>
- #include "driver/gpio.h"
- #include "sdkconfig.h"
- #include "driver/spi_common.h"
- #include "driver/spi_master.h"
- #include "freertos/task.h"
- #include "EPD_Test.h"
- #include "EPD_4in2.h"
- /* Can use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
- or you can edit the following line and set a number here.
- */
- #define BLINK_GPIO 16//0 is turn on,1 is turn off
- //the list pins are controled by spi
- //#define PIN_NUM_MISO 37
- #define PIN_NUM_MOSI 13
- #define PIN_NUM_CLK 14
- #define PIN_NUM_CS 15
- #define PIN_NUM_RST 2
- #define PIN_NUM_BUSY 4
- #define PIN_NUM_DC 12
- esp_err_t ret;
- spi_device_handle_t spi;
- spi_transaction_t t;
- void gpio_init(void){
- /* Configure the IOMUX register for pad BLINK_GPIO (some pads are
- muxed to GPIO on reset already, but some default to other
- functions and need to be switched to GPIO. Consult the
- Technical Reference for a list of pads and their default
- functions.)
- */
- gpio_pad_select_gpio(BLINK_GPIO);
- /* Set the GPIO as a push/pull output */
- gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
- /*e-paper rest pin ,mode is output*/
- gpio_pad_select_gpio(PIN_NUM_RST);
- gpio_set_direction(PIN_NUM_RST, GPIO_MODE_OUTPUT);
- /*e-paper data or command pin ,mode is output*/
- gpio_pad_select_gpio(PIN_NUM_DC);
- gpio_set_direction(PIN_NUM_DC, GPIO_MODE_OUTPUT);
- /*e-paper busy pin ,mode is input*/
- gpio_pad_select_gpio(PIN_NUM_BUSY);
- gpio_set_direction(PIN_NUM_BUSY, GPIO_MODE_INPUT);
- }
- void spi_init(void){
- spi_bus_config_t my_config={
- .miso_io_num=-1,
- .mosi_io_num=PIN_NUM_MOSI,
- .sclk_io_num=PIN_NUM_CLK,
- .quadwp_io_num=-1,
- .quadhd_io_num=-1,
- .max_transfer_sz=1000,
- };
- spi_device_interface_config_t my_device={
- .flags=SPI_DEVICE_NO_DUMMY,
- .input_delay_ns=10,
- .command_bits=0,
- .address_bits=0,
- .clock_speed_hz=10*1000*1000,
- .mode=0,
- .spics_io_num=-1,
- .queue_size=7,
- };
- ret=spi_bus_initialize(HSPI_HOST, &my_config, 0);
- ESP_ERROR_CHECK(ret);
- ret=spi_bus_add_device(HSPI_HOST, &my_device, &spi);
- ESP_ERROR_CHECK(ret);
- }
- void app_main(void)
- {
- gpio_init();
- spi_init();
- printf("SPI gpio Init success!");
- //DEV_Module_Init();
- //EPD_4IN2_Init();
- printf("EPD Init success!");
- //EPD_4IN2_Clear();
- EPD_4in2_test();
- while(1) {
- /* Blink off (output low) */
- printf("Turning off the LED\n");
- gpio_set_level(BLINK_GPIO, 0);
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- /* Blink on (output high) */
- printf("Turning on the LED\n");
- gpio_set_level(BLINK_GPIO, 1);
- vTaskDelay(9000 / portTICK_PERIOD_MS);
- }
- }
- #include "DEV_Config.h"
- #include <string.h>
- extern esp_err_t ret;
- extern spi_device_handle_t spi;
- extern spi_transaction_t t;
- //SPI_TRANS_USE_RXDATA
- void DEV_SPI_WriteByte(UBYTE value)
- {
- //memset(&t,0,sizeof(t));
- t.flags=SPI_TRANS_USE_TXDATA;
- t.length=8;
- t.tx_data[0]=value;
- t.rx_buffer=NULL;
- //HAL_SPI_Transmit(&hspi1, &value, 1, 1000);
- //spi_device_transmit(spi,&t);
- spi_device_polling_transmit(spi,&t);
- assert(ret==ESP_OK); //Should have had no issues.
- }
- void DEV_Module_Init(void)
- {
- DEV_Digital_Write(EPD_DC_PIN, 0);
- DEV_Digital_Write(EPD_CS_PIN, 0);
- DEV_Digital_Write(EPD_RST_PIN, 1);
- }
- void DEV_Module_Exit(void)
- {
- DEV_Digital_Write(EPD_DC_PIN, 0);
- DEV_Digital_Write(EPD_CS_PIN, 0);
- //close 5V
- DEV_Digital_Write(EPD_RST_PIN, 0);
- }
- #ifndef _DEV_CONFIG_H_
- #define _DEV_CONFIG_H_
- #pragma once
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "driver/gpio.h"
- #include <stdint.h>
- #include "driver/spi_master.h"
- /**
- * data
- **/
- #define UBYTE uint8_t
- #define UWORD uint16_t
- #define UDOUBLE uint32_t
- /**
- * e-Paper GPIO
- **/
- #define EPD_RST_PIN 2
- #define EPD_DC_PIN 12
- #define EPD_CS_PIN 15
- #define EPD_BUSY_PIN 4
- /**
- * GPIO read and write
- **/
- #define DEV_Digital_Write(_pin, _value) gpio_set_level(_pin, _value == 0? 0:1)
- #define DEV_Digital_Read(_pin) gpio_get_level(_pin)
- /**
- * delay x ms
- **/
- //#define DEV_Delay_ms(__xms) vTaskDelay(__xms/ portTICK_RATE_MS)
- #define DEV_Delay_ms(__xms) vTaskDelay(__xms/ portTICK_RATE_MS)
- void DEV_SPI_WriteByte(UBYTE value);
- void DEV_Module_Init(void);
- void DEV_Module_Exit(void);
- #endif