2018年10月26日 星期五

DIY - ESP32:ESP32 SPI Master 主驅動 API 函數結構件(十七)

DIY - ESP32:ESP32 SPI Master 主驅動 API 函數結構件(十七):

在使用 ESP32 的 ESP-IDF SDK 內的 SPI 的應用程式接口(API)函數 (Function),需要使用到 spi_master 內的結構件(Structure / Struct),這是 SPI 儲存 SPI 的資料和設定數據,也是非常重要的資料。

C語言的結構件(Structure / Struct)
結構件(Structure / Struct):
  1. struct spi_bus_config_t
  2. struct spi_device_interface_config_t
  3. struct spi_transaction_t
  4. struct spi_transaction_ext_t  

1. struct spi_bus_config_t:
This is a configuration structure for a SPI bus。You can use this structure to specify the GPIO pins of the bus. Normally, the driver will use the GPIO matrix to route the signals。An exception is made when all signals either can be routed through the IO_MUX or are -1。 In that case,the IO_MUX is used,allowing for >40MHz speeds。
Public Members
Desription
int mosi_io_num
GPIO pin for Master Out Slave In (=spi_d) signal, or -1 if not used.
int miso_io_num
GPIO pin for Master In Slave Out (=spi_q) signal, or -1 if not used.
int sclk_io_num
GPIO pin for Spi CLocK signal, or -1 if not used.
int quadwp_io_num
GPIO pin for WP (Write Protect) signal which is used as D2 in 4-bit communication modes, or -1 if not used.
int quadhd_io_num
GPIO pin for HD (HolD) signal which is used as D3 in 4-bit communication modes, or -1 if not used.
int max_transfer_sz
Maximum transfer size, in bytes. Defaults to 4094 if 0.
uint32_t flags
Abilities of bus to be checked by the driver. Or-ed value of SPICOMMON_BUSFLAG_* flags.

2. struct spi_device_interface_config_t:
This is a configuration for a SPI slave device that is connected to one of the SPI buses。
Public Members
Desription
uint8_t command_bits
Default amount of bits in command phase (0-16), used when SPI_TRANS_VARIABLE_CMD is not used, otherwise ignored.
uint8_t address_bits
Default amount of bits in address phase (0-64), used when SPI_TRANS_VARIABLE_ADDR is not used, otherwise ignored.
uint8_t dummy_bits
Amount of dummy bits to insert between address and data phase.
uint8_t mode
SPI mode (0-3)
uint8_t duty_cycle_pos
Duty cycle of positive clock, in 1/256th increments (128 = 50%/50% duty). Setting this to 0 (=not setting it) is equivalent to setting this to 128.
uint8_t cs_ena_pretrans
Amount of SPI bit-cycles the cs should be activated before the transmission (0-16). This only works on half-duplex transactions.
uint8_t cs_ena_posttrans
Amount of SPI bit-cycles the cs should stay active after the transmission (0-16)
int clock_speed_hz
Clock speed, divisors of 80MHz, in Hz. See SPI_MASTER_FREQ_*.
int input_delay_ns
Maximum data valid time of slave. The time required between SCLK and MISO valid, including the possible clock delay from slave to master. The driver uses this value to give an extra delay before the MISO is ready on the line. Leave at 0 unless you know you need a delay. For better timing performance at high frequency (over 8MHz), it’s suggest to have the right value.
int spics_io_num
CS GPIO pin for this device, or -1 if not used.
uint32_t flags
Bitwise OR of SPI_DEVICE_* flags.
int queue_size
Transaction queue size. This sets how many transactions can be ‘in the air’ (queued using spi_device_queue_trans but not yet finished using spi_device_get_trans_result) at the same time.
transaction_cb_t pre_cb
Callback to be called before a transmission is started. This callback is called within interrupt context.
transaction_cb_t post_cb
Callback to be called after a transmission has completed. This callback is called within interrupt context.

3. struct spi_transaction_t:
This structure describes one SPI transaction. The descriptor should not be modified until the transaction finishes。
Public Members
Desription
uint32_t flags
Bitwise OR of SPI_TRANS_* flags.
uint16_t cmd
Command data, of which the length is set in the command_bits of spi_device_interface_config_t.
uint64_t addr
Address data, of which the length is set in the address_bits of spi_device_interface_config_t.
size_t length
Total data length, in bits.
size_t rxlength
Total data length received, should be not greater than length in full-duplex mode (0 defaults this to the value of length).
void *user
User-defined variable. Can be used to store eg transaction ID.
const void *tx_buffer
Pointer to transmit buffer, or NULL for no MOSI phase.
uint8_t tx_data[4]
If SPI_USE_TXDATA is set, data set here is sent directly from this variable.
void *rx_buffer
Pointer to receive buffer, or NULL for no MISO phase. Written by 4 bytes-unit if DMA is used.
uint8_t rx_data[4]
If SPI_USE_RXDATA is set, data is received directly to this variable.

