ESP32 SPI driver 4.2inc waveshare e-paper but can't refresh

User avatar
liankafohali
Posts: 4
Joined: Sat Mar 27, 2021 2:24 am

ESP32 SPI driver 4.2inc waveshare e-paper but can't refresh

Postby liankafohali » 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 :?:
snipaste_20210330_202053.jpg
The e-paper driver
snipaste_20210330_202053.jpg (463.45 KiB) Viewed 2763 times
[/img]
snipaste_20210330_202109.jpg
ESP32
snipaste_20210330_202109.jpg (354.1 KiB) Viewed 2763 times
  1. /* Blink Example
  2.  
  3.    This example code is in the Public Domain (or CC0 licensed, at your option.)
  4.  
  5.    Unless required by applicable law or agreed to in writing, this
  6.    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  7.    CONDITIONS OF ANY KIND, either express or implied.
  8. */
  9. #include "freertos/FreeRTOS.h"
  10. #include <stdio.h>
  11. #include "driver/gpio.h"
  12. #include "sdkconfig.h"
  13. #include "driver/spi_common.h"
  14. #include "driver/spi_master.h"
  15. #include "freertos/task.h"
  16.  
  17.  
  18.  
  19.  
  20. #include "EPD_Test.h"
  21. #include "EPD_4in2.h"
  22.  
  23. /* Can use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
  24.    or you can edit the following line and set a number here.
  25. */
  26. #define BLINK_GPIO 16//0 is turn on,1 is turn off
  27. //the list pins are controled by spi
  28. //#define PIN_NUM_MISO 37
  29. #define PIN_NUM_MOSI 13
  30. #define PIN_NUM_CLK  14
  31.  
  32. #define PIN_NUM_CS   15
  33. #define PIN_NUM_RST 2
  34. #define PIN_NUM_BUSY 4
  35. #define PIN_NUM_DC 12
  36.  
  37.  
  38. esp_err_t ret;
  39. spi_device_handle_t spi;
  40. spi_transaction_t t;
  41.  
  42. void gpio_init(void){
  43.     /* Configure the IOMUX register for pad BLINK_GPIO (some pads are
  44.        muxed to GPIO on reset already, but some default to other
  45.        functions and need to be switched to GPIO. Consult the
  46.        Technical Reference for a list of pads and their default
  47.        functions.)
  48.     */
  49.     gpio_pad_select_gpio(BLINK_GPIO);
  50.     /* Set the GPIO as a push/pull output */
  51.     gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
  52.     /*e-paper rest pin ,mode is output*/
  53.     gpio_pad_select_gpio(PIN_NUM_RST);
  54.     gpio_set_direction(PIN_NUM_RST, GPIO_MODE_OUTPUT);
  55.     /*e-paper data or command pin ,mode is output*/
  56.     gpio_pad_select_gpio(PIN_NUM_DC);
  57.     gpio_set_direction(PIN_NUM_DC, GPIO_MODE_OUTPUT);
  58.     /*e-paper busy pin ,mode is input*/
  59.     gpio_pad_select_gpio(PIN_NUM_BUSY);
  60.     gpio_set_direction(PIN_NUM_BUSY, GPIO_MODE_INPUT);  
  61. }
  62.  
  63. void spi_init(void){
  64.  
  65.     spi_bus_config_t my_config={
  66.         .miso_io_num=-1,
  67.         .mosi_io_num=PIN_NUM_MOSI,
  68.         .sclk_io_num=PIN_NUM_CLK,
  69.         .quadwp_io_num=-1,
  70.         .quadhd_io_num=-1,
  71.         .max_transfer_sz=1000,
  72.     };
  73.    
  74.     spi_device_interface_config_t my_device={
  75.         .flags=SPI_DEVICE_NO_DUMMY,
  76.         .input_delay_ns=10,
  77.         .command_bits=0,
  78.         .address_bits=0,
  79.         .clock_speed_hz=10*1000*1000,
  80.         .mode=0,
  81.         .spics_io_num=-1,
  82.         .queue_size=7,
  83.     };
  84.  
  85.  
  86.     ret=spi_bus_initialize(HSPI_HOST, &my_config, 0);
  87.     ESP_ERROR_CHECK(ret);
  88.  
  89.     ret=spi_bus_add_device(HSPI_HOST, &my_device, &spi);
  90.     ESP_ERROR_CHECK(ret);
  91.    
  92.  
  93.  
  94. }
  95.  
  96. void app_main(void)
  97. {
  98.     gpio_init();
  99.     spi_init();
  100.     printf("SPI gpio Init success!");
  101.     //DEV_Module_Init();
  102.     //EPD_4IN2_Init();
  103.     printf("EPD Init success!");
  104.     //EPD_4IN2_Clear();
  105.     EPD_4in2_test();
  106.     while(1) {
  107.         /* Blink off (output low) */
  108.     printf("Turning off the LED\n");
  109.         gpio_set_level(BLINK_GPIO, 0);
  110.         vTaskDelay(1000 / portTICK_PERIOD_MS);
  111.         /* Blink on (output high) */
  112.     printf("Turning on the LED\n");
  113.         gpio_set_level(BLINK_GPIO, 1);
  114.         vTaskDelay(9000 / portTICK_PERIOD_MS);
  115.     }
  116. }
