cancel
Showing results for 
Search instead for 
Did you mean: 

My driver for ILI9325 on stm32f103 works in Atollic TrueStudio, but doesn't work in Arduino IDE

ALaur.14.28
Associate

I'm trying to connect stm32f103c8t6 board with ILI9325 LCD display. I have created a driver for it in Atollic TrueStudio and run it successfully. Now, I am trying to transfer the driver to the Arduino IDE, because here it will be easier to integrate my code with the other code for this project. However, the driver doesn't work in Arduino IDE. The LCD is just blank.

I have tested the basic GPIO operation in Arduino IDE for stm32f1, it works fine. I have checked the pins on the LCD. They seem to receive command from the board. All the wiring is correct, because the screen works with the code from Atollic without any wiring change.

This is the driver code I use in Arduino IDE. It's basically the same as the one in Atollic. All I changed is the functions of initializing and setting GPIO.

#define LCD_RESET_Pin     9
#define LCD_CS_Pin        8
#define LCD_RS_Pin        7                  
#define LCD_WR_Pin        6              
#define LCD_RD_Pin        5 
 
#define TFT_W    320                    
#define TFT_H    240                    
 
#define WHITE           0xFFFF
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define MAGENTA         0xF81F
#define GREEN           0x07E0
#define CYAN            0x7FFF
#define YELLOW          0xFFE0
#define BROWN           0xBC40
#define BRRED           0xFC07                  // brownish red
#define GRAY            0x8430                  // gray
#define DARKBLUE        0x01CF                  // dark blue
#define LIGHTBLUE       0x7D7C                  // blue
#define GRAYBLUE        0x5458                  // gray-blue
#define LIGHTGREEN      0x841F                  // light green
#define LIGHTGRAY       0xC618                  // light gray
 
void write_cmd_tft(uint16_t command)
{
  gpio_write_bit(GPIOA, LCD_RS_Pin, LOW);           
  gpio_write_bit(GPIOA, LCD_CS_Pin, LOW);
  GPIOB->regs->ODR = command;               
  gpio_write_bit(GPIOA, LCD_WR_Pin, LOW);           
  delayMicroseconds(10);
  gpio_write_bit(GPIOA, LCD_WR_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_CS_Pin, HIGH);
}
 
void write_data16_tft(uint16_t data)
{
  gpio_write_bit(GPIOA, LCD_RS_Pin, HIGH);        
  gpio_write_bit(GPIOA, LCD_CS_Pin, LOW);
  GPIOB->regs->ODR = data;                        
  gpio_write_bit(GPIOA, LCD_WR_Pin, LOW);         
  delayMicroseconds(10);
  gpio_write_bit(GPIOA, LCD_WR_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_CS_Pin, HIGH);
}
 
 
#define cmd_write_ROM()     write_cmd_tft(0x22)       
#define cmd_write_pixel(color)  write_data16_tft(color)     
 
void write_reg_tft(uint16_t registerTFT, uint16_t dataTFT)
{
  write_cmd_tft(registerTFT);               
  write_data16_tft(dataTFT);                
}
 
 
 
void set_frame( uint16_t w1, uint16_t h1,                           
        uint16_t w2, uint16_t h2)                                   
{
  if ((w1 >= TFT_W)||(h1 >= TFT_H)||(w2 >= TFT_W)||(h2 >= TFT_H));  
  write_reg_tft(0x50,h1);                                           
  write_reg_tft(0x51,h2);                                           
  write_reg_tft(0x52,w1);                                           
  write_reg_tft(0x53,w2);                                           
  write_reg_tft(0x20,h1);                                           
  write_reg_tft(0x21,w1);
}
 
 
void draw_pixel(uint16_t w, uint16_t h, uint16_t color)
{
  write_reg_tft(0x20,h);                    
  write_reg_tft(0x21,w);                    
  write_reg_tft(0x22,color);                
}
 
void draw_point(uint16_t w, uint16_t h,           
        uint8_t size,                             
        uint16_t color)                           
{
  uint16_t i = (uint16_t)size*size;
  set_frame(w, h, w+size-1, h+size-1);          
  write_cmd_tft(0x22);                          
  while(i--)  write_data16_tft(color);          
}
 
 
void fill_color (uint16_t color)
{
  uint32_t i = (uint32_t)(TFT_W)*(TFT_H);         
  Serial2.print("Чи�?ло пик�?елей: ");
  Serial2.println(i);
  set_frame(0, 0, TFT_W-1, TFT_H-1);              
  write_cmd_tft(0x22);                            
  while(i--) write_data16_tft(color);             
}
 
