You might have scratched your head and said, “OMG!! Its difficult to interface MSP430 and LCD!” If you have been working on it then you surely would have! Also here in today’s blog I would like to add another solution too. I keep hearing that msp430 cannot be used as atmega. Whenever asked the reason what people say is that the logic level doesnt match. One is in cmos and other is in ttl. Well, one should agree the point that we hobby project makers are always a long way behind the companies. That is the main reason in which we dont employ mcu as msp430 which is small and but highly powerful. In my previous post I had shared my experience with TI ADC Phase 1. I had used msp430f149 for my project and I had faced similar problems “logic mismatch”. So today what I am writing will be concentrated on how to solve this problem. My team has found a good solution to solve this issue.
Before coming to solution its always required to know what exactly the problem is. Let me give an example and explain the problem.
The most important problem everyone has is LCD 16×2 interfacing with MSP430. The LCD 16×2 which is usually available in market works on TTL logic. Now what is TTL logic is?
As wiki says, “Transistor–transistor logic (TTL) is a class of digital circuits built from bipolar junction transistors (BJT) and resistors. It is called transistor–transistor logic because both the logic gating function (e.g., AND) and the amplifying function are performed by transistors (contrast with RTL and DTL). Standard TTL circuits operate with a 5-volt power supply. A TTL input signal is defined as “low” when between 0V and 0.8V with respect to the ground terminal, and “high” when between 2.2V and 5V(precise logic levels vary slightly between sub-types and by temperature). TTL outputs are typically restricted to narrower limits of between 0V and 0.4V for a “low” and between 2.6V and 5V for a “high”, providing 0.4V of noise immunity”
It should be noted that, though TTL has logic low as <0.8V and high as >2.6V many a times the actual value will be low as <1.5V and high as >3.5V.
Now coming to CMOS logic, What is it mean? These logic devices works with 3.3Vpower supply. Here usually low means <0.8V and high means >2.3V.
Observing TTL and CMOS, if ideal cases are considered then there is no trouble in conversion between the two logic levels. 3.3V will be considered as high in TTL. But problem is that ideal case doesnt exit!
So it is much required to do the conversion to get rid of this problem. Hence from many months a lot of work in this part has gone and few possible solution where done. Few among them are mentioned below.
Using pull up resistor : Well some people claim this is one of the best and easy solution for this problem. However when comes to LCD interfacing this just doesnt work!
Transistor conversion : Using a BJT or MOSFET people say it is possible to convert. Theoretically one can prove this. There are people who have done circuits based on this and solved the LCD problem. However its is that fast and it usually become clumsy.
Use another controller : This is one also possible but you need to integrate two controllers. One working in 5V logic and other in 3.3V. Example is MSP430 and ATMEGA. Connect LCD to atmega. This has one main problem that you require another controller! So what is the point of using MSP then? For testing purpose one can use it but when comes to hardware this just complicates the overall thing!
Therefore, it was much required to see whether there is any IC which can solve this problem. However, if you search in google you do get a lot of ICs which solves this problem, but there are only few which actually solves! Others have problem of gate delays and frequency matching. Hence a proper IC has to be selected. The IC which I and my teammates found providing the best solution was CD 4050. TI provides this IC too! Use this IC to match the logic levels.
Now let me concentrate mainly on LCD solution and explain in more detail. For any other logic mismatch you just have to change the LCD with your required device 🙂 Thats all!
The main reasons for not working of LCD interface in MSP430 is –
1)LCD (16 x 2) display works with 5V logic level (TTL), where as TI MCU works with 3V logic levels (CMOS). There is voltage level mismatch between the two components.
2) Not understanding data-sheet of LCD 16×2. Contrast pin is not connected properly. LCD which I used datasheet can be seen at http://www.datasheetarchive.com/JHD162A-datasheet.html
(These were the problems which we faced)
Here are the steps for interfacing TIMCU and LCD (16×2). I have chosen MSP430F149 Micro controller to interface to LCD and have used 8bit logic interface.
Do the connections as you want. However keeping in mind that you do it in sequence. This is will help in easier debugging. In the example provided, I have considered P1 as address/control and P2 as data pins.
Voltage Level mismatch:
To solve the problem of voltage level mismatch between the TIMCU and LCD, as said we will use logic level shifter IC. HCF4050 (or CD4050) from ST electronics. Its a 16 pin IC which converts 3.3V level to 5V level, and 0v to 0v level. These have CMOS hex convertors. The data sheet of IC- HCF4050 can be obtained from the link www.8051projects.info/datasheets/CD_4049.PDF
I will explain one pin connection. RS and similarly others will follow. A diagrammatic representation is as shown. You will require 2- HCF4050 IC to connect the entire LCD to MSP430F149 in 8bit method.
Now in-case if you have used 4bit method, then you require 2 CD4050 since IC supports only 6 conversions. Dont ask me the code for this. Because, if I give the code, then the third problem you will solve very easily! So some problems should be there otherwise you will do copy pasting! Learn and paste ! That is why I am giving. I will write a library file and will try updating it in case you could not solve the problem!
For any other device replace the LCD with your device. Dont forget to use the CD4050. In the last, for every problem there exists a proper solution. Its only the way in which you find it is different.
To solve this problem we have burnt 2 LCDs and 2 MCUs! 😀 Well it paid well though 🙂
The blog is re-blogged at http://vinaykumarn.wordpress.com/2012/03/26/three-mistakes-of-the-lcd-interfacing-lcd-to-msp430/
He is one among my teammate who took time drawing images for you to better understand 🙂