2282 views|2 replies

565

Posts

0

Resources
The OP
 

[AT-START-F425 Review] + Software and Hardware SPI Driver (ST7735) 1.8-inch TFT LCD [Copy link]

 

1. Hardware connection
GND GND
3.3V VCC
PA5 SCL
PA7 SDA
PB0 ERS (reset)
PB1 DC (command data selection)
PA4 CS (chip select)
PB2 BL (backlight)


2. Font library access method
: negative code, reverse, column-row mode,
use PCtoLCD2002 software to access.

3. Image acquisition:
horizontal scanning, 16-bit true color
using Image2Lcd acquisition

4. Code implementation
(1) The IO and SPI initialization
codes are compatible with both software SPI and hardware SPI, which are selected by the macro SOFTWARE_SPI_ENABLE .

void LcdIoInit(void)
{

        gpio_init_type gpio_init_struct;

        /* enable the led clock */
        crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
        crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);


        /* set default parameter */
        gpio_default_para_init(&gpio_init_struct);



#if SOFTWARE_SPI_ENABLE        

        /* configure the led gpio */

        gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
        gpio_init_struct.gpio_out_type  = GPIO_OUTPUT_PUSH_PULL;
        gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
        gpio_init_struct.gpio_pins = GPIO_PINS_4|GPIO_PINS_5|GPIO_PINS_7;
        gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
        gpio_init(GPIOA, &gpio_init_struct);

        gpio_bits_set(GPIOA,GPIO_PINS_4|GPIO_PINS_5|GPIO_PINS_7);
#else        

        /*SPI1 :  

                PA4/CS  

                PA5/SCK    

                PA6/MISO   

                PA7/MOSI    

        */

       
        gpio_init_struct.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;
        gpio_init_struct.gpio_pull           = GPIO_PULL_UP;
        gpio_init_struct.gpio_mode           = GPIO_MODE_OUTPUT;
        gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
        gpio_init_struct.gpio_pins = GPIO_PINS_4;
        gpio_init(GPIOA, &gpio_init_struct);
        
        gpio_bits_set(GPIOA,GPIO_PINS_4);

        gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE5, GPIO_MUX_0);
        gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE6, GPIO_MUX_0);
        gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE7, GPIO_MUX_0);

        gpio_default_para_init(&gpio_init_struct);
        gpio_init_struct.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;
        gpio_init_struct.gpio_pull           = GPIO_PULL_DOWN;
        gpio_init_struct.gpio_mode           = GPIO_MODE_MUX;
        gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
        gpio_init_struct.gpio_pins = GPIO_PINS_5;
        gpio_init(GPIOA, &gpio_init_struct);


        gpio_init_struct.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;
        gpio_init_struct.gpio_pull           = GPIO_PULL_UP;
        gpio_init_struct.gpio_mode           = GPIO_MODE_MUX;
        gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
        gpio_init_struct.gpio_pins = GPIO_PINS_6;
        gpio_init(GPIOA, &gpio_init_struct);


        gpio_init_struct.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;
        gpio_init_struct.gpio_pull           = GPIO_PULL_UP;
        gpio_init_struct.gpio_mode           = GPIO_MODE_MUX;

        gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;

        gpio_init_struct.gpio_pins = GPIO_PINS_7;

        gpio_init(GPIOA, &gpio_init_struct);

        

        

        spi_init_type spi_init_struct;



        crm_periph_clock_enable(CRM_SPI1_PERIPH_CLOCK, TRUE);

  

        spi_default_para_init(&spi_init_struct);

        spi_init_struct.transmission_mode = SPI_TRANSMIT_HALF_DUPLEX_TX;

        spi_init_struct.master_slave_mode = SPI_MODE_MASTER;

        spi_init_struct.mclk_freq_division = SPI_MCLK_DIV_2;

        spi_init_struct.first_bit_transmission = SPI_FIRST_BIT_MSB;

        spi_init_struct.frame_bit_num = SPI_FRAME_8BIT;

        spi_init_struct.clock_polarity = SPI_CLOCK_POLARITY_HIGH;  //SPI_CLOCK_POLARITY_HIGH

        spi_init_struct.clock_phase = SPI_CLOCK_PHASE_2EDGE;       //SPI_CLOCK_PHASE_2EDGE

        spi_init_struct.cs_mode_selection = SPI_CS_SOFTWARE_MODE;

        spi_init(SPI1, &spi_init_struct);



        spi_enable(SPI1, TRUE);

        

#endif        

        

        gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;

        gpio_init_struct.gpio_out_type  = GPIO_OUTPUT_PUSH_PULL;

        gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;

        gpio_init_struct.gpio_pins = GPIO_PINS_0|GPIO_PINS_1|GPIO_PINS_2;

        gpio_init_struct.gpio_pull = GPIO_PULL_NONE;

        gpio_init(GPIOB, &gpio_init_struct);

        

        gpio_bits_set(GPIOB,GPIO_PINS_0|GPIO_PINS_1|GPIO_PINS_2);

}

(2) SPI write data

void LCD_Writ_Bus(u8 dat) 
{        
        LCD_CS_LOW();

#if SOFTWARE_SPI_ENABLE        

        
        u8 i;
        for(i=0;i<8;i++)
        {                          
                LCD_SCLK_LOW();
                if(dat&0x80)
                {
                   LCD_MOSI_HIGH();
                }
                else
                {
                   LCD_MOSI_LOW();
                }
                LCD_SCLK_HIGH();
                dat<<=1;
        }
#else

    spi_i2s_data_transmit(SPI1, dat);

    while(spi_i2s_flag_get(SPI1, SPI_I2S_TDBE_FLAG) == RESET) {};
#endif        
        LCD_CS_HIGH();        
}

(3) Test code

void LcdTest(void)
{

        LcdInit();//LCD初始化
        LcdFill(0,0,LCD_W,LCD_H,BLACK);

        LcdShow16x16Hz(40, 0, 4, YELLOW, BLACK);
        LcdShow16x16Hz(56, 0, 5, YELLOW, BLACK);
        LcdShow16x16Hz(72, 0, 6, YELLOW, BLACK);

        LcdShowString(32,24,"AT32F425",BLUE, BLACK,16);
        LcdShowImage (14,60, 100, 93, gImage_zan);
}

5. Phenomenon

This post is from Domestic Chip Exchange

Latest reply

This color screen is nice. There should be a corresponding library for screen display, right?   Details Published on 2022-5-23 18:52
Personal signaturestm32/LoRa物联网:304350312
 
 

6742

Posts

2

Resources
2
 

This color screen is nice. There should be a corresponding library for screen display, right?

This post is from Domestic Chip Exchange

Comments

The spi part is related to the specific mcu, and other initialization processes can be referred to the manufacturer.  Details Published on 2022-5-23 19:01
 
 
 

565

Posts

0

Resources
3
 
wangerxian posted on 2022-5-23 18:52 This color screen is good. There should be a corresponding library for screen display, right?

The spi part is related to the specific mcu, and other initialization processes can be referred to the manufacturer.

This post is from Domestic Chip Exchange
Personal signaturestm32/LoRa物联网:304350312
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list