View previous topic :: View next topic |
Author |
Message |
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Tue Apr 25, 2006 1:13 pm Post subject: RS232 ? Mega8 |
|
|
Hi All ..
How can I use the rx on the Mega8
Trying to read data send from GSM Phone 19200 baud
cant find the data i recive
I use this as read rx
__________________
Sub Rs232_data
Buf_Rs232 = ""
While _rs_head_ptr0 <> _rs_tail_ptr0
In_Rs232 = Inkey()
If Asc(In_rs232) > 32 Then
Buf_Rs232 = In_Rs232 + In_rs232
End If
Print Buf_Rs232
Wend
End Sub
Is this not for Mega8 ?
anyone got some rs232 tx rx source for M8
:roll: _________________ / Kim |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Tue Apr 25, 2006 3:10 pm Post subject: |
|
|
Hi,
This should work on most AVR's. It just echos back the input.
Code: |
'---[ Define stack space required ]--------------------------------------------
$hwstack = 40 'from the stack analysis
$swstack = 12
$framesize = 24
declare sub Test(byval txt as Byte)
$crystal = 11059200
$regfile = "m32def.dat"
$baud = 9600
Config Serialin = Buffered , Size = 10
Dim Serialchar As Byte
Enable Interrupts
Do
While Ischarwaiting() <> 0
Serialchar = Inkey()
print ;chr(serialchar);
wend
Loop
End
|
Hope this helps
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Tue Apr 25, 2006 4:39 pm Post subject: |
|
|
Hi ..
Tnx for replay ..
still canīt get it to read the rx in to a string
if I do this :
Print "AT" ' send AT to phone get OK back
need to read this data from phone :
Print "AT+CSCA"
the phone send this :
+CSCA: "+4540390999",145
but M8 cant read it
have tryed all sources from forum now no luck
the rx in mega8 wont work but TX is ok _________________ / Kim |
|
Back to top |
|
|
Eugen
Joined: 10 May 2005 Posts: 11
|
Posted: Wed Apr 26, 2006 8:40 am Post subject: |
|
|
Hello,
Just some thoughts:
1) Your source is not correct, but perhaps its only a typo:
Sub Rs232_data
Buf_Rs232 = ""
While _rs_head_ptr0 <> _rs_tail_ptr0
In_Rs232 = Inkey()
If Asc(In_rs232) > 32 Then
Buf_Rs232 = In_Rs232 + In_rs232
------------------------------------------>above line is wrong, must be:
Buf_Rs232 = Buf_Rs232 + In_rs232
End If
Print Buf_Rs232 ---> Perhaps you want the print of the received data after the wend?
Wend
End Sub
2) Are you calling your routine RS232_data frequently? Unlike the print statement, the receiving does need more attention! The Inkey-situation must be polled all the time, as the serial transfer is much slower than the program speed. That means that you will not see data everytime you call the routine. And you can't expect that when exiting the while-wend you have a complete transferred record.
3) You need to decide when the transmit is ready. Typically AT messages from modems (and cellphones) are terminated by CR-LF. or only CR - check the specs. You can take care for both terminations by finalising the buffer after CR has occured and ignoring all LFs.
Hope to help a bit,
Eugen |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Wed Apr 26, 2006 9:44 am Post subject: |
|
|
hi Eugen ..
it was a type O
but cant use (CR) because it send (13) (10) in start and finish like this
in Hex :
0D 0A 4F 4B 0D 0A > 13 10 OK 13 10
0D 0A 4F 4B 0D 0A > 13 10 OK 13 10
0D 0A 2B 43 53 43 41 3A 20 22 2B 34 35 34 30 33 39 30 39 39 39 22 2C 31 34 35 0D 0A > 13 10 +CSCA: "+4540390999",145 13 10
0D 0A 4F 4B 0D 0A > 13 10 OK 13 10
_________________ / Kim |
|
Back to top |
|
|
Eugen
Joined: 10 May 2005 Posts: 11
|
Posted: Wed Apr 26, 2006 11:37 am Post subject: |
|
|
You can still use CR LF as termination recognition, do something like this:
Code: | if Cr then
check if buffer is empty
If buffer empty then
ignore cr, carry on listening to rs232
elseif buffer= OK then
set OK flag or whatever
else
take buffer into received-string and work with received-string
end if
elseif not LF
buffer=buffer + received character
end if
|
Furthermore you can reduce the OK flood with
ATE0 - switches echo off
ATV0 - replaces <13><10>OK<13><10> with 0<13>
if you get 0 then OK, other numbers are errors
Regards,
Eugen |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Wed Apr 26, 2006 8:27 pm Post subject: |
|
|
Hey Eugen ..
have found the problem .
it was stored in the eram not in eeprom thats was my
problem to find it now it works fine
tnx for your help
_________________ / Kim |
|
Back to top |
|
|
|