Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

channel numbers in variables

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
kartmanne

Bascom Member



Joined: 02 Mar 2018
Posts: 28

germany.gif
PostPosted: Fri May 17, 2019 11:13 am    Post subject: channel numbers in variables Reply with quote

HI,

I use on a atmega48 two UARTS. Both shall be available, so one is the hardware-uart com1 and the second one is a software-part, because this chip has only one hardware-uart. In general only one com-port will be active. The whole code has ischarwaiting, get and print in many routines. The com-port to use will be switched depending in variuos dependencies (pin states, variables, ...).

I assume, that I have to specify the channel number like GET #1 or PRINT #2. Is there a chance to specify the port in use with a variable? Like i.e GET #var? If not, I have to nearly double 50% of the code to have only one difference #1 or #2.

(BASCOM-AVR version : 2.0.8.1 )

_________________
CU
Manfred
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri May 17, 2019 6:37 pm    Post subject: Reply with quote

You can answer this by yourself by reading the help, topic Open
Quote:
Channel The number of the channel to open. Must be a positive constant >0

From the compiler's point of view it simply needs to know what routine - different for HW-/SW-UART - is to hard-code at compile-time.
If the compiler would be able to create different calling code using a variable channel, it would be called an option.
Obviously it was not required by anyone else, thus this option does not exist.
Quote:
If not, I have to nearly double 50% of the code to have only one difference #1 or #2.

If this was a requirement known at project-start and if it is not possible to swap out calling the two types of UART into a separate subroutine, I'd say you have screwed up.
Quote:
In general only one com-port will be active.

If 'in general' could become an 'always', then a hardware mod can be thought of, one UART and two line-drivers with enable function, alternating enable/disable them via control pin.
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Sat May 18, 2019 12:11 am    Post subject: Reply with quote

I think that you choose wrong chip for this task but in our country we search for the solutions, we dont search for the troubles Very Happy ahahaha...
To the point. Look at the example code that can print into variable dependent channell. Important is that you have this channel openned.
Code:
$regfile = "m44def.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 16
$framesize = 64
$baud = 38400

Config Submode = New
Const Max_msg_len = 20

Open "COM1:" For Binary As #1
Open "COMD.3:38400,8,N,1" For Output As #2

Dim My_msg As String * Max_msg_len

My_msg = "Hello World"

Sub Print_by_serial(byval Serial_nr As Byte , Byref Message As String * Max_msg_len)
 Select Case Serial_nr
  Case 1
   Print #1 , Message
  Case 2
   Print #2 , Message
  Case Else
   Exit Sub
 End Select
End Sub


Call Print_by_serial(1 , My_msg) 'should be printed on the PD1 by HW-UART
Call Print_by_serial(2 , My_msg) 'should be printed on the PD3 by SW-UART

End
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sat May 18, 2019 7:26 am    Post subject: Reply with quote

EDC wrote:
we search for the solutions, we dont search for the troubles

Maybe you would doing better by searching for trouble, as in standard Bascom code a Print may contain different variables.
This is a special feature of the compiler. These chained variables, including implicit conversions like hex(), can not be forwarded as arguments to a function.
This tells: if the TO wants to print anything other than a string, it has to converted to string first. To implement compiler-like behavior into code at each required place will likely cost multiple times the flash and multiple times the efforts of the TOs brute force approach.
Back to top
View user's profile
kartmanne

Bascom Member



Joined: 02 Mar 2018
Posts: 28

germany.gif
PostPosted: Sat May 18, 2019 7:32 am    Post subject: Reply with quote

HI,

I'm the trouble seeker. That's why I get the salary Very Happy Very Happy Very Happy

Yes, changing hardware is an option.

EDC: yes, sub routines with port selection is an obviously option what in fact need additional execution time and message preparation. The tricky one will be the receiving part on the soft-part. The system uses 4 interrupts, two of them are firing in a wide range, down to about 10ms.

But, ok, I see, BASCOM does not handle variables for channel numbers. Regarding timing issues I will spend time to check hardware change options...

THX

_________________
CU
Manfred
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5917
Location: Holland

blank.gif
PostPosted: Sat May 18, 2019 9:49 am    Post subject: Reply with quote

xmega has variable uart channels. but there are PB versions like 328PB that have 2 uarts.
you might check out $serialout and $serialin . you could write some custom code that either handle the HW uart or the SW uart.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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