View previous topic :: View next topic |
Author |
Message |
MIKRO_MAN
Joined: 22 Jan 2015 Posts: 38
|
Posted: Thu Jan 28, 2016 3:11 am Post subject: Help _ simple examble for RX UART data |
|
|
i have simple example for rx data (uart)
when i rx one chr like A OR B OR ANY NUMBER 1,2,3.....9 code is working
but when i rx statement code not work
problem _ the code not work what is the worng ?
Code: |
$regfile = "m8def.dat"
$crystal = 4000000
'------------------------
Dim Value As Byte
Config Portb.0 = Input
Config Portb.1 = Output
Portb.1 = 0
Portb.0 = 1
'------------------------
Open "comd.6:9600,8,n,1" For Output As #6
Open "comd.7:9600,8,n,1" For Input As #5
'------------------------
Do
'tx value
Value = Inkey(#5)
A = Inkey()
If Value > 0 Then
If Value = "AAAA" Then Toggle Portb.1
End If
Loop
|
|
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1571 Location: Basel, Switzerland
|
Posted: Thu Jan 28, 2016 9:20 am Post subject: |
|
|
Hello,
If I understand you correctly:
inkey does that, it returns 1 key press (character) from the serial port (not a string of characters.)
You have defined "value" as a byte which can only hold 1 character.
Have a look at the input command (which returns a string), or you need to use inkey in a loop grabbing the individual characters from the serial port and adding then to a string.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Thu Jan 28, 2016 12:27 pm Post subject: |
|
|
The way I do this is..
You see we get a character from the buffer
look at it
decide what it is maybe end of command
or add it to the string
Regards Paul
Code: |
Config Portb.0 = Input
Config Portb.1 = Output
Portb.1 = 0
Portb.0 = 1
'------------------------
Open "comd.6:9600,8,n,1" For Output As #6
Open "comd.7:9600,8,n,1" For Input As #5
'------------------------
Dim Uart_command as string * 20 "room for 20 characters
Dim Rs232 as string * 1
Do
If Ischarwaiting(#5) = 1 Then
Rs232 = Inkey(#5) 'get a character from the buffer
If Rs232 = 13 Or Len(uart_command) > 19 Then 'uart_command full or enter key sent
Delchars Uart_command ,(13)
if Uart_command ="AAA" then
Toggle Portb.1
End If
Uart_command = ""
'--------------------
' we can use this Exit Do to continue to the next part of our program
' Exit Do
Else
Uart_command = Uart_command + Chr(rs232) 'add the character to the uart_command buffer
End If
End If
Loop
End
|
|
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Thu Jan 28, 2016 4:01 pm Post subject: |
|
|
paul,
in the help :
Quote: |
IsCharWaiting can NOT be used with a software uart (SW-UART). This because a SW-UART does not buffer the data is receives or sends.
|
it seems Mikro_man use a M8, afaik M8 as only one Hw -uart DO D1
if he wants more HW-UART he needs to use a bigger one as M2560
jp |
|
Back to top |
|
|
MIKRO_MAN
Joined: 22 Jan 2015 Posts: 38
|
Posted: Fri Jan 29, 2016 5:36 pm Post subject: |
|
|
Duval JP wrote: | paul,
in the help :
Quote: |
IsCharWaiting can NOT be used with a software uart (SW-UART). This because a SW-UART does not buffer the data is receives or sends.
|
it seems Mikro_man use a M8, afaik M8 as only one Hw -uart DO D1
if he wants more HW-UART he needs to use a bigger one as M2560
jp |
i cant understand what is M8 & M2560
?? |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Fri Jan 29, 2016 7:11 pm Post subject: |
|
|
Quote: |
$regfile = "m8def.dat"
$crystal = 4000000
'------------------------
|
M8 means atmega 8
M2560 means ATMEGA 2560
Arduino use ATMEGA328 or ATMEGA2560 for the arduino usable with BASCOM
jp |
|
Back to top |
|
|
MIKRO_MAN
Joined: 22 Jan 2015 Posts: 38
|
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Sat Jan 30, 2016 7:59 am Post subject: Check Weatherstation source |
|
|
In this forum check Bascom Project Blog, and get the source code of the weatherstation. In it a routine for the Arduino Mega with just what you want. Below the inkey part. There is checked on all kind of keywords like "temperature=" and "humidity=".
Must do the trick..
Have fun
Ben Zijlstra |
|
Back to top |
|
|
MIKRO_MAN
Joined: 22 Jan 2015 Posts: 38
|
Posted: Mon Feb 01, 2016 3:35 am Post subject: Re: Check Weatherstation source |
|
|
bzijlstra wrote: | In this forum check Bascom Project Blog, and get the source code of the weatherstation. In it a routine for the Arduino Mega with just what you want. Below the inkey part. There is checked on all kind of keywords like "temperature=" and "humidity=".
Must do the trick..
Have fun
Ben Zijlstra |
i find weatherstation
but i cant understand how can i rx string to uart
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=13038 |
|
Back to top |
|
|
MIKRO_MAN
Joined: 22 Jan 2015 Posts: 38
|
Posted: Mon Feb 01, 2016 3:37 am Post subject: Re: Check Weatherstation source |
|
|
bzijlstra wrote: | In this forum check Bascom Project Blog, and get the source code of the weatherstation. In it a routine for the Arduino Mega with just what you want. Below the inkey part. There is checked on all kind of keywords like "temperature=" and "humidity=".
Must do the trick..
Have fun
Ben Zijlstra |
i find weatherstation
but i cant understand how can i rx string to uart
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=13038 |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Mon Feb 01, 2016 8:07 am Post subject: Byte and string |
|
|
What I don't understand is how you Dim value as byte and later on check if value = "AAA" A byte is a value of 0 - 255. What you need is a string to hold the characters.
You first have to grab all incoming characters in a string and check the string for "AAA"
In the weatherstation that is done. Inkey to check for a character, add it to a string and with instr a check is done if some keywords are in the string.
You are nearly there...
Have fun
Ben Zijlstra |
|
Back to top |
|
|
MIKRO_MAN
Joined: 22 Jan 2015 Posts: 38
|
Posted: Fri Feb 12, 2016 7:41 am Post subject: Re: Byte and string |
|
|
bzijlstra wrote: | What I don't understand is how you Dim value as byte and later on check if value = "AAA" A byte is a value of 0 - 255. What you need is a string to hold the characters.
You first have to grab all incoming characters in a string and check the string for "AAA"
In the weatherstation that is done. Inkey to check for a character, add it to a string and with instr a check is done if some keywords are in the string.
You are nearly there...
Have fun
Ben Zijlstra |
atmega8 _ 1
Code: |
$regfile = "m8def.dat"
$crystal = 4000000
'------------------------
Dim Value As String*6
Config Portb.0 = Input
Config Portb.1 = Output
Portb.1 = 0
Portb.0 = 1
'------------------------
Open "comd.6:9600,8,n,1" For Output As #6
Open "comd.7:9600,8,n,1" For Input As #5
'------------------------
Do
Value = Inkey(#5)
If Value > 0 Then
If Value = "AA" Then Toggle Portb.1
End If
'----------------
'recived value
If Pinb.0 = 0 Then
Print #6 , "AA"
Waitms 100
End If
Loop
|
atmega8 _2
Code: |
$regfile = "m8def.dat"
$crystal = 4000000
'------------------------
'Ucsrb = 0
Dim Value As String*6
Config Portb.0 = Input
Config Portb.1 = Output
Portb.1 = 0
Portb.0 = 1
'------------------------
Open "comd.6:9600,8,n,1" For Output As #5
Open "comd.7:9600,8,n,1" For Input As #6
'------------------------
Do
Value = Inkey(#6)
If Value > 0 Then
If Value = "AA" Then Toggle Portb.1
End If
'----------------
'recived value
If Pinb.0 = 0 Then
Print #5 , "AA"
Waitms 100
End If
Loop
|
the circuit and code NOT WORKING ???
i hope to update this code to working |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Fri Feb 12, 2016 11:38 am Post subject: |
|
|
- I'm sorry but I don't understand why you don't use PD.O and PD1 the hard serial pin for your communication.? on your schematic they are free...
- sometimes serial communications are difficult to adjust because following the sentence you print you have CR+LF
see the help :
Quote: | You can use a semicolon ( ; ) to print multiple variables or constants after each other.
When you end a line with a semicolon, no linefeed and carriage return will be added.
|
so Quote: | If Value = "AA" Then Toggle Portb.1 | while never right be cause, in fact you send AA+CR+LF
- split you program in small parts, then try them, use simulator, it works well
JP |
|
Back to top |
|
|
MIKRO_MAN
Joined: 22 Jan 2015 Posts: 38
|
Posted: Fri Feb 12, 2016 12:13 pm Post subject: |
|
|
Duval JP wrote: | - I'm sorry but I don't understand why you don't use PD.O and PD1 the hard serial pin for your communication.? on your schematic they are free...
- sometimes serial communications are difficult to adjust because following the sentence you print you have CR+LF
see the help :
Quote: | You can use a semicolon ( ; ) to print multiple variables or constants after each other.
When you end a line with a semicolon, no linefeed and carriage return will be added.
|
so Quote: | If Value = "AA" Then Toggle Portb.1 | while never right be cause, in fact you send AA+CR+LF
- split you program in small parts, then try them, use simulator, it works well
JP |
ok i already use PD0 PD1 in another project _ this circuit for explanation simply what I want
i cant understand [ in fact you send AA+CR+LF ]
?? |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Fri Feb 12, 2016 12:22 pm Post subject: 1 or 4 Mhz |
|
|
From the factory the ATmega8 comes with its CKSEL fuses programmed for 1 Mhz.
What about your fusebit settings?
You got an atmega8 and a LED. Is it possible to write a small program to just blink the LED at an interval of 1 second?
And if you Print "AA" you are sending AA+CR+LF
If you just want to send "AA" you do a Print "AA";
Ben Zijlstra |
|
Back to top |
|
|
|