CONFIG COMX
Contents |
Action
Configures the UART of AVR chips that have an extended UART like the M2560.
Syntax
CONFIG COMx = baud , synchrone=0|1,parity=none|disabled|even|odd,stopbits=1|2,databits=4|6|7|8|9,clockpol=0|1
Syntax Xmega
CONFIG COMx = baud , Mode=mode, Parity=parity, Stopbits=stopbits, Databits=databits,clockpol=Clockpol
Remarks
COMx |
The COM port to configure. Value in range from 1-4 |
baud |
Baud rate to use. |
synchrone |
0 for asynchrone operation (default) and 1 for synchrone operation. |
Parity |
None, disabled, even or odd |
Stopbits |
The number of stop bits : 1 or 2 |
Databits |
The number of data bits : 4,5,7,8 or 9. |
Clockpol |
Clock polarity. 0 or 1. |
Note that not all AVR chips have the extended UART. Most AVR chips have a UART with fixed communication parameters. These are : No parity, 1 stopbit, 8 data bits.
The Mega2560 does support 4 UART's.
Remarks Xmega
COMx |
The COM port to configure. Value in range from 1-8 |
baud |
Baud rate to use. If the baud rate can be generated accurately depends on the system clock. |
mode |
The USART mode, this can be : - ASYNCHRONEOUS or 0 (default) for asynchronous operation. - SYNCHRONEOUS or 1 , for synchronous operation. - IRDA or IRCOM for IRDA operation - SPI or MSPI for operation as SPI controller
|
Parity |
None, disabled, even or odd |
Stopbits |
The number of stop bits : 1 or 2 |
Databits |
The number of data bits : 5,6,7,8 or 9. |
In the Xmega the registers have a fixed offset. This allows to use dynamic UARTS : you can change settings at run time by using a variable. This will use some more code when using just one UART but will save code when using multiple UARTS because you need only one copy of the code.
In the Xmega you MUST use CONFIG COM before you can use the UART. The CONFIG commands makes a call to _INIT_XMEGA_UART where the various parameters are passed to setup the UART. You also need to specify the baud rate. Do not use $BAUD.
The CLOCKPOL for the SPI mode has been removed, it will be added to a configuration command for the SPI.
The CONFIG COM will set the TX pin to output mode. This are the following pins :
UART |
TX pin |
RX pin |
COM1 - UART_C0 |
PORTC.3 |
PORTC.2 |
COM2 - UART_C1 |
PORTC.7 |
PORTC.6 |
COM3 - UART_D0 |
PORTD.3 |
PORTD.2 |
COM4 - UART_D1 |
PORTD.7 |
PORTD.6 |
COM5 - UART_E0 |
PORTE.3 |
PORTE.2 |
COM6 - UART_E1 |
PORTE.7 |
PORTE.6 |
COM7 - UART_F0 |
PORTF.3 |
PORTF.2 |
COM8 - UART_F1 |
PORTF.7 |
PORTF.6 |
In IRDA mode, depending on the module you use, it might be necessary to invert the logic level of the TX pin with CONFIG XPIN. For example when COM1 is used for the IRDA module, you would use : CONFIG XPIN=PORTC.3, INVERTIO=ENABLED
It is important that you specify all parameters of CONFIG COM. Do not omit one.
See Also
Example
'----------------------------------------------------------------------------------------- 'name : 'copyright : (c) 1995-2008, MCS Electronics 'purpose : test for M2560 support 'micro : Mega2560 'suited for demo : yes 'commercial addon needed : no '----------------------------------------------------------------------------------------- $regfile = "m2560def.dat" ' specify the used micro $crystal = 8000000 ' used crystal frequency $hwstack = 40 ' default use 32 for the hardware stack $swstack = 40 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space 'The M128 has an extended UART. 'when CO'NFIG COMx is not used, the default N,8,1 will be used Config Com1 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Config Com2 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Config Com3 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Config Com4 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 'Open all UARTS Open "com2:" For Binary As #1 Open "Com3:" For Binary As #2 Open "Com4:" For Binary As #3 Print "Hello" 'first uart Dim B As Byte Dim Tel As Word Do Incr Tel Print Tel ; " test serial port 1" Print #1 , Tel ; " test serial port 2" Print #2 , Tel ; " test serial port 3" Print #3 , Tel ; " test serial port 4" B = Inkey(#3) If B <> 0 Then Print #3 , B ; " from port 4" End If Waitms 500 Loop Close #1 Close #2 Close #3 End
Languages | English • Deutsch |
---|