Page 1 of 2
PLEASE HELP NEWBIE! Rs-232/Microcontroller
Posted: Sun Sep 28, 2003 9:32 pm
by funkymule
I'm an experienced programmer, but new to microcontrollers. The VFD display was suppposed to be the easy part of my project, but I am having one hell of a time!
I bought the VFD2041 to match the display in the dashboard of my Corvette. Using a DB9 from the computer, the display works perfectly.
I wrote and tested code on my Atmel microcontroller, and had the RS-232 output sent back to the computer's COM2 port. Everything was working fine.
I wired my microcontroller wires, to the Rx/Tx pins of my VFD, and nothing happens. I tried wiring into pins 2,3 & 5 of the DB9 on the VFD, and nothing.
Sometimes when I hook the VFD to the STK500 development board, garbage rapidly scrolls across the screen and the development board isn't even turned on!
What the heck is going on? The display obviously works...I can write to it through COM1 from the PC. The microcontroller obvioulsy works, I am watching the data go from the MC to the PCs COM2. Why will they not work together, and why is it giving me all kinds of garbage?
Any help is greatly appreciated.
Posted: Mon Sep 29, 2003 10:21 am
by Miles
Hello...
By you saying that you "wrote and tested code on my Atmel microcontroller, and had the RS-232 output sent back to the computer's COM2 port. Everything was working fine", do you mean that you took this exact RS232 ouput and connected it directly to the VFD and it still didn't work? I assume you are using some sort of terminal program...Do you have it set at 19200 baud, 8N1 and flow control set to none...? Also, it is imperative that a good communication ground is established between the development board and the display.

Posted: Mon Sep 29, 2003 3:06 pm
by funkymule
Exactly. I took the DB9 out from my Microcontroller, into COM2 on my PC, and watched the data with HyperTerminal. Then I took the DB9 off of my PC, and into the back of the VFD, and it did not respond at all. My HyperTerminal settings were 19200 baud, 8N1, with Hardware flow control. Could that be the difference?
Posted: Mon Sep 29, 2003 3:09 pm
by funkymule
Also, shouldn't the DB9 provide a good ground to the development board and display? or is there something else i have to do?
Posted: Mon Sep 29, 2003 3:10 pm
by Miles
Our units do not use hardware flow control and this should be switched to none...try this!
Posted: Mon Sep 29, 2003 3:15 pm
by Miles
The three lines to make "sufficient" communication are Rx, Tx and Grnd. As long as these lines are connected appropriately, everything should be O.K!!
Posted: Tue Sep 30, 2003 8:24 am
by funkymule

I changed flow control to none. i still can't get my VFD to respond. also, when I hook up the Rx/Tx wires between the +5V/Gnd wires, my VFD screen goes haywire! When I unplug the wires, it stops. When I plug the wires in to my development board, it prints crazy characters repeatedly. The funny thing is, the development board isn't even turned on!
Has anyone ever had success using a microcontroller with this VFD?
Any suggestions about where to go next? Please?

Posted: Tue Sep 30, 2003 9:34 am
by Henry
You are talking to the display through the power header, using the Rx and Tx lines. Did you set the jumpers to allow RS232 through the power header? The VFD2041 works just fine on any uC, I have used 4 different ones with out any prolems.
Posted: Tue Sep 30, 2003 10:36 am
by Miles
Would it possible to show us how you have it connected as well as a piece of your code that you use to initialize the VFD??
Posted: Tue Sep 30, 2003 10:40 am
by funkymule
I set the jumpers above the DB9 to the RS-232 side like the image at the top of page 10 in the manual (VFD2041_02.pdf). Then i connected wires to the Tx/Rx pins on the power header to the Tx/Rx pins on my uC development board.
Posted: Tue Sep 30, 2003 11:57 am
by funkymule
Excellent. I will go home and gather the info with pics and sample code. I'm sure I'm doing something stupid. I'm just not sure what that is!

Thanks for your help. Will get back with the info!
Posted: Tue Sep 30, 2003 2:20 pm
by Miles
Another thing you can try is connecting our display via TTL and bypass the development board RS232 circuit. All that needs to be completed is the appropriate jumps as described in the manual and a connection directly from the uprocessor!!