4. struct spi_transaction_ext_t: 
This struct is for SPI transactions which may change their address and command length。 Please do set the flags in base to SPI_TRANS_VARIABLE_CMD_ADR to use the bit length here。 
Public Members
Desription
struct spi_transaction_t base
Transaction data, so that pointer to spi_transaction_t can be converted into spi_transaction_ext_t.
uint8_t command_bits
The command length in this transaction, in bits.
uint8_t address_bits
The address length in this transaction, in bits.

相關網址:
※ DIY - ESP32:ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏電路(十三)
※ DIY - ESP32:ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏程式(十四)
※ DIY - ESP32:ESP32 SPI 驅動 IO 介紹(十五)
※ DIY - ESP32:ESP32 SPI Master 主驅動 API 函數(十六)

2018年 10月 26日 天氣報告
氣溫:27.2@ 21:20
相對濕度:百分之 71%
天氣:大致多雲

2018年10月25日 星期四

DIY - ESP32:ESP32 SPI Master 主驅動 API 函數(十六)

DIY - ESP32:ESP32 SPI Master 主驅動 API 函數(十六):

在 ESP32 的 ESP-IDF SDK 內包函有 SPI 的應用程式接口(API)函數 (Function),但這應用程式接口(API / Application Programming Interface)函數會使用在程式上,筆者為了方便,將 SPI 的函數都放在 Blog 上,隨時可以查閱。

ESP32 SPI Mater 主驅動 API函數
使用 spi_master 驅動程序:
  • 通過調用 spi_bus_initialize 初始化 SPI 總線。 確保在 bus_config 結構中設置正確的 IO 引腳。 注意將不需要的信號設置為 -1。
  • 通過調用 spi_bus_add_device 告訴驅動程序有關連接到總線的 SPI 從設備。 確保在 dev_config 結構中配置設備具有的任何時序要求。 您現在應該擁有該設備的句柄,以便在發送事務時使用。
  • 要與設備交互,請使用您需要的任何事務參數填充一個或多個 spi_transaction_t 結構。 然後以輪詢方式或中斷方式發送它們。

功能 – spi_bus_initialize ()
原型:esp_err_t spi_bus_initialize(spi_host_device_t host, const spi_bus_config_t *bus_config, int dma_chan)
參數:host: SPI peripheral that controls this bus bus_config: Pointer to a spi_bus_config_t struct specifying how the host should be initialized dma_chan: Either channel 1 or 2, or 0 in the case when no DMA is required. Selecting a DMA channel for a SPI bus allows transfers on the bus to have sizes only limited by the amount of internal memory. Selecting no DMA channel (by passing the value 0) limits the amount of bytes transfered to a maximum of 32.
返回:ESP_ERR_INVALID_ARG if configuration is invalid
            ESP_ERR_INVALID_STATE if host already is in use
            ESP_ERR_NO_MEM if out of memory
            ESP_OK on success
說明:Initialize a SPI bus. For now, only supports HSPI and VSPI.
範例:

功能 – spi_bus_free()
原型:esp_err_t spi_bus_free(spi_host_device_t host)
參數:host: SPI peripheral to free
返回:ESP_ERR_INVALID_ARG if parameter is invalid 
            ESP_ERR_INVALID_STATE if not all devices on the bus are freed 
            ESP_OK on success
說明:Free a SPI bus,In order for this to succeed,all devices have to be removed first
範例:

功能 – spi_bus_add_device()
原型:esp_err_t spi_bus_add_device(spi_host_device_t host, const spi_device_interface_config_t *dev_config, spi_device_handle_t *handle)
參數:host:SPI peripheral to allocate device on
            dev_config:SPI interface protocol config for the device 
            handle:Pointer to variable to hold the device handle
返回:ESP_ERR_INVALID_ARG if parameter is invalid
            ESP_ERR_NOT_FOUND if host doesn’t have any free CS slots 
            ESP_ERR_NO_MEM if out of memory 
            ESP_OK on success 
