Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Help _ simple examble for RX UART data
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO
View previous topic :: View next topic  
Author Message
MIKRO_MAN

Bascom Member



Joined: 22 Jan 2015
Posts: 38

PostPosted: Thu Jan 28, 2016 3:11 am    Post subject: Help _ simple examble for RX UART data Reply with quote

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
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1518
Location: Basel, Switzerland

switzerland.gif
PostPosted: Thu Jan 28, 2016 9:20 am    Post subject: Reply with quote

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

_________________
Home of AVRTimer, the Bascom timer value calculator.
http://www.planet-ian.com

Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1107
Location: SYDNEY

australia.gif
PostPosted: Thu Jan 28, 2016 12:27 pm    Post subject: Reply with quote

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
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 827
Location: France

france.gif
PostPosted: Thu Jan 28, 2016 4:01 pm    Post subject: Reply with quote

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
Wink
jp
Back to top
View user's profile Visit poster's website
MIKRO_MAN

Bascom Member



Joined: 22 Jan 2015
Posts: 38

PostPosted: Fri Jan 29, 2016 5:36 pm    Post subject: Reply with quote

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
Wink
jp


i cant understand what is M8 & M2560
??
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 827
Location: France

france.gif
PostPosted: Fri Jan 29, 2016 7:11 pm    Post subject: Reply with quote

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
Wink
jp
Back to top
View user's profile Visit poster's website
MIKRO_MAN

Bascom Member



Joined: 22 Jan 2015
Posts: 38

PostPosted: Fri Jan 29, 2016 7:39 pm    Post subject: Reply with quote

Duval JP wrote:
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
Wink
jp


Ok Thank
i need to know how can i update my code to RX [AAAA] or any statement [string]
by using arduino atmega328p
Code:

$regfile = "m328p.dat"
$crystal = 16000000
'------------------------
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
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Sat Jan 30, 2016 7:59 am    Post subject: Check Weatherstation source Reply with quote

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
View user's profile Visit poster's website
MIKRO_MAN

Bascom Member



Joined: 22 Jan 2015
Posts: 38

PostPosted: Mon Feb 01, 2016 3:35 am    Post subject: Re: Check Weatherstation source Reply with quote

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
View user's profile
MIKRO_MAN

Bascom Member



Joined: 22 Jan 2015
Posts: 38

PostPosted: Mon Feb 01, 2016 3:37 am    Post subject: Re: Check Weatherstation source Reply with quote

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
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Mon Feb 01, 2016 8:07 am    Post subject: Byte and string Reply with quote

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
View user's profile Visit poster's website
MIKRO_MAN

Bascom Member



Joined: 22 Jan 2015
Posts: 38

PostPosted: Fri Feb 12, 2016 7:41 am    Post subject: Re: Byte and string Reply with quote

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
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 827
Location: France

france.gif
PostPosted: Fri Feb 12, 2016 11:38 am    Post subject: Reply with quote

- 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 Wink
Back to top
View user's profile Visit poster's website
MIKRO_MAN

Bascom Member



Joined: 22 Jan 2015
Posts: 38

PostPosted: Fri Feb 12, 2016 12:13 pm    Post subject: Reply with quote

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 Wink




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
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Fri Feb 12, 2016 12:22 pm    Post subject: 1 or 4 Mhz Reply with quote

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
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
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