Advertisement  

Monday, 26 June 2017
     
 
Main Menu
Home Home
Shop Shop
News News
BASCOM-AVR BASCOM-AVR
BASCOM-8051 BASCOM-8051
Products Products
Application Notes Application Notes
Publications Publications
Links Links
Support Center Support Center
Downloads Downloads
Forum Forum
Resellers Resellers
Contact Us Contact Us
Updates Updates
MCS Wiki MCS Wiki
Online Help
BASCOM-AVR Help BASCOM-AVR Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login
Username

Password

If you have problem after log in with disappeared login data, please press F5 in your browser

RSS News
 
     
 

 
   
     
 
AN #146 - Loopback test Print
L O O P B A C K  T E S T by Luciano

When a Loopback test is performed, data is sent from the pin 3 of the serial port and it is immediately looped back by a loopback plug to the pin 2 of the same serial port. (9-Pin serial port connector).
A loopback test is useful to quickly verify the functioning of the serial port of a computer. All what we need is a loopback plug, which is described later on in this document. Using the same concept, I have replaced the loopback plug with an AVR microcontroller. This tool provides a simple environment where
you can test the basics of the serial communication programming with Bascom AVR. This program is less complicated than a standard terminal emulator program but it is not a replacement for it.



Performing a loopback test with a loopback plug

Hardware requirements:
In order to perform this test you will need to plug into the serial port of your computer a loopback plug. A loopback plug is a female DB-9 connector with pin 2 and pin 3 shorted.
(Pin 2 and pin 3 are connected together).

Software requirements:
- Windows 2000 Workstation or Windows XP.
- The program Loopback.exe. (This tool).

Run the program Loopback.exe. (If you get an error message, read the last part of this document.'General notes about the Loopback tool'). From the main screen of the program, select the serial port and the baud rate. Note that you can also enter a custom baud rate. Press the button 'Loopback'. The tool will open the selected serial port and send out 1000 bytes of data. (The blue text ABCDEFGHIJABC....in the upper window). If the serial port is operational, immediately you will see the same data coming back in the lower window. (The
green text in the lower window). If the data received back is the same as the data sent, the program will display 'PASS'. If the data is different, the program will display 'FAIL'. More precisely, when 1000 bytes are received back, the program will immediately close the serial port and compare the data. If the data received back is less than 1000 bytes, the program will wait for the calculated minimum transmission time plus a variable delay preceding a time-out.
During this time, the program repeatedly checks the reception buffer of the serial port and will display 'FAIL' if within this time the correct data is not received back. The time-out occurs after a 3000 ms delay for baud rates up to 300 bauds, 1000 ms for baud rates from 301 to 1200 bauds and 100 ms above 1201 bauds. When the time-out occurs, the serial port is closed. If within the delay the thousandth byte is received, the serial port is closed immediately and the data is compared. The program shows timing information for the various operations. Some elements of the GUI have the ToolTip enabled giving additional information. The yellow Tooltip pops up when you move the mouse pointer over the element of the graphical interface.
The idea here is to perform a loopback test using a microcontroller instead of the female DB-9 connector with pin 2 and pin 3 shorted.
The AVR will receive and send back the data immediately. The main screen of this program shows a diagram with the connections to the microcontroller system.
This test is almost the same as the previous test. If you have not read the description of the previous test, please do it now.

Hardware requirements:
- AVR microcontroller system with a RS-232 transceiver.
(RS-232 level shifter).
- Serial cable.
Software requirements:
- Windows 2000 Workstation or Windows XP.
- The BASCOM AVR compiler.
- The program Loopback.exe. (This tool).

The aim of this tool is to provide a simple environment where you can test the basics of the serial communication programming with Bascom AVR. With this tool you can verify that your Bascom AVR
program is fast enough to keep up with a given baud rate. With the two Bascom AVR sample codes you can see in the next two pages, at 14.7456 MHz I was able to pass the loopback test up to 921600 baud,
which is also the maximum baud rate for the serial ports of my PC. (16C950 UART on a PCI card). The standard UART soldered on the motherboard of a PC can usually handle up to a baud rate of 115200.
For data rates higher than 115200 baud, you will also need a high speed RS-232 transceiver. (The MAX232 operates only up to 120 kbit/s).
The following two samples are just very basic examples using the hardware UART of the AVR microcontroller. Bascom AVR has a wide support for hardware UART and software UART. See the Bascom AVR help
file for more details.
To respond to problems such as the receiver getting overloaded, real applications generally use also hardware or software handshaking. The tool does not implement any form of flow control. (Handshaking).
The serial port of a computer uses large FIFO buffers. The program was tested up to 921600 bauds and no data was lost during the transmission. (Use the loopback plug to test your serial port).

