Serial port outputs random data

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.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Serial port outputs random data

Post 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].
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: Serial port outputs random data

Post 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.
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: Serial port outputs random data

Post 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.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Serial port outputs random data

Post 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
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: Serial port outputs random data

Post 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.
User avatar
osdever
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am
Contact:

Re: Serial port outputs random data

Post by osdever »

It's not random, as @iansjack said.
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing

OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Post Reply