Skip to content

Connecting 5V and 3V3

ATtiny3216

Voltage - Supply (Vcc/Vdd) 1.8V ~ 5.5V

ref. digikey

ATtiny3216 can work with both 5V and 3.3V supply.
When VCC is 3.3V, all signals from this board will be 3.3V.

FT230XS

Class USB-serial Schematic Symbol
Pin No. Name Type Description
10 VCC POWER Input 5 V (or 3V3) supply to IC
1 VCCIO POWER Input 1V8 - 3V3 supply for the IO cells
8 3V3OUT POWER Output 3V3 output at 50mA. May be used to power VCCIO.When VCC is 3V3; pin 8

ref. datasheet

In Class USB-serial board,

  • FT230XS’s VCC is connected 5V from USB and VCC of J2 serial. This means the power supplied from this FTDI board to your boards is 5V.
    If you need to supply 3.3V to your board, we need 3.3V regulator externally before connecting VCC of your IC.

  • VIO is connected 3V3. FT230XS is working with 1.8V, but IO voltage is set to 3.3V. This means Tx signal from FT230XS is regulated to 3.3V from 1.8V before send, Rx signal from other 5V IC will regulated to 3.3V internally in FT230XS chip.

This is the Oscilloscope result.

  • Signal 1 (Yellow) is from Tx of FTDI board. This shows Yellow is 3.3V range.
  • Signal 2 (Blue) is from Rx of 3216 board supplied 5V VCC. This shows Blue is 5V range.

ref. group_assignments_page

Connecting TFT module(3.3V), 3216(working with 3.3V) and class FTDI board(5V)

Voltage Devider Registers

In this tips, because Arduino UNO worked with 5V and TFT modules works with 3.3V, 2.2k and 3.3k Ohm registers were used as Voltage Divider registers.

Logic Level Converter

If Logic Level Converter is used instead of registers, Schematic will be simple.

3.3V regulator

On the other hand, if the IC working with 3.3V rather than 5V can be used, no need to think about Voltage difference. To do this, only a 3.3V regulator between 5V from FTDI and VCC to IC is needed to install.

PinNo Printed on board detail SPI my pin
9 SDO/MISO SerialDataOut/MasterInSlaveOut yes 12 /PA2
8 LED BackLightLED - 1 /PA5 or 3.3V_reg_out
7 SCK Clock yes 16 /defined by system
6 SDI/MOSI SerialDstaIn/MasterOutSlaveIn yes 14 /defined by system
5 DC/RS DataCommand - 5 /PB4
4 RESET - 4 /PB5
3 CS ChipSelect yes 0 /PA4
2 GND yes GND
1 VCC 5V/3.3V 5V -> J1 Off(use_regulator) 3.3V -> J1 Bridge(no_regulator) 3.3V_reg_out

Sample program

2.2 inch SPI Module Package

Copy these two dependent_libraly (LCDWIKI_GUI,LCDWIKI_SPI) to ArduinoIDE sketchbook location folder

Open Simple_test.ino

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//This application does not rely on any libraries and it is for ILI9341

//This program is a demo of clearing screen to display black,white,red,green,blue.

//when using the BREAKOUT BOARD only and using these hardware spi lines to the LCD,
//**the SDA pin and SCK pin is defined by the system and can't be modified.
//**if you don't need to control the LED pin,you can set it to 3.3V and set the pin definition to -1.
//**other pins can be defined by youself,for example
//pin usage as follow:
//             CS  DC/RS  RESET  SDI/MOSI  SCK   LED    VCC     GND    
//Arduino Uno  A5   A3     A4       11      13   A0   5V/3.3V   GND

//Remember to set the pins to suit your display module!
/********************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, QD electronic SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
**********************************************************************************/
#include <SPI.h>

#define LED   -1 // -1 to no control or LED pin 1 to control
#define CS    0 //myPin
#define RS    5 //myPin      
#define RESET 4 //myPin

void Lcd_Writ_Bus(unsigned char d)
{
  SPI.transfer(d);
}

void Lcd_Write_Com(unsigned char VH)  
{   
  *(portOutputRegister(digitalPinToPort(RS))) &=  ~digitalPinToBitMask(RS);//LCD_RS=0;
  Lcd_Writ_Bus(VH);
}

void Lcd_Write_Data(unsigned char VH)
{
  *(portOutputRegister(digitalPinToPort(RS)))|=  digitalPinToBitMask(RS);//LCD_RS=1;
  Lcd_Writ_Bus(VH);
}

void Lcd_Write_Com_Data(unsigned char com,unsigned char dat)
{
  Lcd_Write_Com(com);
  Lcd_Write_Data(dat);
}

void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
        Lcd_Write_Com(0x2a);
    Lcd_Write_Data(x1>>8);
    Lcd_Write_Data(x1);
    Lcd_Write_Data(x2>>8);
    Lcd_Write_Data(x2);
        Lcd_Write_Com(0x2b);
    Lcd_Write_Data(y1>>8);
    Lcd_Write_Data(y1);
    Lcd_Write_Data(y2>>8);
    Lcd_Write_Data(y2);
    Lcd_Write_Com(0x2c);                             
}

void SPI_Init(void)
{
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz (half speed)
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE0);  
}

