Saturday, 6 December 2014

USB Programmer for 93c46 family EEPROMs

I have seen many people have been searching for a At93c46 programmer. Some time ago i built a programmer for one of my friend. So here i am publishing its source and schematic. 

I built the programmer using ATTINY2313 AVR micro-controller. My programmer uses V-USB library to implement a software based USB protocol handler.



If you want the high-resolution PDF format of the schematic here it is.

I have implemented the programmer using the USI module found in the ATTINY. However there where couple of glitches which came up when interfacing with same chip from different manufacturers. Solution for it is provided in the Host Software.

The USI module of Tiny2313 is configured to run as SPI Master mode 0.

The Source code for the programmer can be found at https://github.com/neutronstriker/VUSB_93C46_PROG.

If you want only the at93c46 interfacing library then you will only need at93c46.h and at93c46.c files from the repository.

The companion windows software is at https://github.com/neutronstriker/UBS93CxxProg

Just enter the program name in the console and press Enter it will show all the commands that are valid.


I built the circuit and fit it into a small transparent case. This is what my final design looks like:




Since I designed the programmer circuit on a perfboard(DOT PCB). So i can't provide any board layouts. But you are welcome to make your own designs. Click here to download the schematic in .sch format.

Until now i have only added support for the c46 chip with 1KBit, but in future i may add support for c56, c66 and other members of the family. Meanwhile if any you are interested to add support for other chips, then just grab the source and modify as you like.

If you have any suggestions or question you can post a comment.

Friday, 5 December 2014

Programming and Interfacing the Serial/UART/RS-232 port of a Computer/PC in Windows and Linux Part-2

So here is the linux part of my tutorial on how to interface a serial port. Windows part is here.

To say the truth the programming a serial port is comparatively easier in linux then in windows.

In linux we can open the serial port directly using the terminal emulator. As the terminal emulator has nearly the same settings like a Serial Terminal.

Below is the code for a basic SerialConsole like program which sends any characters typed to the serial port and prints received text in the terminal emulator.



So first we have to override the terminal settings and then apply the settings for the serial port.

You can compile the program directly in linux and run it. Like i wrote above make sure you have proper rights to access the serial port, or better just run the program as root user.

So this is the end of my serial port tutorial.

If you have any questions or suggestions feel free to post a comment.

Wednesday, 3 December 2014

3 wire interface for 16x2 or 8x2 or any other HD44780 based LCDs.

When interfacing with Micro-controllers a LCD display could be a very useful tool either for debugging or displaying messages or to show result of a calculation or some other information.

In embedded World the most popular LCD is a 16x2 display i.e. 16 characters per line and 2 lines on the display. However there are other variants like 8x2 or 20x4 etc. These Displays are run by the very popular lcd controller Hitachi HD44780.



This display controller is the most widely used one and has lot of documentation available on the web. However while interfacing it with micro-controllers one problem arises very often. The scarcity of pins.

The HD44780 operates on a 8bit or 4bit wide bus and requires at-least 2 extra control pins(3 to be exact). So the minimum number of pins required to interface such a display is 6.

So to add a lcd to our micro-controller system we will have to sacrifice at-least 6 pins of our micro-controller. If we are using 40pin ICs like ATMEGA32 or 89C51/89S51 or 40 pin PIC then it is not much of a concern.




But if our chip has about 20 or less than that pins for IO? lets take Arduino UNO for example we have only 14 digital + 6 Analog/Digital pins. Reserving 6 pins for LCD is very tragic.

But what if we could reduce the number of pins required. This can be achieved by a very simple and effective digital logic chip : A Serial in Parallel out shift Register.

So by using a shift register either CD4094 or 74HC595 we can interface the Lcd with the help of only 3 pins.

A serial-in-parallel-out shift-register takes data-in using essentially one pin only(however another pin CLK is required to synchronise the transfer) and it has in general a 8 bit output(i.e. 8 output data pins).




So we send the data using only one pin of the micro-controller and then as usual the 4bit or 8bit data is given to the LCD controller by the Shift-register.

However another pin Strobe is required to enable or disable the output of data on the pins. Because if we keep continuously sending the data and data keeps travelling on the shift-register's output pins continuously then the lcd controller can get mad.

So what we do is we actually hold the outputs until the whole 8 bits are sent into the shift register. Then we release the output pins and data goes into the lcd controller.


But remember since we still need to control the RS(register select) and E(enable) pins of the LCD controller and that is also accomplished by the help of shift-register. 

So what i did was that i connected the RS and EN pins of the LCD to the shift-register output pins and sent the same data or control byte twice; once with EN set(1) and again the same data content and RS value but EN pin value cleared(0).

In this way the EN pin was provided with CLK.

Since i was using 4bit data bus so i had to send 4 nibbles while using Shift-register as opposed to the 2 nibbles when directly connected.

I have made a project to demonstrate this on AVR micro-controller you can get it here. This project also contains an arduino sketch with the same functionality. 

However i have also made a ready made library to to integrate it with your existing programs. Here is the link to the library. You just need to keep two files sipolcd.h and ds.h in the folder of your <main_program>.c file and and before including sipolcd.h  you need to define SIPO_PORT possible values are A,B,C,D or whatever ports your AVR has.