Posted: Wed Oct 01, 2003 2:07 pm
by funkymule
OK. This is driving me crazy.
Here's what I've done so far:
Sample C++ from my PC to VFD:
Code: Select all
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
DCB dcb;
HANDLE hCom;
hCom = CreateFile("COM1",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
GetCommState(hCom, &dcb);
dcb.BaudRate = CBR_19200; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit
SetCommState(hCom, &dcb);
DWORD dw;
char buffer[256];
// set up screen options:
buffer[0] = 0xfe;
// auto line wrap off
buffer[1] = 68;
WriteFile(hCom,buffer,2,&dw,NULL);
// auto scroll off
buffer[1] = 82;
WriteFile(hCom,buffer,2,&dw,NULL);
// turn off underline cursor
buffer[1] = 75;
WriteFile(hCom,buffer,2,&dw,NULL);
// turn off blinking cursor
buffer[1] = 84;
WriteFile(hCom,buffer,2,&dw,NULL);
// clear the screen
buffer[1] = 88;
WriteFile(hCom,buffer,2,&dw,NULL);
lstrcpy((LPTSTR)buffer,"Hello, World!");
WriteFile(hCom,buffer,lstrlen(buffer),&dw,NULL);
CloseHandle(hCom);
return 0;
}
Works perfect! (looks cool as hell, too

!)
Next step, CodeViewAVR to program uC.
Here's the code I came up with:
Code: Select all
#define RXEN 0x04
#define RXC 0x07
#define TXEN 0x03
#define UDRE 0x05
void TransmitByte( unsigned char data );
#include <90s8515.h>
// Standard Input/Output functions
#include <stdio.h>
// Declare your global variables here
void main(void)
{
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0xff;
TCCR0=0x00;
TCNT0=0x00;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
GIMSK=0x00;
MCUCR=0x00;
TIMSK=0x00;
UCR=0x08;
UBRR=0x0B;
ACSR=0x80;
TransmitByte(0xfe);
TransmitByte(68);
TransmitByte(0xfe);
TransmitByte(82);
TransmitByte(0xfe);
TransmitByte(75);
TransmitByte(0xfe);
TransmitByte(84);
TransmitByte(0xfe);
TransmitByte(88);
TransmitByte('H');
TransmitByte('e');
TransmitByte('l');
TransmitByte('l');
TransmitByte('o');
TransmitByte(',');
TransmitByte(' ');
TransmitByte('W');
TransmitByte('o');
TransmitByte('r');
TransmitByte('l');
TransmitByte('d');
TransmitByte('!');
}
void TransmitByte( unsigned char data )
{
while ( !(USR & (1<<UDRE)) )
; /* Wait for empty transmit buffer */
UDR = data; /* Start transmittion */
}
Now, to make sure it works, I hooked my development board to COM2 of my PC, and watched output with HyperTerminal. Perfect. Works like a charm. Each time I reset the uC, I see the bytes go to HyperTerminal.
Last step, hook uC to VFD.
1st attempt: using DB9 from development board to VFD (just pulled out of PC COM2 and plugged into VFD).

No response from VFD
2nd attempt: using 2 wires, from PD0 and PD1 on uC to Rx/Tx on VFD (with jumpers set to RS-232).

No response from VFD
What am I doing wrong?
Does anyone see anything I did wrong. Any help is appreciated.
Thx.
Posted: Wed Oct 01, 2003 2:15 pm
by Miles
On attempt number 2, did you change the display to TTL mode as described in the manual? You will be receiveing TTL CMOS directly of the uprocessor so you need to make the unit compatible. Also be sure to connect a ground for communication...
Posted: Wed Oct 01, 2003 3:15 pm
by funkymule
Well, I don't really know what TTL is, and that may be part of the problem. The manual says that "Three modifications have to be made." but doesn't go into detail. Is it just soldering across the jumps? Does this
have to be done to communicate with the uC directly thru the power header pinout? 'Cause I didn't do that, so that might be my problem.
Also, you say connect a ground for communication. Connect where? I have the ground on the power header. Do I need another?