spi devconfig.c
  1. #include "DEV_Config.h"
  2. #include <string.h>
  3.  
  4. extern esp_err_t ret;
  5. extern spi_device_handle_t spi;
  6.  
  7. extern spi_transaction_t t;
  8. //SPI_TRANS_USE_RXDATA
  9.  
  10.  
  11. void DEV_SPI_WriteByte(UBYTE value)
  12. {
  13.     //memset(&t,0,sizeof(t));
  14.     t.flags=SPI_TRANS_USE_TXDATA;
  15.     t.length=8;
  16.     t.tx_data[0]=value;
  17.     t.rx_buffer=NULL;
  18.     //HAL_SPI_Transmit(&hspi1, &value, 1, 1000);
  19.     //spi_device_transmit(spi,&t);
  20.     spi_device_polling_transmit(spi,&t);
  21.     assert(ret==ESP_OK);            //Should have had no issues.
  22.  
  23. }
  24.  
  25. void DEV_Module_Init(void)
  26. {
  27.     DEV_Digital_Write(EPD_DC_PIN, 0);
  28.     DEV_Digital_Write(EPD_CS_PIN, 0);
  29.     DEV_Digital_Write(EPD_RST_PIN, 1);
  30. }
  31.  
  32. void DEV_Module_Exit(void)
  33. {
  34.     DEV_Digital_Write(EPD_DC_PIN, 0);
  35.     DEV_Digital_Write(EPD_CS_PIN, 0);
  36.  
  37.     //close 5V
  38.     DEV_Digital_Write(EPD_RST_PIN, 0);
  39. }
devconfig.h
  1. #ifndef _DEV_CONFIG_H_
  2. #define _DEV_CONFIG_H_
  3.  
  4. #pragma once
  5. #include "freertos/FreeRTOS.h"
  6. #include "freertos/task.h"
  7. #include "driver/gpio.h"
  8. #include <stdint.h>
  9.  
  10. #include "driver/spi_master.h"
  11. /**
  12.  * data
  13. **/
  14. #define UBYTE   uint8_t
  15. #define UWORD   uint16_t
  16. #define UDOUBLE uint32_t
  17.  
  18. /**
  19.  * e-Paper GPIO
  20. **/
  21. #define EPD_RST_PIN     2
  22. #define EPD_DC_PIN      12
  23. #define EPD_CS_PIN      15
  24. #define EPD_BUSY_PIN    4
  25.  
  26. /**
  27.  * GPIO read and write
  28. **/
  29. #define DEV_Digital_Write(_pin, _value) gpio_set_level(_pin, _value == 0? 0:1)
  30. #define DEV_Digital_Read(_pin) gpio_get_level(_pin)
  31.  
  32. /**
  33.  * delay x ms
  34. **/
  35. //#define DEV_Delay_ms(__xms) vTaskDelay(__xms/ portTICK_RATE_MS)
  36. #define DEV_Delay_ms(__xms) vTaskDelay(__xms/ portTICK_RATE_MS)
  37.  
  38. void DEV_SPI_WriteByte(UBYTE value);
  39.  
  40. void DEV_Module_Init(void);
  41. void DEV_Module_Exit(void);
  42. #endif
snipaste_20210330_202941.jpg
The monitor output
snipaste_20210330_202941.jpg (376.76 KiB) Viewed 2763 times

ESP_Sprite
Posts: 9759
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 SPI driver 4.2inc waveshare e-paper but can't refresh

Postby ESP_Sprite » Wed Mar 31, 2021 3:38 am

Not sure if it matters, but in your GPIO initialization, you seem to have forgotten to also initialize CS as an output.

User avatar
liankafohali
Posts: 4
Joined: Sat Mar 27, 2021 2:24 am

Re: ESP32 SPI driver 4.2inc waveshare e-paper but can't refresh

Postby liankafohali » Wed Mar 31, 2021 8:07 am

thank you for you reply,this is my carelessness,my problem has been solved。 :D

Who is online

Users browsing this forum: No registered users and 55 guests