' Bascom loopback sample code A (Polling mode)
'
' For data rates higher than 115200 baud, you will need a high
' speed RS-232 transceiver. (The MAX232 operates only up to 120 kbit/s).
' This code was tested up to a baud rate of 921600.
'
$regfile = "m16def.dat"
$crystal = 14745600
$baud = 115200
$hwstack = 32
$swstack = 16
$framesize = 32
Dim Rx_char As Byte
Do
If Ischarwaiting() = 1 Then
Rx_char
= Inkey()
'Rx_char = Rx_char + 32 'Uncomment this line to send back lower-case
Printbin Rx_char
End If
Loop
End
' =======================


' Bascom loopback sample code B (Interrupt-driven mode)
'
' For data rates higher than 115200 baud, you will need a high
' speed RS-232 transceiver. (The MAX232 operates only up to 120 kbit/s).
' This code was tested up to a baud rate of 921600.
'
' Character LCD Module in 4-bit mode:
'
' The LCD pins DB0, DB1, DB2, DB3 are not connected.
' The LCD pin R/W is connected permanently to GND.
' With most displays you can connect the contrast pin to GND.
' For optimum contrast, on some displays you need a slightly
' positive voltage on this pin. Using a 10k potentiometer between
' +5V and GND should give an optimum setting for most displays.
'
$regfile = "m16def.dat"
$crystal = 14745600
$baud = 115200
$hwstack = 32
$swstack = 16
$framesize = 32
Config Lcd = 16 * 2
Config Lcdpin = Pin,Db4=Portb.4,Db5=Portb.5,Db6=Portb.6,Db7=Portb.7,E=Portb.3,Rs=Portb.2
Config Lcdmode = Port
Cursor Off
Dim Rx_char As Byte
Dim My_counter As Long
On Urxc Getchar
Enable Interrupts
Enable Urxc
Waitms 100
Cls
Lcd "Power on!"
Waitms 1000
Do
Cls
Incr My_counter
Lcd My_counter
Waitms 1000
Loop
End
Getchar
:
Rx_char
= Inkey()
'Rx_char = Rx_char + 32 'Uncomment this line to send back lower-case
Printbin Rx_char
Return
' =========================================================



AVR baud rate calculator (Asynchronous operation)

With the baud rate calculator you can calculate all the possible baud rates for a given system clock frequency. This tool will help you find the best system clock frequency for your application.
From the graphical user interface you can select the values for the requested baud rate and the used system clock frequency. If desired you can enter custom values.
The calculator shows the following values:
(With U2Xn=0 and U2Xn=1).
- Baud rate closest match
- Baud rate error in %
- UBRRn values (UBRRnH - UBRRnL)
The calculator will also show a list with all the possible 4096 UBRRn values. (4096 with U2Xn=0 and 4096 with U2Xn=1).
If you select any of the UBRRn value from the list, the calculator will display the UBRRnH - UBRRnL values. If you click with the mouse on one of the two grey UBRRn numeric values, the same value is located in the list. (UBRRn values in the upper part of the form).
The tool calculates the values using the equations that can be found in the Atmel AVR datasheet.
Bascom AVR automatically calculates and sets the baud rate register values for you. This is done when you use the compiler directive $BAUD = x in your code or when you set the baud rate from the Bascom AVR IDE. The Bascom IDE also shows the baud rate error in %.



General notes about this Loopback tool
This tool is freeware. There is no support for this tool. The program was developed by Luciano, a member of the Bascom AVR forum. The software runs intentionally only on Windows XP and Windows 2000 machines. No data is written to the Windows registry or to the hard disk. The program was developed using Visual Basic 6.0. The serial port is accessed through the Windows API, so there is no need to install additional components.
All applications written with Visual Basic 6.0 require the Visual Basic 6.0 run-time files to be installed on the computer. If your computer is running Windows XP, the Microsoft Visual Basic 6.0 runtime files are already installed on your system. If Visual Basic 6.0 run-time files are not already on your system, you can download the self-extracting file vbrun60sp6.exe from Microsoft.
VBRun60sp6.exe is a self-extracting executable file that installs the latest versions of Visual Basic 6.0 run-time files. The files include the fixes that are included with Visual Studio 6.0 Service Pack 6.

Microsoft support link:
http://support.microsoft.com/default.aspx?scid=fh;en-us;vbruntime

Download file for this application note

Luciano