Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

RS232 ? Mega8

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Tue Apr 25, 2006 1:13 pm    Post subject: RS232 ? Mega8 Reply with quote

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
View user's profile Visit poster's website MSN Messenger
i.dobson

Bascom Expert



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

switzerland.gif
PostPosted: Tue Apr 25, 2006 3:10 pm    Post subject: Reply with quote

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

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Tue Apr 25, 2006 4:39 pm    Post subject: Reply with quote

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

Bascom Member



Joined: 10 May 2005
Posts: 11

PostPosted: Wed Apr 26, 2006 8:40 am    Post subject: Reply with quote

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

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Wed Apr 26, 2006 9:44 am    Post subject: Reply with quote

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

Shocked

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
Eugen

Bascom Member



Joined: 10 May 2005
Posts: 11

PostPosted: Wed Apr 26, 2006 11:37 am    Post subject: Reply with quote

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

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Wed Apr 26, 2006 8:27 pm    Post subject: Reply with quote

Hey Eugen .. Very Happy
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

Razz

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive 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