說明:Allocate a device on a SPI bus。This initializes the internal structures for a device, plus allocates a CS pin on the indicated SPI master peripheral and routes it to the indicated GPIO. All SPI master devices have three CS pins and can thus control up to three devices. While in general, speeds up to 80MHz on the dedicated SPI pins and 40MHz on GPIO-matrix-routed pins are supported, full-duplex transfers routed over the GPIO matrix only support speeds up to 26MHz.
範例:

功能 – spi_bus_remove_device()
原型:esp_err_t spi_bus_remove_device(spi_device_handle_t handle)
參數:handle:Device handle to free
返回:ESP_ERR_INVALID_ARG if parameter is invalid 
            ESP_ERR_INVALID_STATE if device already is freed 
            ESP_OK on success
說明:Remove a device from the SPI bus.
範例:

功能 – spi_device_queue_trans()
原型:esp_err_t spi_device_queue_trans(spi_device_handle_t handle, spi_transaction_t *trans_desc, TickType_t ticks_to_wait)
參數:handle:Device handle obtained using spi_host_add_dev
            trans_desc:Description of transaction to execute 
            ticks_to_wait:Ticks to wait until there’s room in the queue; use portMAX_DELAY to never time out.
返回:ESP_ERR_INVALID_ARG if parameter is invalid 
            ESP_ERR_TIMEOUT if there was no room in the queue before ticks_to_wait expired 
            ESP_ERR_NO_MEM if allocating DMA-capable temporary buffer failed
            ESP_ERR_INVALID_STATE if previous transactions are not finished 
            ESP_OK on success
說明:Queue a SPI transaction for interrupt transaction execution. Get the result by spi_device_get_trans_result. Normally a device cannot start (queue) polling and interrupt transactions simultaneously.
範例:

功能 – spi_device_get_trans_result()
原型:esp_err_t spi_device_get_trans_result(spi_device_handle_t handle, spi_transaction_t **trans_desc, TickType_t ticks_to_wait)
參數:handle:Device handle obtained using spi_host_add_dev 
            trans_desc:Pointer to variable able to contain a pointer to the description of the transaction that is executed. The descriptor should not be modified until the descriptor is returned by spi_device_get_trans_result. 
            ticks_to_wait:Ticks to wait until there’s a returned item; use portMAX_DELAY to never time out.
返回:ESP_ERR_INVALID_ARG if parameter is invalid 
            ESP_ERR_TIMEOUT if there was no completed transaction before ticks_to_wait expired 
            ESP_OK on success
說明:Get the result of a SPI transaction queued earlier by spi_device_queue_trans. This routine will wait until a transaction to the given device succesfully completed. It will then return the description of the completed transaction so software can inspect the result and e.g. free the memory or re-use the buffers.
範例:

功能 – spi_device_transmit()
原型:esp_err_t spi_device_transmit(spi_device_handle_t handle, spi_transaction_t *trans_desc)
參數:handle:Device handle obtained using spi_host_add_dev 
            trans_desc:Description of transaction to execute
返回:ESP_ERR_INVALID_ARG if parameter is invalid 
            ESP_OK on success
說明:Send a SPI transaction, wait for it to complete, and return the result. This function is the equivalent of calling spi_device_queue_trans() followed by spi_device_get_trans_result(). Do not use this when there is still a transaction separately queued (started) from spi_device_queue_trans() or polling_start/transmit that hasn’t been finalized.. This function is not thread safe when multiple tasks access the same SPI device. Normally a device cannot start (queue) polling and interrupt transactions simutanuously.
範例:

功能 – spi_device_polling_start()
原型:esp_err_t spi_device_polling_start(spi_device_handle_t handle, spi_transaction_t *trans_desc, TickType_t ticks_to_wait)
參數:handle:Device handle obtained using spi_host_add_dev 
            trans_desc:Description of transaction to execute 
            ticks_to_wait:Ticks to wait until there’s room in the queue; currently only portMAX_DELAY is supported.
返回:ESP_ERR_INVALID_ARG if parameter is invalid 
            ESP_ERR_TIMEOUT if the device cannot get control of the bus before ticks_to_wait expired 
            ESP_ERR_NO_MEM if allocating DMA-capable temporary buffer failed 
            ESP_ERR_INVALID_STATE if previous transactions are not finished 
            ESP_OK on success
說明:Immediately start a polling transaction. Normally a device cannot start (queue) polling and interrupt transactions simutanuously. Moreover, a device cannot start a new polling transaction if another polling transaction is not finished.
範例:

功能 – spi_device_polling_end()
原型:esp_err_t spi_device_polling_end(spi_device_handle_t handle, TickType_t ticks_to_wait)
參數:handle:Device handle obtained using spi_host_add_dev 
            ticks_to_wait:Ticks to wait until there’s a returned item; use portMAX_DELAY to never time out.
返回:ESP_ERR_INVALID_ARG if parameter is invalid 
            ESP_ERR_TIMEOUT if the transaction cannot finish before ticks_to_wait expired 
            ESP_OK on success
說明:Poll until the polling transaction ends. This routine will not return until the transaction to the given device has succesfully completed. The task is not blocked, but actively busy-spins for the transaction to be completed.
範例:

功能 – spi_device_polling_transmit()
原型:esp_err_t spi_device_polling_transmit(spi_device_handle_t handle, spi_transaction_t *trans_desc)
參數:handle:Device handle obtained using spi_host_add_dev 
            trans_desc:Description of transaction to execute
返回:ESP_ERR_INVALID_ARG if parameter is invalid
            ESP_OK on success 
說明:Send a polling transaction, wait for it to complete, and return the result. This function is the equivalent of calling spi_device_polling_start() followed by spi_device_polling_end(). Do not use this when there is still a transaction that hasn’t been finalized. This function is not thread safe when multiple tasks access the same SPI device. Normally a device cannot start (queue) polling and interrupt transactions simutanuously.
範例:

功能 – spi_device_acquire_bus()
原型:esp_err_t spi_device_acquire_bus(spi_device_handle_t device, TickType_t wait)
參數:device:The device to occupy the bus. 
            wait:Time to wait before the the bus is occupied by the device. Currently MUST set to portMAX_DELAY.
返回:Occupy the SPI bus for a device to do continuous transactions. Transactions to all other devices will be put off until spi_device_release_bus is called. Note: The function will wait until all the existing transactions have been sent.
說明:ESP_ERR_INVALID_ARG : wait is not set to portMAX_DELAY. 
            ESP_OK : Success.
範例:

功能 – spi_device_release_bus()
原型:void spi_device_release_bus(spi_device_handle_t dev)
參數:dev: The device to release the bus.
返回:無
說明:Release the SPI bus occupied by the device. All other devices can start sending transactions.
範例:

功能 – spi_cal_clock()
原型:int spi_cal_clock(int fapb, int hz, int duty_cycle, uint32_t *reg_o)
參數:fapb:The frequency of apb clock, should be APB_CLK_FREQ. 
            hz:Desired working frequency duty_cycle:Duty cycle of the spi clock 
            reg_o:Output of value to be set in clock register, or NULL if not needed.
返回:Actual working frequency that most fit.
說明:Calculate the working frequency that is most close to desired frequency, and also the register value.
範例:

功能 – spi_get_timing()
原型:void spi_get_timing(bool gpio_is_used, int input_delay_ns, int eff_clk, int *dummy_o, int *cycles_remain_o)
參數:gpio_is_used:True if using GPIO matrix, or False if iomux pins are used. 
            input_delay_ns:Input delay from SCLK launch edge to MISO data valid. 
            eff_clk:Effective clock frequency (in Hz) from spi_cal_clock. 
           dummy_o:Address of dummy bits used output. Set to NULL if not needed.  
           cycles_remain_o:Address of cycles remaining (after dummy bits are used) output. -1 If too many cycles remaining, suggest to compensate half a clock. 0 If no remaining cycles or dummy bits are not used. 
           positive value:cycles suggest to compensate.
返回:無
說明:Calculate the timing settings of specified frequency and settings. If **dummy_o* is not zero, it means dummy bits should be applied in half duplex mode, and full duplex mode may not work.
範例:

功能 – spi_get_freq_limit()
原型:int spi_get_freq_limit(bool gpio_is_used, int input_delay_ns)
參數:gpio_is_used: True if using GPIO matrix, or False if native pins are used. input_delay_ns: Input delay from SCLK launch edge to MISO data valid.
返回:Frequency limit of current configurations.
說明:Get the frequency limit of current configurations. SPI master working at this limit is OK, while above the limit, full duplex mode and DMA will not work, and dummy bits will be applied in the half duplex mode.
範例:

Header File:driver/include/driver/spi_master.h

相關網址:
※ DIY - ESP32:ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏電路(十三)
※ DIY - ESP32:ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏程式(十四)
※ DIY - ESP32:ESP32 SPI 驅動 IO 介紹(十五)
※ DIY - ESP32:ESP32 SPI Master 主驅動 API 函數結構件(十七)

