Nucleo F303K8x and Nokia 5110 LCD - can't show anything :/
Hi Everyone !
I want to ask for your help, maybe someone have had the same problem as mine and know how to solve it. I;ve got an STM32 F303K8T6 Nucleo board and it was a time to programm a SPI transmission. I wanted to show something on Nokia 5110 LCD. I wrote the code and saw that there are some black pixels but it’s not the picture that I want to show on the screen. My code is below. I don’t know what I’m doing wrong. I’ve been trying to solve that for a week.
HEEEEEEEELP PLEASE !!!!!!!!!!!!!!!
- include “stm32f30x.h”
- include “delay.h”
- include
- include
- define LCD_DC GPIO_Pin_0
- define LCD_CE GPIO_Pin_7
- define LCD_RST GPIO_Pin_6
- define LCD_BL GPIO_Pin_12
const unsigned char logo_mini_mono [] = {
0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x7F, 0x7F, 0x7F, 0xFF, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFE, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF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FF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F,
};
uint8_t spi_sendrecv(uint8_t byte){
SPI_I2S_ReceiveData16(SPI1);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData16(SPI1, byte);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
return SPI_I2S_ReceiveData16(SPI1);
}
void lcd_reset(){
GPIO_ResetBits(GPIOB, LCD_RST);
delay_ms(10);
GPIO_SetBits(GPIOB, LCD_RST);
}
void lcd_cmd(uint8_t cmd){
GPIO_ResetBits(GPIOB, LCD_CE|LCD_DC);
spi_sendrecv(cmd);
GPIO_SetBits(GPIOB, LCD_CE);
}
void lcd_data(const uint8_t* data, int size){
int i;
GPIO_SetBits(GPIOB, LCD_DC);
GPIO_ResetBits(GPIOB, LCD_CE);
for (i = 0; i < size; i++) {spi_sendrecv(datai);}
GPIO_SetBits(GPIOB, LCD_CE);
}
int main(void){
GPIO_InitTypeDef gpio;
SPI_InitTypeDef spi;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
GPIO_StructInit(&gpio);
SPI_StructInit(&spi);
//BL
gpio.GPIO_Pin = GPIO_Pin_12;
gpio.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(GPIOA, &gpio);
//MOSI, SCK
gpio.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_3;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &gpio);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_5);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_5);
//MISO
gpio.GPIO_Pin = GPIO_Pin_4;
gpio.GPIO_Mode = GPIO_Mode_IN;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
gpio.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &gpio);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_5);
gpio.GPIO_Pin = LCD_DC|LCD_RST|LCD_CE;
gpio.GPIO_Mode = GPIO_Mode_OUT;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &gpio);
GPIO_SetBits(GPIOB, LCD_CE|LCD_RST);
spi.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
spi.SPI_Mode = SPI_Mode_Master;
spi.SPI_DataSize = SPI_DataSize_8b;
spi.SPI_CPOL = SPI_CPOL_High;
spi.SPI_CPHA = SPI_CPHA_2Edge;
spi.SPI_NSS = SPI_NSS_Soft;
spi.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
spi.SPI_FirstBit = SPI_FirstBit_MSB;
spi.SPI_CRCPolynomial = 7;
SPI_Init(SPI1,&spi);
SPI_Cmd(SPI1,ENABLE);
SysTick_Config(SystemCoreClock / 1000);
GPIO_SetBits(GPIOA, LCD_BL);
lcd_reset();
lcd_cmd(0x21);
lcd_cmd(0xc8);
lcd_cmd(0x06);
lcd_cmd(0x13);
lcd_cmd(0x20);
lcd_cmd(0x0c);
lcd_cmd(0x80 | 0x35);
lcd_data(logo_mini_mono, sizeof(logo_mini_mono));
while(1){
}
}