Page 2 of 2

Re: Serial port outputs random data

Posted: Sun Aug 28, 2016 3:50 pm
by Octacone
iansjack wrote:'X' = 0x58, you get 0x18
'o' = 0x6F, you get 0x0F

Do you spot the pattern? You haven't set the number of data bits, so it looks like it has defaulted to 5 bits rather than 7 or 8.
Yeah, @f2 also mentioned it.
Reading the entire wiki can sometimes be useful.
The number of bits in a character is variable. Having fewer bits is, of course, faster, but they store less information. If you are only sending ASCII text, you probably only need 7 bits.
Set this value by writing to the two least significant bits of the Line Control Register [PORT + 3].

Re: Serial port outputs random data

Posted: Sun Aug 28, 2016 4:18 pm
by Ycep
f2 wrote:OK, so your outb() seems correct.

I just found something in your InitPort() function I haven't seen before.
Look at this code from OSDev Wiki ( http://wiki.osdev.org/Serial_Ports#Example_Code ):

Code: Select all

#define PORT 0x3f8   /* COM1 */
void init_serial() {
   outb(PORT + 1, 0x00);    // Disable all interrupts
   outb(PORT + 3, 0x80);    // Enable DLAB (set baud rate divisor)
   outb(PORT + 0, 0x03);    // Set divisor to 3 (lo byte) 38400 baud
   outb(PORT + 1, 0x00);    //                  (hi byte)
   outb(PORT + 3, 0x03);    // 8 bits, no parity, one stop bit
   outb(PORT + 2, 0xC7);    // Enable FIFO, clear them, with 14-byte threshold
   outb(PORT + 4, 0x0B);    // IRQs enabled, RTS/DSR set
}
If I compare it with your code:

Code: Select all

outb(portaddr+1,0x00);
   SetBaud(portaddr,3);
   outb(portaddr,0x03);//0000 0011
   outb(portaddr+2,0xC7);
   outb(portaddr+4,0x0B);
I see on the third line that you are sending the value 0x03 to portaddr and not to portaddr + 3, as you can see in the init_serial() function.
Can you change the line outb(portaddr,0x03) to outb(portaddr+3,0x03) and see if that fixes your problem?

EDIT: removed a comma, thanks octacone :)
Thanks a lot, I appreaciate that. :D
It's still same, but atleast fixed a bit.

Re: Serial port outputs random data

Posted: Sun Aug 28, 2016 4:20 pm
by Ycep
iansjack wrote:'X' = 0x58, you get 0x18
'o' = 0x6F, you get 0x0F

Do you spot the pattern? You haven't set the number of data bits, so it looks like it has defaulted to 5 bits rather than 7 or 8.
As F2 spotted the problem, it was because I was writting it on wrong port. But it's still same. Althrough it's 00:19 there; I shall continue on osdeving for 10 -15 hrs.

Re: Serial port outputs random data

Posted: Sun Aug 28, 2016 4:23 pm
by Octacone
Lukand wrote:
iansjack wrote:'X' = 0x58, you get 0x18
'o' = 0x6F, you get 0x0F

Do you spot the pattern? You haven't set the number of data bits, so it looks like it has defaulted to 5 bits rather than 7 or 8.
As F2 spotted the problem, it was because I was writting it on wrong port. But it's still same. Althrough it's 00:19 there; I shall continue on osdeving for 10 -15 hrs.
I wanted to mention something, does COM0 even exist?
10-15 hours that is perfectly fine. :P

Re: Serial port outputs random data

Posted: Mon Aug 29, 2016 7:24 am
by Ycep
octacone wrote:
Lukand wrote:
iansjack wrote:'X' = 0x58, you get 0x18
'o' = 0x6F, you get 0x0F

Do you spot the pattern? You haven't set the number of data bits, so it looks like it has defaulted to 5 bits rather than 7 or 8.
As F2 spotted the problem, it was because I was writting it on wrong port. But it's still same. Althrough it's 00:19 there; I shall continue on osdeving for 10 -15 hrs.
I wanted to mention something, does COM0 even exist?
10-15 hours that is perfectly fine. :P
Of course that COM0 exists, I said that my code can detect is there COM0 or not.
It won't output anything if it didn't exist, but the thing that it outputs is random.

Re: Serial port outputs random data

Posted: Sun Sep 18, 2016 1:01 am
by osdever
It's not random, as @iansjack said.