Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Serail data getting garbled...

Status
Not open for further replies.

Scruit

New Member
When I try to write to one of the UARTs on this Zilog Z8 chip the data arrives all mangled up. I've triple-checked the baud/parity/data/stop bits and they all match, still my data arrives all garbled (but exactly the right number of characters.)

Can anyone recommend where to look for problems? Here is my code;


===========================================
#include <eZ8.h>

void main(void) {
int n,msglen, m,z;
char Status;

char Msg[28]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

PAADDR = 0x02; //point PAADDR at the alternate function register
PACTL = 0x30; // set uart0 Rx & Tx pins to alternate function
PAADDR = 0;


U0BRH = 0x01; //2400 (480) hi-byte
U0BRL = 0xe0; //2400 (480) lo byte

U0CTL0 = 0xC0; // Transmit enable, Receive Enable, No Parity, 1 Stop

msglen = sizeof(Msg);
for(n=0;n<msglen;n++) {
for(m=0;m<0xff;m++)
for(z=0;z<0xff;z++)
;

U0TXD = Msg[n]; // send char
}
}
 
I have not worked with Z80 CPUs but have good experience with 8051 family. I guess the problem lies in your Transmit Loop. Before sending any data you should check if the UART has already finished sending the previous byte or is currently receiving any byte or not. In short check if UART is busy or not. In 8051, there are bits which indicates UART status and I guess you'll find them in Z80 too. So modify your loop so that it will send character only when the PORT is free.
 
Thanks for the reply.

I changed the code to replace the simple delay with;

while((U0STAT0 & 0x04) == 0) {} //bit 2: 0=busy, 1=available for TX

The data still arrives the same, just much more quickly.

I sent that code to ZiLog and they said it worked find on their test boards. The difference was that UART0 is also connected to the console serial port (the one you program the chip with) and they actually turned off the dev environment and ran hyperterminal on the dev computer.

I am connecting my bodged-together serial cable directly to the UART0 pins on the dev board. So, it seems my cable is bad.

I currently have this pin assignment (2400 8-N-1, no flow control)

Z8 - Remote RS232
----------------------
U0RXD - TX
U0TXD - RX
GND - GND
----------------------

Right now I'm thinking there's some fundemental mistake that I'm making, like there's actually supposed to be a seperate 232 chip even though it claims two on-board UARTs - or the tx line is staying low instead of high when it's not TXing, so the receiving end gets confused when data arrives.

I'd love to see how they have their console port hooked up to UART0. Maybe I'm missing something.

They are using hardware flow control with the CTS/DTS, but the onboard UARTS don't have a DTS pin - what's up with that?
 
There is a possibility that your RS232 port is being loaded. Do not connect more than one circuits in parallel on RS232 with using buffers. Check for proper voltages on the Tx and RX lines. IT should be between 8-13V for high and -8 to-13 V for logic low.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top