void init_tft (void)
{
  gpio_write_bit(GPIOA, LCD_RD_Pin, HIGH);        
  gpio_write_bit(GPIOA, LCD_RESET_Pin, LOW);
  delay(100);
  gpio_write_bit(GPIOA, LCD_RESET_Pin, HIGH);
  delay(100);
 
  write_reg_tft(0x01,0x0000);               
  write_reg_tft(0x02,0x0700);
  write_reg_tft(0x03,0x1038);               
  write_reg_tft(0x04,0x0000);
  write_reg_tft(0x07,0x0000);
  write_reg_tft(0x08,0x0302);
  write_reg_tft(0x09,0x0000);
  write_reg_tft(0x0A,0x0000);
  write_reg_tft(0x0C,0x0000);
  write_reg_tft(0x0D,0x0000);
  write_reg_tft(0x0F,0x0000);
  write_reg_tft(0x10,0x1290);
  write_reg_tft(0x11,0x0007);
  delay(100);
  write_reg_tft(0x12,0x0092);
  delay(100);
  write_reg_tft(0x13,0x0E00);
  delay(100);
  write_reg_tft(0x29,0x0005);
  write_reg_tft(0x2B,0x000E);
 
  write_reg_tft(0x30,0x0004);
  write_reg_tft(0x31,0x0307);
  write_reg_tft(0x32,0x0002);
  write_reg_tft(0x35,0x0206);
  write_reg_tft(0x36,0x0A00);
  write_reg_tft(0x37,0x0507);
  write_reg_tft(0x38,0x0204);
  write_reg_tft(0x39,0x0707);
  write_reg_tft(0x3C,0x0405);
  write_reg_tft(0x3D,0x0000);
 
  write_reg_tft(0x50,0x0000);
  write_reg_tft(0x51,0x00EF);
  write_reg_tft(0x52,0x0000);
  write_reg_tft(0x53,0x013F);
 
  write_reg_tft(0x60,0xA700);               
  write_reg_tft(0x61,0x0001);
  write_reg_tft(0x6A,0x0000);
 
  write_reg_tft(0x80,0x0000);
  write_reg_tft(0x81,0x0000);
  write_reg_tft(0x82,0x0000);
  write_reg_tft(0x83,0x0000);
  write_reg_tft(0x84,0x0000);
  write_reg_tft(0x85,0x0000);
 
  write_reg_tft(0x90,0x0029);
  write_reg_tft(0x92,0x0600);
  write_reg_tft(0x93,0x0003);
  write_reg_tft(0x95,0x0110);
  write_reg_tft(0x97,0x0000);
  write_reg_tft(0x98,0x0000);
  write_reg_tft(0x07,0x0133);
 
  fill_color(BLUE);                   
}
 
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize GPIO pins  
  pinMode(PA9, OUTPUT);                             //LCD_RESET_Pin
  pinMode(PA8, OUTPUT);                             //LCD_CS_Pin
  pinMode(PA7, OUTPUT);                             //LCD_RS_Pin
  pinMode(PA6, OUTPUT);                             //LCD_WR_Pin
  pinMode(PA5, OUTPUT);                             //LCD_RD_Pin
 
  gpio_write_bit(GPIOA, LCD_RESET_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_CS_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_RS_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_WR_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_RD_Pin, HIGH);
 
  pinMode(PB15, OUTPUT);                             
  pinMode(PB14, OUTPUT);                             
  pinMode(PB13, OUTPUT);                             
  pinMode(PB12, OUTPUT);                             
  pinMode(PB11, OUTPUT);      
  pinMode(PB10, OUTPUT);                             
  pinMode(PB9, OUTPUT);                             
  pinMode(PB8, OUTPUT);
  pinMode(PB7, OUTPUT);                             
  pinMode(PB6, OUTPUT);                             
  pinMode(PB5, OUTPUT);                             
  pinMode(PB4, OUTPUT);                             
  pinMode(PB3, OUTPUT);      
  pinMode(PB2, OUTPUT);                             
  pinMode(PB1, OUTPUT);                             
  pinMode(PB0, OUTPUT);                          
 
  init_tft();                                  
}
 
// the loop function runs over and over again forever
void loop() {
}

What it's supposed to do is to initialize the LCD and to fill it in blue. Instead, it's just a blank screen.

0 REPLIES 0