在 ESP8266 的 SPI / HSPI 的 I/O 腳是定義了,可參考 include 內的 eagle_soc.h ,一般 SPI 是定義為 0,而 HSPI 是定義為 1。時鐘頻率是 80MHz ,但可以根據 SPI_CLKDIV_PRE 和SPI_CLKCNT_N 的數字來改變頻率,公式 80MHz / (SPI_CLKDIV_PRE + 1) / (SPI_CLKCNT_N + 1) 。而 ESP8266 內部的 SPI 和 HSPI 的記存器都沒有很詳細資料!
ESP8266 和 ESP-12E 開發板 SPI 腳定義:
ESP8266
|
GPIO
|
Pin
Name
|
Function
Name
|
Define
I/O Name
|
15
|
IO0
|
GPIO0
|
SPICS2
|
PERIPHS_IO_MUX_GPIO0_U
|
26
|
IO1
|
U0TXD
|
SPICS1
|
PERIPHS_IO_MUX_U0TXD_U
|
21
|
IO6
|
SDIO_CLK
|
SPICLK
|
PERIPHS_IO_MUX_SD_CLK_U
|
22
|
IO7
|
SDIO_DATA0
|
SPIQ/MISO
|
PERIPHS_IO_MUX_SD_DATA0_U
|
23
|
IO8
|
SDIO_DATA1
|
SPID / MOSI
|
PERIPHS_IO_MUX_SD_DATA1_U
|
18
|
IO9
|
SDIO_DATA2
|
SPIHD
|
PERIPHS_IO_MUX_SD_DATA2_U
|
19
|
IO10
|
SDIO_DATA3
|
SPIWP
|
PERIPHS_IO_MUX_SD_DATA3_U
|
20
|
IO11
|
SDIO_CMD
|
SPICS0
|
PERIPHS_IO_MUX_SD_CMD_U
|
10
|
IO12
|
MTDI
|
HSPIQ / MISO
|
PERIPHS_IO_MUX_MTDI_U
|
12
|
IO13
|
MTCK
|
HSPID / MOSI
|
PERIPHS_IO_MUX_MTCK_U
|
9
|
IO14
|
MTMS
|
HSPICLK
|
PERIPHS_IO_MUX_MTMS_U
|
13
|
IO15
|
MTDO
|
HSPICS
|
PERIPHS_IO_MUX_MTDO_U
|
ESP8266 SPI 記存器定義:
ESP8266
|
Pin
Name
|
Description
|
0x00
|
SPI_CMD
|
|
0x04
|
SPI_ADDR
|
|
0x08
|
SPI_CTRL
|
|
0x10
|
SPI_RD_STATUS
|
|
0x14
|
SPI_CTRL2
|
|
0x18
|
SPI_CLOCK
|
|
0x1C
|
SPI_USER
|
|
0x20
|
SPI_USER1
|
|
0x24
|
SPI_USER2
|
|
0x28
|
SPI_WR_STATUS
|
|
0x2C
|
SPI_PIN
|
|
0x30
|
SPI_SLAVE
|
|
0x34
|
SPI_SLAVE1
|
ESP8266 SPI / HSPI 初始化程式定義:
if(spi_no==SPI){
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x005); //clear
bit9,and bit8
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CLK_U, 1); //configure
io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CMD_U,
1);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA0_U,
1); //configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA1_U,
1); //configure io to spi mode
}else if(spi_no==HSPI){
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105); //clear bit9
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,
2); //configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2); //configure
io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U,
2);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U,
2);//configure io to spi mode
}
|
ESP8266 SPI 頻率時鐘程式定義:
// SPI clock=CPU clock/8
WRITE_PERI_REG(SPI_CLOCK(spi_no),
((1&SPI_CLKDIV_PRE) <<SPI_CLKDIV_PRE_S)|
((3&SPI_CLKCNT_N) <<SPI_CLKCNT_N_S)|
((1&SPI_CLKCNT_H) <<SPI_CLKCNT_H_S)|
((3&SPI_CLKCNT_L) <<SPI_CLKCNT_L_S)); //clear bit 31,set SPI clock div
|
2017年 4月 12日 天氣報告
氣溫:19.5度 @ 20:10
相對濕度:百分之 90%
天氣:微雨
沒有留言:
張貼留言