cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with connect stm32f0discovery and LCDTS1620A-21

pdmtech
Associate
Posted on February 26, 2015 at 17:53

hi

i want show a text in LCD and i use LCDTS1620A-21 and stm32f0discovery 0690X00000605EwQAI.png 0690X00000602hlQAA.jpgand this is my code

#include ''stm32f0xx.h'' 
uint32_t TickValue=0; 
#define RS GPIO_BRR_BR_13 // RS is named as Port 13 
#define RW GPIO_BRR_BR_14 // RW is named as Port 14 
#define EN GPIO_BRR_BR_15 // EN is named as Port 15 
void
initgpio() 
{ 
RCC->AHBENR |= RCC_AHBENR_GPIOCEN; 
RCC->AHBENR |= RCC_AHBENR_GPIOAEN; 
GPIOC->MODER |= (GPIO_MODER_MODER13_0 | GPIO_MODER_MODER14_0 | GPIO_MODER_MODER15_0) ; 
GPIOC->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR13 | GPIO_OSPEEDER_OSPEEDR14 | GPIO_OSPEEDER_OSPEEDR15); 
GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_13 | GPIO_OTYPER_OT_14 | GPIO_OTYPER_OT_15) ; 
// GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPDR13 | GPIO_PUPDR_PUPDR14 | GPIO_PUPDR_PUPDR15); 
GPIOA->MODER |= (GPIO_MODER_MODER0_0 | GPIO_MODER_MODER1_0 | GPIO_MODER_MODER2_0 | 
GPIO_MODER_MODER3_0 | GPIO_MODER_MODER4_0 | GPIO_MODER_MODER5_0 | GPIO_MODER_MODER6_0 | GPIO_MODER_MODER7_0) ; 
GPIOA->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR0 | GPIO_OSPEEDER_OSPEEDR1 | GPIO_OSPEEDER_OSPEEDR2 | 
GPIO_OSPEEDER_OSPEEDR3 | GPIO_OSPEEDER_OSPEEDR4 | GPIO_OSPEEDER_OSPEEDR5 | GPIO_OSPEEDER_OSPEEDR6 | GPIO_OSPEEDER_OSPEEDR7); 
GPIOA->OTYPER &= ~(GPIO_OTYPER_OT_0 | GPIO_OTYPER_OT_1 | GPIO_OTYPER_OT_2 | GPIO_OTYPER_OT_3 | 
GPIO_OTYPER_OT_4 | GPIO_OTYPER_OT_5 | GPIO_OTYPER_OT_6 | GPIO_OTYPER_OT_7) ; 
// GPIOA->PUPDR &= ~(GPIO_PUPDR_PUPDR0 | GPIO_PUPDR_PUPDR1 | GPIO_PUPDR_PUPDR2 | 
// GPIO_PUPDR_PUPDR3 | GPIO_PUPDR_PUPDR4 | GPIO_PUPDR_PUPDR5 | GPIO_PUPDR_PUPDR6 | GPIO_PUPDR_PUPDR7); 
} 
void
s_init() 
{ 
GPIOC->BRR=RS; 
GPIOC->BRR=RW; 
} 
void
s_data() 
{ 
GPIOC->BSRR=RS; 
GPIOC->BRR=RW; 
} 
void
delay_ms(uint32_t n_ms) 
{ 
SysTick_Config(8000*3 - 30); 
TickValue = n_ms; 
while
(TickValue == n_ms) 
; 
SysTick_Config(8000*3); 
while
(TickValue != 0) 
; 
} 
void
s_latch() 
{ 
GPIOC->BSRR=EN; 
delay_ms(10); 
GPIOC->BRR=EN; 
delay_ms(10); 
} 
void
TimingDelay_Decrement(
void
) 
{ 
TickValue--; 
} 
int
main(
void
) 
{ 
int
k=0; 
char
a[]=
''WWW.EEHERALD.COM''
; 
char
b[]=
''EMBEDDED SYSTEMS''
; 
initgpio(); 
GPIOC->BRR=RS; 
//Initialize RS=0 for selecting instruction Send 
GPIOC->BRR=RW; 
// Select RW=0 to write Instruction/data on LCD 
GPIOC->BSRR=EN; 
// EN=1 for unlatch. (used at initial condition) 
delay_ms(10); 
s_init(); 
//Call Instruction Select routine 
GPIOA->ODR=0x0001; 
// Clear Display, Cursor to Home 
s_latch(); 
//Latch the above instruction 
GPIOA->ODR=0x0038; 
// Display Function (2 rows for 8-bit data; small) 
s_latch(); 
//Latch this above instruction 4 times 
s_latch(); 
s_latch(); 
s_latch(); 
GPIOA->ODR=0x000E; 
// Display and Cursor on, Cursor Blink off 
s_latch(); 
//Latch the above instruction 
GPIOA->ODR=0x0010; 
// Cursor shift left 
s_latch(); 
//Latch the above instruction 
GPIOA->ODR=0x0006; 
// Cursor Increment, Shift off 
s_data(); 
//Change the input type to Data.(before it was instruction input) 
s_latch(); 
//Latch the above instruction 
for
(k=0;a[k];k++) 
{ 
GPIOA->ODR=a[k]; 
//It will send a[0]='P' as = '0x0050' on Port A. 
s_latch(); 
//Latch the above instruction only once. Or it will clone each character twice if you latch twice. 
} 
GPIOC->BRR=RS; 
//Initialize RS=0 for selecting instruction Send 
GPIOC->BRR=RW; 
// Select RW=0 to write Instruction/data on LCD 
GPIOC->BSRR=EN; 
// EN=1 for unlatch. (used at initial condition) 
delay_ms(10); 
GPIOA->ODR=0x00C0; 
// Move cursor to beginning of second row 
s_latch(); 
//Latch the above instruction 
s_data(); 
//Change the input type to Data.(before it was instruction input) 
for
(k=0;b[k];k++) 
{ 
GPIOA->ODR=b[k]; 
//It will send b[0]='E' as = '0x0044' on Port A. 
s_latch();
//Latch the above instruction only once. Or it will clone each character twice if you latch twice. 
} 
s_init(); 
} 