void Lcd_Init(void)
{
  digitalWrite(RESET,HIGH);
  delay(5);
  digitalWrite(RESET,LOW);
  delay(15);
  digitalWrite(RESET,HIGH);
  delay(15);

  digitalWrite(CS,LOW);  //CS

    Lcd_Write_Com(0xCB);  
    Lcd_Write_Data(0x39);
    Lcd_Write_Data(0x2C);
    Lcd_Write_Data(0x00);
    Lcd_Write_Data(0x34);
    Lcd_Write_Data(0x02);

    Lcd_Write_Com(0xCF);  
    Lcd_Write_Data(0x00);
    Lcd_Write_Data(0XC1);
    Lcd_Write_Data(0X30);

    Lcd_Write_Com(0xE8);  
    Lcd_Write_Data(0x85);
    Lcd_Write_Data(0x00);
    Lcd_Write_Data(0x78);

    Lcd_Write_Com(0xEA);  
    Lcd_Write_Data(0x00);
    Lcd_Write_Data(0x00);

    Lcd_Write_Com(0xED);  
    Lcd_Write_Data(0x64);
    Lcd_Write_Data(0x03);
    Lcd_Write_Data(0X12);
    Lcd_Write_Data(0X81);

    Lcd_Write_Com(0xF7);  
    Lcd_Write_Data(0x20);

    Lcd_Write_Com(0xC0);    //Power control
    Lcd_Write_Data(0x23);   //VRH[5:0]

    Lcd_Write_Com(0xC1);    //Power control
    Lcd_Write_Data(0x10);   //SAP[2:0];BT[3:0]

    Lcd_Write_Com(0xC5);    //VCM control
    Lcd_Write_Data(0x3e);   //Contrast
    Lcd_Write_Data(0x28);

    Lcd_Write_Com(0xC7);    //VCM control2
    Lcd_Write_Data(0x86);   //--

    Lcd_Write_Com(0x36);    // Memory Access Control
    Lcd_Write_Data(0x48);   

    Lcd_Write_Com(0x3A);    
    Lcd_Write_Data(0x55);

    Lcd_Write_Com(0xB1);    
    Lcd_Write_Data(0x00);  
    Lcd_Write_Data(0x18);

    Lcd_Write_Com(0xB6);    // Display Function Control
    Lcd_Write_Data(0x08);
    Lcd_Write_Data(0x82);
    Lcd_Write_Data(0x27);  

    Lcd_Write_Com(0x11);    //Exit Sleep
    delay(120);

    Lcd_Write_Com(0x29);    //Display on
    Lcd_Write_Com(0x2c);
    digitalWrite(CS,HIGH);
}

void H_line(unsigned int x, unsigned int y, unsigned int l, unsigned int c)                   
{
  unsigned int i,j;
  digitalWrite(CS,LOW);
  Lcd_Write_Com(0x02c); //write_memory_start
  //digitalWrite(RS,HIGH);
  l=l+x;
  Address_set(x,y,l,y);
  j=l*2;
  for(i=1;i<=j;i++)
  {
    Lcd_Write_Data(c);
  }
  digitalWrite(CS,HIGH);   
}

void V_line(unsigned int x, unsigned int y, unsigned int l, unsigned int c)                   
{
  unsigned int i,j;
  digitalWrite(CS,LOW);
  Lcd_Write_Com(0x02c); //write_memory_start
  //digitalWrite(RS,HIGH);
  l=l+y;
  Address_set(x,y,x,l);
  j=l*2;
  for(i=1;i<=j;i++)
  {
    Lcd_Write_Data(c);
  }
  digitalWrite(CS,HIGH);   
}

void Rect(unsigned int x,unsigned int y,unsigned int w,unsigned int h,unsigned int c)
{
  H_line(x  , y  , w, c);
  H_line(x  , y+h, w, c);
  V_line(x  , y  , h, c);
  V_line(x+w, y  , h, c);
}

void Rectf(unsigned int x,unsigned int y,unsigned int w,unsigned int h,unsigned int c)
{
  unsigned int i;
  for(i=0;i<h;i++)
  {
    H_line(x  , y  , w, c);
    H_line(x  , y+i, w, c);
  }
}

int RGB(int r,int g,int b)
{
  return r << 16 | g << 8 | b;
}

void LCD_Clear(unsigned int j)                   
{
  unsigned int i,m;
  digitalWrite(CS,LOW);
  Address_set(0,0,240,320);
  for(i=0;i<240;i++)
    for(m=0;m<320;m++)
    {
      Lcd_Write_Data(j>>8);
      Lcd_Write_Data(j);
    }
  digitalWrite(CS,HIGH);   
}

void setup()
{
  SPI_Init();
  pinMode(A0,OUTPUT);
  pinMode(A3,OUTPUT);
  pinMode(A4,OUTPUT);
  pinMode(A5,OUTPUT);

  digitalWrite(A0, HIGH);
  digitalWrite(A3, HIGH);
  digitalWrite(A4, HIGH);
  digitalWrite(A5, HIGH);

  Lcd_Init();

}

void loop()
{  
   LCD_Clear(0xf800);
   LCD_Clear(0x07E0);
   LCD_Clear(0x001F);
   LCD_Clear(0x0);
  for(int i=0;i<500;i++)
  {
    Rect(random(300),random(300),random(300),random(300),random(65535)); // rectangle at x, y, with, hight, color
  }

//  LCD_Clear(0xf800);
}

Last update: April 30, 2021