View previous topic :: View next topic |
Author |
Message |
Tubeampman
Joined: 27 Feb 2006 Posts: 100 Location: Bodo
|
Posted: Fri Aug 26, 2016 2:05 am Post subject: Xmega uart problem |
|
|
Hi
I have been struggling with somethig that should not be an issue
The following code produces just rubbish in the terminal, some ideas?
When i short the pins on my FTDI adapter the typed caracters are OK.
Also when i connect a GPS the caracters appear OK
I use BASCOM AVR 2.0.7.9
Thanks
$regfile = "xm256a3budef.dat"
$lib "xmega.lib"
$hwstack = 64
$swstack = 40
$framesize = 40
$external _xmegafix_clear
$external _xmegafix_rol_r1014
$lib "xmega.lib"
Config Osc = Disabled , 32mhzosc = Enabled '32MHz
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
'Config Interrupts
Config Priority = Static , Vector = Application , Lo = Enabled 'Enable Lo Level Interrupts
Config Com1 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
do
waitms 500
Print "hello"
loop
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
JC
Joined: 15 Dec 2007 Posts: 584 Location: Cleveland, OH
|
Posted: Fri Aug 26, 2016 3:32 am Post subject: |
|
|
I don't have a board in front of me to test, and it has been a while since I did any USART work, but I'll offer a thought or two:
Include:
$crystal = 32000000
Otherwise the IDE has to have it set correctly, and if it isn't read in correctly the baud rate will be set up incorrectly, which will give you garbage.
Do you really need:
$lib "xmega.lib"
And why did you list it twice.
My old serial port monitor program didn't use that library.
I don't have time at the moment to look it up and see why you might have included it.
You might not need it.
$hwstack = 64
$swstack = 40
$framesize = 40
The Xmegas have a lot more memory that many of the Tiny and Mega chips.
At least for now increase all of those, perhaps double them.
$external _xmegafix_clear
$external _xmegafix_rol_r1014
I think these were for the earlier versions of the compiler.
I doubt you still need to use them.
Try removing them, although that might not make any difference.
If you are using interrupts then you also need:
Enable Interrupts 'Global Enable Interrupts
In my old program, which only monitored USART input, and I don't recall the details, but it might get you started, I used Bin mode, and Opened the com port.
Config Com1 = 19200 , Mode = 0 , Parity = None , Stopbits = 1 , Databits = 8
Open "COM1:" For Binary As #1
Config Serialin = Buffered , Size = 64
.
.
.
Getspchar:
'Read in one Byte via the Serial Port, from the buffer
'This awaits a character to arrive.
'On Exit have: SPDB Type String*1,
While Ischarwaiting(#1) <> 1 'Await Char in input buffer
Wend
Spdb = Waitkey(#1) 'Get Incoming Character from SP Buffer
Return
If you have an LCD you could try reading in data from the serial port and displaying it on the LCD.
This would verify that you have a working serial port connection, good baud rate, correctly connected TxData and RxDAta lines, etc.
Then work on the uC transmission back to the PC.
JC |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Fri Aug 26, 2016 2:09 pm Post subject: |
|
|
Baud 9600 is slow and, in my case, work without enabling automatic calibration but for 115200 I must enable it.
Code: | $regfile = "xm128a3udef.dat"
$crystal = 32000000 '32MHz
$hwstack = 80
$swstack = 64
$framesize = 128
' ***************** SYSTEM CLOCK CONFIG **************************
' INTERNAL 32MHz NO PRESCALE
'
Config Osc = Disabled , 32mhzosc = Enabled , 32khzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
'
' ENABLING AUTOMATIC OSCILLATOR CALIBRATION
Osc_dfllctrl.0 = 1
Dfllrc32m_ctrl.0 = 1
'
'*****************************************************************
'************ CONFIGURATION FOR COM1 ON PORTC ********************
'
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8 'Tx-PC3 Rx-PC2
Open "COM1:" For Binary As #1
Config Serialin0 = Buffered , Size = 100 'for COM1
Config Input1 = Crlf , Echo = Crlf
'
Const Max_str_len = 150 : Dim Com1_str As String * Max_str_len
'***************************************************************** |
|
|
Back to top |
|
|
Tubeampman
Joined: 27 Feb 2006 Posts: 100 Location: Bodo
|
Posted: Fri Aug 26, 2016 4:47 pm Post subject: |
|
|
Hi
Many thanx to both of you for taking time to try help me.
I wil try your tips and let you know hoe it goes.
Best regards
Øyvind |
|
Back to top |
|
|
Tubeampman
Joined: 27 Feb 2006 Posts: 100 Location: Bodo
|
Posted: Fri Aug 26, 2016 8:37 pm Post subject: |
|
|
Hi
Well i found out that starting on a new project in the middle of the night aint a good idea.
As JC stated, it was the $crystal = 32000000 which was missing.
I guess i didnt think about that line since the oscillatorfrequency is stated elsewhere.
Thanx guys |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|