利用STM32F030 的SPI驱动TFT LCD,我使用的LCD为240*320像素的2.4寸彩屏,驱动IC为ili9341,只需四根线即可点亮LCD,先贴上SPI配置吧,声明一下,F030的SPI配置和F103等的配置有些不一样
/*LCD SPI Init*/
void SPI_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
/* Enable the SPI periph */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);//
/* Enable SCK, MOSI GPIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
// GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_0);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_0);//SCK PIN
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_0);//SDAPIN
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;//GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
/* SPI SCK, MOSIpin configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* SPI configuration -------------------------------------------------------*/
// SPI_I2S_DeInit(SPI2);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//SPI_Direction_1Line_Tx;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;//SPI_CPOL_Low;SPI_CPOL_High
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;//SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//SPI_NSS_Soft; SPI_NSS_Hard
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_Init(SPI2, &SPI_InitStructure);
/* Initialize the FIFO threshold */
SPI_RxFIFOThresholdConfig(SPI2, SPI_RxFIFOThreshold_QF);
/* Enable the Rx buffer not empty interrupt */
// SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE);
// /* Enable the SPI Error interrupt */
// SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_ERR, ENABLE);
/* Enable the SPI peripheral */
SPI_Cmd(SPI2, ENABLE);
/* Configure the SPI interrupt priority */
// NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
// NVIC_Init(&NVIC_InitStructure);
}