6.1. SPI - TFT LCD Display
6.1.1. Hardware Connection
This demo is based on BL706_AVB, and the connection method is as follows
GPIO function GPIO pin
----------------------------------
LCD_CS <--> GPIO10
LCD_DC <--> GPIO22
SPI_SCK <--> GPIO19
SPI_MISO <--> GPIO20
SPI_MOSI <--> GPIO21
6.1.2. Software Implementation
See
examples/spi/spi_lcd
for the software code
1#define BSP_SPI_CLOCK_SOURCE ROOT_CLOCK_SOURCE_BCLK
2#define BSP_SPI_CLOCK_DIV 0
Configure the
SPI
device clock source, seebsp/board/bl706_avb/clock_config.h
1#define CONFIG_GPIO19_FUNC GPIO_FUN_SPI
2#define CONFIG_GPIO20_FUNC GPIO_FUN_SPI
3#define CONFIG_GPIO21_FUNC GPIO_FUN_SPI
Configure
SPI
device multiplexing pins, seebsp/board/bl706_avb/pinmux_config.h
备注
bsp/board/bl706_avb/pinmux_config.h
is currently used by all demo demos, so you need to select PINMUX_SELECT
as PINMUX_LVGL
, and open one of the demos
备注
In order to adapt to the bl702_avb hardware, the MOSI and MISO of SPI have been swapped by default. If you want to restore the default, modify SPI_SWAP_ENABLE
in drivers/bl702_driver/hal_drv/default_config/spi_config.h
to 0
1#define BSP_USING_SPI0
2
3#if defined(BSP_USING_SPI0)
4#ifndef SPI0_CONFIG
5#define SPI0_CONFIG \
6{ \
7.id = 0, \
8.clk = 36000000,\
9.mode = SPI_MASTER_MODE, \
10.direction = SPI_MSB_BYTE0_DIRECTION_FIRST, \
11.clk_polaraity = SPI_POLARITY_LOW, \
12.clk_phase = SPI_PHASE_1EDGE, \
13.datasize = SPI_DATASIZE_8BIT, \
14.fifo_threshold = 4, \
15}
16#endif
17#endif
Enable
BSP_USING_SPI0
and configureSPI
device, seebsp/board/bl706_avb/peripheral_config.h
1gpio_set_mode(LCD_CS_PIN,GPIO_OUTPUT_MODE);
2gpio_set_mode(LCD_DC_PIN,GPIO_OUTPUT_MODE);
3gpio_write(LCD_CS_PIN,1); //CS1
4gpio_write(LCD_DC_PIN,1); //DC
5
6spi0 = device_find("spi0");
7if(spi0)
8{
9 device_close(spi0);
10}
11else{
12 spi_register(SPI0_INDEX,"spi0",DEVICE_OFLAG_RDWR);
13 spi0 = device_find("spi0");
14}
15if(spi0)
16{
17 device_open(spi0,DEVICE_OFLAG_STREAM_TX|DEVICE_OFLAG_STREAM_RX);
18}
Configure the
LCD_CS
andLCD_DC
pins as output mode and pull upCall
spi_register
function to registerSPI
device, currently registerSPI0
Then use the
find
function to find the handle corresponding to the device and save it in thespi0
handleFinally use
device_open
to open thespi0
device in polling sending mode
1void LCD_WR_Byte(uint8_t data)
2{
3 CS1_LOW;
4 DC_HIGH;
5 spi_transmit(spi0,&data,1,SPI_TRANSFER_TYPE_8BIT);
6 CS1_HIGH;
7}
8
9void LCD_WR_HalfWord(uint16_t data)
10{
11 CS1_LOW;
12 DC_HIGH;
13 spi_transmit(spi0,&data,1,SPI_TRANSFER_TYPE_16BIT);
14 CS1_HIGH;
15}
16
17void LCD_WR_Word(uint32_t data)
18{
19 CS1_LOW;
20 DC_HIGH;
21 spi_transmit(spi0,&data,1,SPI_TRANSFER_TYPE_32BIT);
22 CS1_HIGH;
23}
Provide interface for LCD display driver
6.1.3. Compile and Program
CDK compilation
Open project:spi_lcd.cdkproj
Refer to the steps of Guide to using CDK (like MDK Keil) under Windows to compile and download
Command compilation
1 $ cd <sdk_path>/bl_mcu_sdk
2 $ make BOARD=bl706_avb APP=spi_lcd
Program
6.1.4. Experimental Phenomena
spi display!