but dont work :(((((((((( plz help me i am a beginerrrrrrrrr #stm32f0discovery #lcdts1620a-21
4 REPLIES 4
AvaTar
Lead
Posted on February 26, 2015 at 20:05

Didn't really looking at the code.

But driving a 5.0V peripheral (LCD) from a 3.3V MCU, this can't work.

pdmtech
Associate
Posted on February 26, 2015 at 21:59

thanks

what do you means?

If possible

please explain

a little more

Posted on February 26, 2015 at 22:19

The inference is that the VOL/VOH levels are incompatible. I've not looked at the data sheet for this specific display, so honestly couldn't say one way or the other. I'm using a similar one, but it's 3.3V rated. 

http://www.newhavendisplay.com/specs/NHD-0216HZ-FSW-FBW-3V3C.pdf

Other peoples register level code really isn't something I'm going to spend my time on. Would suggest you look at other implementations using the Standard Peripheral Library.

Connectivity otherwise doesn't look bad, but you'd want to walk through the code, make sure the delays on the pins/signals are what you expect, and debug to understand if it's getting stuck somewhere, just not responding as expected.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jj2
Associate II
Posted on February 27, 2015 at 00:14

''But driving a 5.0V peripheral (LCD) from a 3.3V MCU, this can't work.''

 

Except my friend - for those times - when it (surely) does!

Might (some) attention be paid to LCD's data manual?   I extract key portion, here:

0690X000006030cQAA.jpg

Shown here - and our long (past 10+ year's use/success) of strictly 5V based character Lcds - w/3V3 MCUs (almost exclusively) proves this, VERY MUCH CAN WORK!

Retreat to the fine manual - or data sheet - always trumps ''guessing.''

Poster would do well to obtain HD44780 manual - read/absorb initialization code & timing - and try again.