View previous topic :: View next topic |
Author |
Message |
atmega64
Joined: 23 Feb 2005 Posts: 298 Location: ITALY
|
Posted: Fri Mar 06, 2020 4:01 pm Post subject: Bug BASCOM AVR 2.0.8.2 version? |
|
|
Hi,
why does the following code work only with BASCOM version 2.0.8.1 and not with version 2.0.8.2?
Code: |
$regfile = "m1284def.dat"
$crystal = 16000000
$baud = 19200
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Portb.4 = Output 'BUZZER
Buzzer Alias Portb.4
Declare Sub Bip
On Urxc Rxcom1_isr
Enable Urxc
Open "COM1:" For Binary As #1 'open channel
Dim Rxdata1$ As String * 254 , Rxcmd As String * 254 , Id As String * 2
Dim Comchar1 As Byte
Dim Rxdata1 As Bit
Enable Interrupts
'ID DEVICE
Id = "06"
Reset Rxdata1
Rxdata1$ = ""
Bip
Do
If Rxdata1 = 1 Then
Reset Rxdata1
If Left(rxdata1$ , 1 ) = "[" And Right(rxdata1$ , 1 ) = "]" And Len(rxdata1$) > 5 Then 'comando corretto
If Id = Mid(rxdata1$ , 2 , 2) Then
'Rxcmd = Mid(rxdata1$ , 4 , 2)
Select Case Mid(rxdata1$ , 4 , 2)
Case "GM" : Bip
Waitms 500
Print "OK GM";
Case "GS" : Bip
Waitms 500
Print "OK GS";
Case "SM" : Bip
Waitms 500
Print "OK SM";
End Select
End If
End If
Rxdata1$ = ""
End If
Loop
Rxcom1_isr:
Comchar1 = Inkey()
Rxdata1$ = Rxdata1$ + Chr(comchar1)
If Comchar1 = 93 Then '] the closed square bracket ends command reading
Set Rxdata1
End If
Return
Sub Bip
Buzzer = 0
Waitms 20
Buzzer = 1
End Sub
End |
While if I modify the code as follows, it works with both versions
Code: | Rxcmd = Mid(rxdata1$ , 4 , 2)
Select Case Rxcmd |
(BASCOM-AVR version : 2.0.8.2 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Mar 06, 2020 9:48 pm Post subject: |
|
|
According to help, 'select case' expects a var and not another function. Thus it is not guaranteed that it works with a newer version, even it works with an older one.
Second, declarations for stack and frame are missing in the shown code. In such case the IDE's values are used, which may differ between the versions.
Too small values for stack and frame may create surprising effects. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Mar 09, 2020 12:40 pm Post subject: |
|
|
MWS wrote: | Too small values for stack and frame may create surprising effects. |
Indeed. And that is the problem here. there is not sufficient frame space to create a temp string of the MID result.
when you have a string with a length of 100, the maximum data it can contain is 100 chars/bytes.
when you do an operation on that string which requires a full copy, you need enough frame space. that is where temp data is stored.
simple sample :
s="abc"
s= s + "x" ' ok no need to have a temp copy since we add to the end of the string
s="klm" + s 'this is where we need a copy of S because S is overwritten with new data + the old data
using SELECT with a function that returns a string works similar. _________________ Mark |
|
Back to top |
|
|
atmega64
Joined: 23 Feb 2005 Posts: 298 Location: ITALY
|
Posted: Mon Mar 09, 2020 2:03 pm Post subject: |
|
|
ok...
but how do you explain that with v.2.0.8.1 it works? |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Mar 09, 2020 8:53 pm Post subject: |
|
|
atmega64 wrote: | but how do you explain that with v.2.0.8.1 it works? |
Already said, one more time:
Quote: | In such case the IDE's values are used, which may differ between the versions. |
Did you at least try if your code works with any version and proper stack/frame values? |
|
Back to top |
|
|
atmega64
Joined: 23 Feb 2005 Posts: 298 Location: ITALY
|
Posted: Tue Mar 10, 2020 8:08 am Post subject: |
|
|
Quote: |
Already said, one more time:
Quote:
In such case the IDE's values are used, which may differ between the versions.
|
Obviously I had already checked that IDE's values were the same ...
Quote: | Did you at least try if your code works with any version and proper stack/frame values? |
I will try soon ... |
|
Back to top |
|
|
atmega64
Joined: 23 Feb 2005 Posts: 298 Location: ITALY
|
Posted: Tue Mar 10, 2020 8:55 am Post subject: |
|
|
I confirm that even increasing the stacks / frame values it only works with the BASCOM version 2.0.8.1
Code: | $regfile = "m1284def.dat"
$crystal = 16000000
$hwstack = 48
$swstack = 40
$framesize = 48 |
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Mar 10, 2020 12:00 pm Post subject: |
|
|
I tested with 2082 and it seems to work just fine.
I did mod your code a bit. it is not a good idea to have variables with the same base name.
Code: | $regfile = "m1284def.dat"
$crystal = 16000000
$baud = 19200
$hwstack = 48
$swstack = 40
$framesize = 48
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Portb.4 = Output 'BUZZER
Buzzer Alias Portb.4
Declare Sub Bip
On Urxc Rxcom1_isr
Enable Urxc
Open "COM1:" For Binary As #1 'open channel
Dim Rxdata2$ As String * 254 , Rxcmd As String * 254 , Id As String * 2
Dim Comchar1 As Byte
Dim Rxdata1 As Bit
Enable Interrupts
'ID DEVICE
Id = "06"
Reset Rxdata1
Rxdata2$ = "[06GM TEST]"
'Bip
Do
If Rxdata1 = 1 Then
Reset Rxdata1
If Left(rxdata2$ , 1 ) = "[" And Right(rxdata2$ , 1 ) = "]" And Len(rxdata2$) > 5 Then 'comando corretto
If Id = Mid(rxdata2$ , 2 , 2) Then
'Rxcmd = Mid(rxdata1$ , 4 , 2)
Select Case Mid(rxdata2$ , 4 , 2)
Case "GM" : Bip
Waitms 500
Print "OK GM";
Case "GS" : Bip
Waitms 500
Print "OK GS";
Case "SM" : Bip
Waitms 500
Print "OK SM";
End Select
End If
End If
Rxdata2$ = ""
End If
Loop
Rxcom1_isr:
Comchar1 = Inkey()
Rxdata2$ = Rxdata2$ + Chr(comchar1)
If Comchar1 = 93 Then '] the closed square bracket ends command reading
Set Rxdata1
End If
Return
Sub Bip
Buzzer = 0
Waitms 20
Buzzer = 1
End Sub
|
i would not recommend to work on a variable inside an int and in the main program without disabling interrupts in the main code.
in your code it might work but take in mind that when you do : Rxdata2$ = "" in the main code
and the ISR adds data, it will depend on where the main code is executing if you get that data or not. _________________ Mark |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Mar 10, 2020 12:38 pm Post subject: |
|
|
atmega64 wrote: | Obviously I had already checked that IDE's values were the same |
To make it 'obvious' for the reader, you would need to write that you have checked it.
Did not notice that, where in this thread did you write it?
The help mentions %&#! as suffixes for numeric variables, but I see nowhere in the help the dollar-sign suggested.
Help for 'Dim' shows the dollar sign used as compiler-directive prefix or as hex notifier, but I don't see and neither saw it in Bascom used for strings..
I would not use special characters as variable-names unless I know them as save.
Btw., to name a bit var rxdata1 and and a string val rxdata1$ is also not the brightest idea around.
Easier reading and less error-prone it's with self explaining names, for example rx1_data and rx1_received.
If you want to know where's the difference, means why the one works while you state the other does not, you need to provide an original string for rxdata1$.
Then it's possible to find out. |
|
Back to top |
|
|
atmega64
Joined: 23 Feb 2005 Posts: 298 Location: ITALY
|
Posted: Tue Mar 10, 2020 12:58 pm Post subject: |
|
|
Quote: | i would not recommend to work on a variable inside an int and in the main program without disabling interrupts in the main code. |
so I should disable the interrupts before Rxdata2 $ = "" and immediately re-enable them ... right? |
|
Back to top |
|
|
atmega64
Joined: 23 Feb 2005 Posts: 298 Location: ITALY
|
Posted: Tue Mar 10, 2020 2:12 pm Post subject: |
|
|
Quote: | Btw., to name a bit var rxdata1 and and a string val rxdata1$ is also not the brightest idea around.
Easier reading and less error-prone it's with self explaining names, for example rx1_data and rx1_received. |
ok.. |
|
Back to top |
|
|
atmega64
Joined: 23 Feb 2005 Posts: 298 Location: ITALY
|
Posted: Tue Mar 10, 2020 3:28 pm Post subject: |
|
|
I modified the code but always the same problem, that is, it doesn't work with the bascom version 2.0.8.2...
Code: | $regfile = "m1284def.dat"
$crystal = 16000000
$hwstack = 48
$swstack = 40
$framesize = 48
$baud = 19200
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Portb.4 = Output 'BUZZER
Buzzer Alias Portb.4
Declare Sub Bip
On Urxc Rxcom1_isr
Enable Urxc
Open "COM1:" For Binary As #1 'open channel
Dim Rxdata1 As String * 254 , Rxcmd As String * 254 , Id As String * 2
Dim Comchar1 As Byte
Dim Rxdata1end As Bit
Enable Interrupts
'ID DEVICE
Id = "06"
Reset Rxdata1end
Rxdata1 = ""
Bip
Do
If Rxdata1end = 1 Then
Reset Rxdata1end
If Left(Rxdata1 , 1 ) = "[" And Right(Rxdata1 , 1 ) = "]" And Len(Rxdata1) > 5 Then 'comando corretto
If Id = Mid(Rxdata1 , 2 , 2) Then
'Rxcmd = Mid(Rxdata1 , 4 , 2)
Select Case Mid(Rxdata1 , 4 , 2)
Case "GM" : Bip
Waitms 500
Print "OK GM";
Case "GS" : Bip
Waitms 500
Print "OK GS";
Case "SM" : Bip
Waitms 500
Print "OK SM";
End Select
End If
End If
Rxdata1 = ""
End If
Loop
Rxcom1_isr:
Comchar1 = Inkey()
Rxdata1 = Rxdata1 + Chr(comchar1)
If Comchar1 = 93 Then '] the closed square bracket ends command reading
Set Rxdata1end
End If
Return
Sub Bip
Buzzer = 0
Waitms 20
Buzzer = 1
End Sub
End |
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Mar 10, 2020 4:14 pm Post subject: |
|
|
you should also include info about the data you sent.
and if it includes CR , LF or both. _________________ Mark |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Mar 10, 2020 4:28 pm Post subject: |
|
|
i tested with real HW and with the SIM and it works in 2082 as expected.
Code: |
$regfile = "m88def.dat"
$crystal = 8000000
$baud = 19200
$hwstack = 48
$swstack = 40
$framesize = 48
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Portb.4 = Output 'BUZZER
Buzzer Alias Portb.4
Declare Sub Bip
On Urxc Rxcom1_isr
Enable Urxc
Open "COM1:" For Binary As #1 'open channel
Dim Rxdata2$ As String * 254 , Rxcmd As String * 254 , Id As String * 2
Dim Comchar1 As Byte
Dim Rxdata1 As Bit
Enable Interrupts
'ID DEVICE
Id = "06"
Reset Rxdata1
'Rxdata2$ = "[06GM TEST]"
'Bip
Do
If Rxdata1 = 1 Then
Reset Rxdata1
If Left(rxdata2$ , 1 ) = "[" And Right(rxdata2$ , 1 ) = "]" And Len(rxdata2$) > 5 Then 'comando corretto
If Id = Mid(rxdata2$ , 2 , 2) Then
'Rxcmd = Mid(rxdata1$ , 4 , 2)
Select Case Mid(rxdata2$ , 4 , 2)
Case "GM" : Bip
Waitms 500
Print "OK GM";
Case "GS" : Bip
Waitms 500
Print "OK GS";
Case "SM" : Bip
Waitms 500
Print "OK SM";
End Select
End If
End If
Rxdata2$ = ""
End If
Loop
Rxcom1_isr:
Comchar1 = Inkey()
Rxdata2$ = Rxdata2$ + Chr(comchar1)
If Comchar1 = 93 Then '] the closed square bracket ends command reading
Set Rxdata1
End If
Return
Sub Bip
' Buzzer = 0
Waitms 20
' Buzzer = 1
End Sub |
i send the data using the bascom terminal emu. and i get the expected result printed.
i have no idea what you do but judging from the earlier code i have some doubts. _________________ Mark |
|
Back to top |
|
|
atmega64
Joined: 23 Feb 2005 Posts: 298 Location: ITALY
|
Posted: Tue Mar 10, 2020 4:33 pm Post subject: |
|
|
Quote: | you should also include info about the data you sent.
and if it includes CR , LF or both. |
The data I send does not include CR and LF
but I repeat, sending the same data, with the bascom version 2.0.8.1 it works ...
Quote: | you should also include info about the data you sent.
and if it includes CR , LF or both. |
The data I send does not include CR and LF
but I repeat, sending the same data, with the bascom version 2.0.8.1 it works ...
Code: | i have no idea what you do but judging from the earlier code i have some doubts. |
why does the following code make you wonder?
Code: | $regfile = "m1284def.dat"
$crystal = 16000000
$hwstack = 48
$swstack = 40
$framesize = 48
$baud = 19200
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Portb.4 = Output 'BUZZER
Buzzer Alias Portb.4
Declare Sub Bip
On Urxc Rxcom1_isr
Enable Urxc
Open "COM1:" For Binary As #1 'open channel
Dim Rxdata1 As String * 254 , Rxcmd As String * 254 , Id As String * 2
Dim Comchar1 As Byte
Dim Rxdata1end As Bit
Enable Interrupts
'ID DEVICE
Id = "06"
Reset Rxdata1end
Rxdata1 = ""
Bip
Do
If Rxdata1end = 1 Then
Reset Rxdata1end
If Left(Rxdata1 , 1 ) = "[" And Right(Rxdata1 , 1 ) = "]" And Len(Rxdata1) > 5 Then 'comando corretto
If Id = Mid(Rxdata1 , 2 , 2) Then
'Rxcmd = Mid(Rxdata1 , 4 , 2)
Select Case Mid(Rxdata1 , 4 , 2)
Case "GM" : Bip
Waitms 500
Print "OK GM";
Case "GS" : Bip
Waitms 500
Print "OK GS";
Case "SM" : Bip
Waitms 500
Print "OK SM";
End Select
End If
End If
Rxdata1 = ""
End If
Loop
Rxcom1_isr:
Comchar1 = Inkey()
Rxdata1 = Rxdata1 + Chr(comchar1)
If Comchar1 = 93 Then '] the closed square bracket ends command reading
Set Rxdata1end
End If
Return
Sub Bip
Buzzer = 0
Waitms 20
Buzzer = 1
End Sub
End |
|
|
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
|
|