Serial communication help

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
devil6600
Posts: 1
Joined: Tue Oct 23, 2007 10:51 am

Serial communication help

Post by devil6600 »

i used the following program to receive data from serial port, the program is working but i get output in the form of repeated characters and most often characters are skipped, for example if the output is "COMPUTER" then i am getting something like this CCCCCCCCCOOOOOOOOOOMMMMTTTTTTTTTRRRRRRRRRRRRR

i have no idea what to do
how can i remove this problem?

i want serial communication to work on baud 4800, 8 data bits, no parity, 1 stop bit

#include "dos.h"
using std::cout;
using std::endl;

int main(void)
{
char st[100];
int i=0;
outportb(0x3F8+0x03,0x80);
outportb(0x3F8+0x01,0x00);
outportb(0x3F8+0x00,0x18);
outportb(0x3F8+0x03,0x03);
outportb(0x3F8+0x01,0x00);
outportb(0x3F8+0x02,0xC7);
outportb(0x3F8+0x04,0x0B);
unsigned char rr;
while(1)
{
rr = inportb(0x3F8);
st[i++] = rr;
if(rr==0x0d)
{
st = '\0';
cout<<st<<endl;
i=0;
}
}
}
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

The fact that you're getting repeated characters makes it seem like a baud problem. Is the reciever using 4800 baud too? Might I suggest using 9600 as it's the default for most clients. (minicom and kermit both use 9600 8N1 as their default mode)
Post Reply