And then SPIN which is the DATA pin of Shift-register, STB i.e. strobe, and CLK is CLOCK.

Let me put an example here.

You can find other keywords in the keywords.txt file in the above mentioned library.

And finally here is the code in action.




We know that to be able to use the LCD with only 3 wires is cool but there are some people who have made it possible to use a lcd with Only 1 wire, That's right only 1 wire is enough. But it is a little tricky and you will have to go a little deeper with R-C time constants and frequencies etc. Here is the link to the Shift1_System.

So as usual guys if you have any suggestions or questions feel free to post a comment.

Monday, 15 September 2014

Programming and Interfacing the Serial/UART/RS-232 port of a Computer/PC in Windows and Linux Part-1

From now on in this article i will be using the Serial/COM/UART words interchangeably so dear readers please cope with it. RS-232  is also the same just that it defines the same communication protocol with different voltage levels. Read more about it at RS-232 wiki.

After many futile attempts of trying to write a program in C/C++ to access the serial port of a computer especially in windows, I finally succeeded in writing a simple program in C to access the serial port of windows to send and receive data.

Now in this era of modern computers where high-speed lan, wifi and optical fibre like communications method exist some of you might think what is the use of serial port, also most of computers nowadays don't have a serial/com port any more.

But ask any electronic engineer or an embedded system designer or any networking engineer dealing with programming of modems, network switches etc or to my fellow hobbyists and electronic enthusiasts out there, a serial port is as important and crucial tool of their day to day requirement as you can say is a hammer is to a blacksmith.

I agree that serial ports have disappeared from modern PCs but to fill the void and especially suited for the needs of people like us are Usb to Serial converters available in the market from many vendors to list a few FTDI232RL/230x/231x  and Prolific PL2303 or Silicon labs CP2102 etc.There are many more also.

Now using them for sending and receiving data from a device having a UART is very easily accomplished in windows or linux or osx, by using the appropriate drivers for the device and using a console application like hyper-terminal or Termite in windows or Putty which is cross-platform. So that we can communicate with our device may be for programming or debugging or just for using as input/output console for example with microcontroller platforms like Arduino, AVR, ARM, PIC, 8051 etc.

But sometimes need arises to write a custom application so that you can make it a total standalone app fine tuning it according to your requirement. 

Like for example suppose i want a windows app to have a few buttons such that when i press a button a particular character is sent to the serial port; now i can send a character using any serial console apps described above, but suppose i need it for use by people of non-technical background to operate this. Then it would be a bad idea to think of training the end user for operating the product using a terminal app which would obviously be difficult for non-technical people instead we can just ask the end user to press a button.

But for that we will have to build a custom app which can interface with serial port. Many people have built this kind of stuff but there are rarely good articles on the web which can explain people with very less experience in windows coding where to begin from.

For people like me with not so much experience with windows programming it is a difficult feat to achieve especially the receiving data part(sending data is comparatively easier).

After doing a lot of search on the web and reading a few books i was able to send data using a program built in Visual C++/CLR dotnet. But still i was not able to receive data. I wrote this program for an embedded systems project i did "Bluetooth based home automation". In this project, by sending certain characters to the device using serial port i could turn on or off household electrical appliances connected to it.

But recently i figured it out how to write a simple ( totally basic command line) program to send and receive data from serial port. well this was a good start then building upon it, I decided to build a console like Windows app in C/C++( not .net) and i can say i somewhat succeeded as i was able to send and receive data using it. I built the GUI part using wxWidgets(had to mess around a lot first to get the wxWidgets to work at beginning) and used the same C code used in the console app to deal with the UART interfacing part. Well it has a few bugs but i consider it not bad for beginners like me.

Below you can find the complete code for the command line program. The program below uses WINAPI. You can compile it using any free version of Visual Studio or using mingW. You can use Codeblocks also it comes with a pre-configured version of mingW.

Most of the code is self explanatory but i will explain the important ones.


Here is the link  https://github.com/neutronstriker/SerialPortWin to whole project you can download it and modify it if you like.


I think after going through the whole code thoroughly by now you must have understood the basics of sending and receiving data from the serial port in C using WINAPI.

So lets now proceed to make a more user-friendly app i.e. a GUI(Graphical user interface) program, which should be easy to use even by the non-programmers.

So using the same functions used above to send and receive data i made a GUI program GUI_SerialConsole_wx. I made the GUI part using wxWidgets and CodeBlocks IDE. 

Well Codeblocks i a great IDE and when combined with wxWidgets makes building the GUI part as easy as possible.

Here is a screen shot of my app 



Now if you want the program only and want to skip the hassle of searching for the dependencies then here it is Release.7z. It contains all necessary files related to the program.

However i have to warn you that this is test-only initial release and it has lot of bugs especially related to the receiving part. Because the program needs to actively keep polling the serial port buffer for any new characters received, So that it can be shown in the app window. 

But it requires multi-threaded programming or Inter process communication, with which i am not much familiar. 

So what i did was i used wx_timer to initiate a 1-Second timer and whenever the timer event was triggered i would display the characters in the lower Receive Data Box. Well this works but isn't a very clean solution to our problem.

So i welcome you to modify the code and solve the issue if you like.

For basic programming of serial port in linux please read the next part of this blog..