Serial Ports: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
(Category Rename)
Line 35:
The baud rate is set by writing a divisor value to the UART. The divisor is the fraction of 115200 that makes the baud rate. For instance, the baud rate 57600 would have a divisor of 2.
 
The number of bits in a character is variable. LessHaving fewer bits is, of course, faster, but they store less information. If you are only sending ASCII text, you probably only need 7 bits. These days you could consider 8N1 (8 bits, no parity, one stop bit) pretty much the default.
 
The parity type can be even, odd, or none.
Line 52:
}
</pre>
 
Notice that the initialization code above writes to ports [PORT + 0] and [PORT + 1] twice with different values. The reason for this is because these two ports have different meanings based on the setting of the DLAB (Divisor Latch Access Bit), the most significant bit in [PORT + 3]. When this bit is set, the serial controller maps [PORT + 0] and [PORT + 1] onto the low and high bytes of the Baud Rate Divisor register, and when it is clear they are mapped onto their normal registers.
 
In the code above, the second write to [PORT + 3] clears the DLAB again as well as setting various other bits.
 
===Receiving data===
33

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu