Changes

How to use UARTs

26 bytes added, 17:48, 23 January 2012
no edit summary
More information about [http://en.wikipedia.org/wiki/UART UART].
'''Note''': This program have a debug option using GPIOs to debug via oscilloscope, this option is useful to learnt about the Kernel latencies. Debug has set to "write" and "select" functions.
= Feedback and Contributing =
</pre>
By default, UART3 is used by Kernel serial console, we need to disable it, go to igep.ini file, comment next line: <br>
<pre>console=ttyS2,115200n8</pre> 
=== Check UARTs devices ===
root@localhost:~/PROGRAM# </pre>
If you don't have setserial installed type:
<pre>apt-get install setserial</pre> 
=== Connect peripherals ===
(Connect to 3) o---| 9 10 |---x (Not used)
------
</pre> 
=== Send some data ===
| style="text-align: left;" | [[Image:Minicom screenshot.png|640x400px]]
|}
 
= Schematics =
 
p
= Compile and run program =
Constant SIZE: it determines the max number of char than can be sent<br>
Constant DEBUG: it can break program infinite loop part, it can be useful to debug some errors, 0 (infinite loop) or positive number determine loop max entrances
Constant WAIT: it configurea select max time.
Once you have installed module. Compile program using your Cross Compiler, I used arm-linux-gnueabi-:
<pre>arm-linux-gnueabi-gcc uart-test-beta1.c -o uart-test-beta1 </pre> 
= Testing UART =
Decoded with [http://www.asciitable.com/ ASCII table].
{| width="200" cellspacing="1" cellpadding="1" border="1" align="center" width="200"
|-
| [[Image:Uart decode1withlf.JPG|350x230px]]
Program sends information via UART1 but don't receive response via UART3, because only a process is executed. This problem is repeated every 5 seconds (constant WAIT=5) until other process sends information via UART3 at the same speed. If "select" hasn't been implemented, process would have stayed blocked.<br>
{| width="200" cellspacing="1" cellpadding="1" border="1" align="center" width="200"
|-
| [[Image:Uart select timeout9.JPG|350x230px]]
|}
Click to enlarge image
=== RS232 Voltage params ===
More information [http://en.wikipedia.org/wiki/RS-232#Standard_details here].
{| width="200" cellspacing="1" cellpadding="1" border="1" align="center" width="200"
|-
| [[Image:Uart voltageparams8.JPG|350x230px]]
Note that wave is degraded when speed is higher
{| width="200" cellspacing="1" cellpadding="1" border="1" align="center" width="200"
|-
| [[Image:Uart 300 o.JPG|260x172px]]
You can see that RS232 have some lag between transmisions. This caused mainly by kernel process management. UART peripheral is controlled by Linux and It isn't a [http://en.wikipedia.org/wiki/Real-time_operating_system real-time operating system].&nbsp;
{| width="200" cellspacing="1" cellpadding="1" border="1" align="center" width="200"
|-
| [[Image:Uart lag left6.JPG|350x230px]]
This program have three I/O functions that connect to UART driver via ioctl: (read(), write() and select()). But select() and write() change process stat to sleep mode until system don't receive or transmit all information via UART. "select" function is used to prevent that read function can be blocked when data aren't available. <br>The next images (program with debug_gpio enabled and 300 bauds speed) show when process is executed or is waiting. Blue=UART1, Violet="write" and Green="select". When GPIO has HIGH value, process is blocked.<br>
{| width="200" cellspacing="1" cellpadding="1" border="1" align="center" width="200"
|-
| [[Image:Uart select5.JPG|260x172px]]
select: blocked until all data is available (LF char received).
write: blocked until all data is send to UART buffer.
=== Error test ===
Every full process the number is increased twice. Program checks that this condicion is true, if it isn't accomplished, process will be finish.
{| width="200" cellspacing="1" cellpadding="1" border="1" align="center" width="200"
|-
| [[Image:Uart_error_test2Uart error test2.png|640x400px]]
|-
| Runs 16h without any transfer error (3000000 bauds)<br>
|}
<br>
[[Category:Communications]] [[Category:How_to_forge]][[Category:Tutorials]]
4,199
edits