2018年 10月 25日 天氣報告
氣溫:25.6@ 19:20
相對濕度:百分之 68%
天氣:天色大致良好

2018年10月24日 星期三

DIY - ESP32:ESP32 SPI 驅動 IO 介紹(十五)

DIY - ESP32:ESP32 SPI 驅動 IO 介紹(十五):

ESP32 SOC 基本上有內置 4個 SPI(Serial Peripheral Interface)接口,包括 SPI0(Serial Peripheral Interface 0)、SPI1(Serial Peripheral Interface 1)、HSPI( High-speed Serial Peripheral Interface)和 VSPI(Very High-speed Serial Peripheral Interface)接口,SPI0 是已用於 Flash Memory 緩存,SPI1 用於寫入 Flash 晶片,ESP32 將連接的 SPI Flash 設備映射到記憶體, SPI0 和 SPI1 使用相同的硬體線,HSPI 和 VSPI 可以自由使用。

ESP32 SOC 內部功能框圖
ESP32 的 SPI 總線,與連接到一個主機的所有 SPI 設備共用。SPI 總線由 MISO、MOSI、SCLK 和可選的 Quadwp 和 Quadhd 信號組成。SPI 從設備並聯連接到這些信號。
  • MISO: 也稱為 q,這是將串行流輸入到 ESP32 中。
  • MOSI:也稱為 d,這是來自 ESP32 的串行流的輸出。
  • SCLK: 時鐘信號。 每個數據位在該信號的正或負邊沿輸出或輸出。
  • Quadwp :防寫信號,僅用於 4 位元(qio/qout)事務。
  • Quadhd:保持信號,僅用於 4 位元(qio/qout)事務。
  • CS:每個 SPI 從設備都有自己的片選(CS)線,當發生到/從 SPI 從設備的傳輸時,該線被啟動。一個 CS 活動的實例,來自和/或發生的設備的資料傳輸,以及 CS 再次變為非活動狀態。事務是原子的,因為它們永遠不會被另一個事務中斷。

ESP32 SPI 控制器的 IO 接口:
Pin Name
HSPI (GPIO Number)
VSPI (GPIO Number)
MISO
12
19
MOSI
13
23
SCLK
14
18
CS0*
15
5
QUADWP
2
22
QUADHD
4
21

SPI 設備連接
SPI 通訊階段處理:SPI 總線上的通訊處理由五個階段組成,其中任何階段都可以跳過:
  • 命令階段(Command): 在此階段,命令(0-16位)被輸出。
  • 地址階段(Address): 在此階段,地址(0-64位)被輸出。
  • 寫階段:主設備將數據發送到從設備。
  • 虛擬階段: 該階段是可配置的,用於滿足時序要求。
  • 閱讀階段: 從站將數據發送給主站。

SPI 命令和位址階段:
在命令和位址階段,spi_transaction_t 結構中的 cmd 和 addr 欄位將發送到匯流排,而不會同時讀取任何內容, 命令和位址階段的缺省長度在 spi_device_interface_config_t 和 spi_bus_add_device 中設置。 當 spi_transaction_t 中未設置標誌 SPI_TRANS_VARIABLE_CMD 和 SPI_TRANS_VARIABLE_ADDR 時,驅動程式會自動將這些階段的長度設置為分別初始化設備時設置的預設值。

如果命令和位元址階段的長度需要變數,則聲明一個 spi_transaction_ext_t 描述符,在基數成員的標誌中設置標誌 SPI_TRANS_VARIABLE_CMD 或/和 SPI_TRANS_VARIABLE_ADDR,並像往常一樣配置 base 的其餘部分。 然後每個階段的長度將是 spi_transaction_ext_t 中設置的 command_bits 和 address_bits。

命令(Command)和地址(Address)階段是可選的,因為不是每個 SPI 設備都需要發送命令和或位址。這反映在設備配置中,當 command_bits 或 address_bits 欄位設置為零時,不執行命令或位址階段。

SPI 讀寫階段:
並非每個事務都需要寫入數據以及要讀取的數據。 當 rx_buffer 為 NULL(並且未設置 SPI_USE_RXDATA)時,將跳過讀取階段。 當 tx_buffer 為 NULL(並且未設置 SPI_USE_TXDATA)時,將跳過寫入階段。

SPI 寫入單指令和 2-Byte 數據的時序
SPI 讀入 2-Byte 數據的時序
全雙工/半雙工模式:
在全雙工模式(Full Duplex Mode)下,讀寫階段被組合,SPI 主機同時讀寫數據。 總長度由決定 command_bits + address_bits + trans_conf.length,而 trans_conf.rx_length 只確定接收到緩衝區的數據長度。

在半雙工模式(Half Duplex Mode)下,主機(Host)具有獨立的寫和讀階段。 寫入階段和讀取階段的長度分別由 trans_conf.length 和 trans_conf.rx_length 決定。

參考網址:https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_master.html

相關網址:
※ DIY - ESP32:ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏電路(十三)
※ DIY - ESP32:ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏程式(十四)
※ DIY - ESP32:ESP32 SPI Master 主驅動 API 函數(十六)
※ DIY - ESP32:ESP32 SPI Master 主驅動 API 函數結構件(十七)

2018年10月23日 星期二

DIY - ESP32:ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏程式(十四)

DIY - ESP32:ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏程式(十四):

ESP32 ILI9341 SPI (Serial Peripheral Interface Bus)TFT LCD 液晶屏程式是包括 LCD 初始化和 LCD 顯示程式,LCD 初始化程式主要是控制 LCD 的 CS(GPIO15 /G15)、D/C(GPIO16 /G16)和 SCK(GPIO14 / G14)接腳,並且要寫入初始化的資料給予 ILI9341 MOSI(GPIO13 / G13)或 MISO(GPIO12 / G12),這樣便可以令 ILI9341 等待顯示數據資料。

ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏製作
ESP32 連接 ILI9341 SPI TFT LCD 模組:
ILI9341 SPI
Signal
Description
ESP32 Board
Board Signal
I/O Signal
1
Vcc
2.7 ~ 3.3V
1
Vcc
Vcc
2
GND
GND
38
GND
GND
3
CS
Chip Select
23
G15
GPIO15
4
Reset
Reset
1
Vcc
Vcc
5
DC
Data / Command
27
G16
GPIO16
6
MOSI
Master Output Slave Input
(MOSI)
15
G13
GPIO13
7
SCK
Serial Clock Input
(SCLK)
12
G14
GPIO14
8
LED
LED Control
1
Vcc
Vcc
9
MISO
Master Input Slave Output
(MISO)
13
G12
GPIO12

ESP32 ILI9341 SPI TFT LCD 液晶屏 IO 設定:
// ESP32 ILI9341 TFT I/O Definition
#define PIN_NUM_MISO 12
#define PIN_NUM_MOSI 13
#define PIN_NUM_CLK   14
#define PIN_NUM_CS     15

#define PIN_NUM_DC     16


ESP32 ILI9341 SPI TFT LCD 液晶屏初始化程式:
void  ili9341_hspi_init(void)
{
    esp_err_t ret;
    spi_bus_config_t buscfg={
        .miso_io_num=PIN_NUM_MISO,
        .mosi_io_num=PIN_NUM_MOSI,
        .sclk_io_num=PIN_NUM_CLK,
        .quadwp_io_num=-1,
        .quadhd_io_num=-1
    };
    spi_device_interface_config_t devcfg={
        .clock_speed_hz=10*1000*1000, //Clock out at 10 MHz
        .mode=0,                                    // SPI mode 0
        .spics_io_num=PIN_NUM_CS,   // CS pin
        .queue_size=7,                           // 7 transactions at a time
        .pre_cb=lcd_spi_pre_transfer_callback,  // Callback to handle D/C line
    };

    //Initialize the SPI bus
    ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
    assert(ret==ESP_OK);
   
    //Attach the LCD to the SPI bus
    ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
    assert(ret==ESP_OK);

操作系統:Windows 7 64-bit 版本
開發環境:AiThinker05 版本
原程碼: ESP32 ESP-IDF V3.0rc1
程式: DIY-ESP32-053-ILI9341_SPI_ESP8266_HSPI_03_Test-20181020


ESP-12F ILI9341 SPI TFT LCD 液晶屏運作中
ESP-12F ILI9341 SPI TFT LCD 液晶屏顯示
相關網址:
※ DIY - ESP32:ESP32 ILI9341 2.4吋 SPI TFT LCD 液晶屏電路(十三)
※ DIY - ESP32:ESP32 SPI 驅動 IO 介紹(十五)
※ DIY - ESP32:ESP32 SPI Master 主驅動 API 函數(十六)
※ DIY - ESP32:ESP32 SPI Master 主驅動 API 函數結構件(十七)

2018年 10月 23日 天氣報告
氣溫:25.8@ 09:05
相對濕度:百分之 72%
天氣:多雲