View previous topic :: View next topic |
Author |
Message |
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Sat May 23, 2015 8:19 am Post subject: Is there a way to do this without compiler error? |
|
|
Hello all,
When I use the following code, I get a compiler error
Code: |
If Slota_format = "M" Then
Open "comc.1:1200,8,n,1" For Input As #3 'COMA TXD
Open "comc.2:1200,8,n,1" For Input As #4 'COMA RXD
Else
Open "comc.1:9600,8,n,1" For Input As #3 'COMA TXD <<==== ERROR HERE device already opened
Open "comc.2:9600,8,n,1" For Input As #4 'COMA RXD
End If
|
If I do not have the If/Then statement, it compile fine but will not do what I need. Can anyone suggest a work around?
Thanks,
TIm
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sat May 23, 2015 9:20 am Post subject: |
|
|
Hello Tim
In the blog section I show in my web server code how to set the baud rate by setting the registers
the .inc file will do baud rate changes without using the open com command every time you need to change it.
Regards Paul |
|
Back to top |
|
|
Meister
Joined: 27 May 2010 Posts: 319
|
Posted: Sat May 23, 2015 1:01 pm Post subject: |
|
|
???
What's that?''
Regards, Meister |
|
Back to top |
|
|
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat May 23, 2015 2:07 pm Post subject: |
|
|
Paulvk wrote: | In the blog section I show in my web server code how to set the baud rate by setting the registers |
Even if you're proud of your work and this is the reason you won't miss a occasion to refer about it, I would find it useful, if you would point the exact position in your blog with a link.
In case of this topic for example I wonder which registers you want to modify to set the baud-rate for a SOFT-UART.
For considering your reply not as complete nonsense, I would have to look up the blogs, find your blog, find your specific message, maybe unzip a file. I feel this is requested a bit much.
That's why I did not look up your blog, and as the soft-UART afaik is hard-coded, I simply assume that you did not understood, or exactly read the question and the Pavlov-reflex was stronger.
Sure I would love to see how you do this on an soft-UART.
@TSEYFARTH
Other than you can live with a compiler directive #IF, means it's decided at compile time and never changed at run-time, it won't work. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sat May 23, 2015 2:20 pm Post subject: |
|
|
nothing to add, just that if you want a dynamic software port, use SERIN/SEROUT instead. _________________ Mark |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Sat May 23, 2015 6:14 pm Post subject: |
|
|
Thanks all for your thoughtful responses!
It does need to be dynamic - depends on what daughter board is plugged in. I will look at the serialin serial out as Mark suggested.
Thanks everyone.
Tim |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sun May 24, 2015 12:04 pm Post subject: |
|
|
Now that I am at home and able to get to my code
here is the sub that sets the baud rate in my web server projects
I made a look up table in eeprom so that standard baud rates could only be used
I tested this into Real Term terminal on my PC
Regards Paul
Code: |
'-------------------------------------------
'---set baud rate for serial port and only allow valid setting
'---by not letting user to enter the baud rate
'-------------------------------------------------
Sub Setbaud
Local Lv As Long
Local Lw As Byte
Local Lx As Byte
Local Ly As Byte
Local Lz As Byte
Ly = Bord(1) 'from eeprom
Lz = Bord(2) 'Bord(2) is an eeprom array of 2
'Lw = Ly
For Lx = 1 To 2
Select Case Lx
Case 1 'com port one
Lv = Lookup(ly , Rs232_speeds)
Lxtl = Xtal / Lv 'divide crystal freq. by the wanted baud rate
'Xtal = crystal frequency
Lxtl = Lxtl / 16 'divide the result by 16
Lxtl = Lxtl - 1 'and subtract 1
Ubrr0l = Lxtl 'when you assign a long it will only write the BYTE
Ubrr0h = Uhxtl 'we use an overlayed variable that is the high byte
'com port two
Case 2 'for the 644p & 1284p with two serial ports
Lv = Lookup(lz , Rs232_speeds)
Lxtl = Xtal / Lv 'divide crystal freq. by the wanted baud rate
'Xtal = crystal frequency
Lxtl = Lxtl / 16 'divide the result by 16
Lxtl = Lxtl - 1 'and subtract 1
Ubrr1l = Lxtl 'when you assign a long it will only write the BYTE
Ubrr1h = Uhxtl 'we use an overlayed variable that is the high byte
End Select
Next Lx
End Sub
|
|
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun May 24, 2015 12:31 pm Post subject: |
|
|
Paulvk wrote: | Now that I am at home and able to get to my code
here is the sub that sets the baud rate in my web server projects |
As already stated, the TO uses the SOFT-UART, writing the UBRR-register makes no sense there, UBRR is for the hardware UART.
I'm wondering if you read or understand the topic and following up posts at all, before you write a reply. |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Sun May 24, 2015 7:53 pm Post subject: Keep calm and program in Bascom... |
|
|
Have fun
Ben Zijlstra |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Mon May 25, 2015 1:06 am Post subject: |
|
|
Great sweatshirt Ben!
Thanks to all who replied - I appreciate your efforts!
Tim |
|
Back to top |
|
|
JC
Joined: 15 Dec 2007 Posts: 585 Location: Cleveland, OH
|
Posted: Mon May 25, 2015 3:25 am Post subject: |
|
|
If the issue is you do not have enough pins or hardware USARTS, then you could always consider moving the project to an Xmega.
Some of the Xmegas have 8 hardware USARTS.
If you switch to using a HW USART, then one can easily reconfigure the baud rate registers at run time.
The Xmega A series are the largest Xmegas.
The Xmega E series are the smallest Xmegas.
JC |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Mon May 25, 2015 3:48 am Post subject: |
|
|
I am using a MEGA1281 with 2 UARTS. I may change it, since the board/design will need a new rev, but not sure to what level I want to change it. Never used an XMega so there would be a learning curve there as well. Not to mention the fact that this I am a month late....
Anyway, all great suggestions and thanks again for all of the feedback.
Tim |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon May 25, 2015 2:19 pm Post subject: Re: Keep calm and program in Bascom... |
|
|
bzijlstra wrote: | |
You need one with stronger contrast for Paul
Don't worry, I was not losing temper, I've asked only the obvious questions. |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Mon May 25, 2015 3:09 pm Post subject: At your service!! |
|
|
At your service!! A special one for Paulvk in Sydney
Paul, thanks for all your nice Bascom-code.
Have fun
Ben Zijlstra |
|
Back to top |
|
|
|