Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Error on com port 2 when acquiring GPS

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
mindstorm

Bascom Member



Joined: 04 Nov 2004
Posts: 11
Location: Singapore

singapore.gif
PostPosted: Fri May 21, 2021 8:54 am    Post subject: Error on com port 2 when acquiring GPS Reply with quote

Hi All

I am playing with Olimex MT128 on a GPS module bought from Aliexpress. It has no issue working with com port 1 and display the GPS time on the LCD. I have problem getting it to work on com port 2. I believe I have made mistake on usage of the Input/Inkey(line 93/94) on port 2 and would greatly appreciate if anyone could help me out.

Thank you very much.

Teo

Bascom version: 2083
Processor: ATMEGA128
Board: Olimex MT128

(BASCOM-AVR version : 2.0.8.3 )
Back to top
View user's profile
i.dobson

Bascom Expert



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

switzerland.gif
PostPosted: Fri May 21, 2021 11:42 am    Post subject: Reply with quote

Hi,

I'm not exactly sure whats wrong with your code, but here's the code I use for com1 & 2

Code:
'--- PC communications serial port --------------------------------------------
Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8
Config Serialout0 = Buffered , Size = 150                                       'Radio serial output buffer
Config Serialin0 = Buffered , Size = 150                                        'Radio serial input buffer
Open "COM1:" For Binary As #1                                                   'Open port PC

'-- Debug ----------------------------------------------------------------------
'-- Hardware
Config Com2 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8
Config Serialout1 = Buffered , Size = 250                                       'Debug serial buffer
Config Serialin1 = Buffered , Size = 50                                         'RFID serial in
Open "COM2:" For Binary As #2                                                   'Open port to RFID
 


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
mindstorm

Bascom Member



Joined: 04 Nov 2004
Posts: 11
Location: Singapore

singapore.gif
PostPosted: Fri May 21, 2021 12:07 pm    Post subject: Reply with quote

Hi Ian

Thanks for looking into my problem.

The error happen around Inkey and Input command

In my com 1 code (working)
A=Inkey()
If A=36 Then Input Gpsdata noecho

In my com 2 code (won't work)
A = Inkey (#2)
If A=36 Then Input #2 Gpsdata noecho

Best Rgds.

Teo
Back to top
View user's profile
i.dobson

Bascom Expert



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

switzerland.gif
PostPosted: Fri May 21, 2021 1:13 pm    Post subject: Reply with quote

Hi,

The inkey command in your example looks OK.

I'm using exactly the same command in my projects, so mybe try using the configuration commands that I included in my first post.

Regards
Ian Dobson




[/code]

_________________
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
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 749

poland.gif
PostPosted: Fri May 21, 2021 11:15 pm    Post subject: Reply with quote

Lets start about enable the Code Explorer... -->View->Enable Code Explorer.
Then Right Click of the Mouse/Touchpad and->Show errrors
I dont know why this is not enabled by default. Tells much here.

look->Code Explorer screaming that this is not correct code or syntax -> " If A = 36 Then Input #2 , Gpsdata Noecho "

Input "hash and the number of channel" is not in the brackets ->this is the first fault I think Very Happy
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5278
Location: Holland

blank.gif
PostPosted: Sat May 22, 2021 1:27 pm    Post subject: Reply with quote

i think the code explorer has a problem since the syntax is ok. i will check that.

well there are many things that can go wrong.
-1 what is the fuse for the processor regarding M103/M128 mode? In case the fuse bytes are not altered use the m128103 dat file. this is a common error.
-2 what kind of hardware you use? how is the second usart connected? and is it actual? did you measure that?
-3 always make a simple as possible piece of code : get rid of the lcd stuff.
-4 make a simple test code which loops like :


Code:
$regfile = "M128def.dat"
$crystal = 11059000
$baud = 9600
$baud1 = 9600

Dim B As Byte
Open "COM1:" For Binary As #2
Do
  B = Inkey(#2)
  If B <> 0 Then
    Print #2 , Chr(b);
  End If
Loop

 


then when it works, just alter COM1 into COM2 in the OPEN statement and test again.

only if that works you can continue.

what i often use :

Code:

Do
  B = Inkey(#1)
  If B <> 0 Then
    Print #1 , Chr(b);
    Print #2 , Chr(b);
  End If

  B = Inkey(#2)                                             'second
  If B <> 0 Then
    Print #1 , Chr(b);
    Print #2 , Chr(b);
  End If
Loop

 


this can test both ports.

ok and then there is the used algo : that is really no good.
just because you read $ does not mean the rest is also there.
a better way is to build up the string when you get the $, then end it when you get the end marker.
only then you know you have a full line of data. you can split() that.

Code:
bFlag=0
if a="$" then
  gpsdata="" clear it
  bFlag=1  'got start
elseif a=SomeENdMarker like 13 or 10 ?
  process here
  bFlag=0 'reset
elseif bflag=1 then 'only when we had a start
  gpsdata=gpsdata+ newchar
end if
 

_________________
Mark
Back to top
View user's profile Visit poster's website
mindstorm

Bascom Member



Joined: 04 Nov 2004
Posts: 11
Location: Singapore

singapore.gif
PostPosted: Sun May 23, 2021 8:34 am    Post subject: Reply with quote

Hi All

Thanks for your input and suggestions.

-1 what is the fuse for the processor regarding M103/M128 mode? In case the fuse bytes are not altered use the m128103 dat file. this is a common error.
It is in M128 mode. I usually programmed it whenever I received a new Atmega128.

-2 what kind of hardware you use? how is the second usart connected? and is it actual? did you measure that?
Olimex MT128. It has uart 2 on a 4 pins molex header(TTL) and also DB9(RS232). Its uart 1 is shared with ICSP so not convenient to use.

-3 always make a simple as possible piece of code : get rid of the lcd stuff.
Yes Sir.

-4 make a simple test code which loops like :
I have tried your first set of code and toggle between com1 and com2. Both codes work and I can see the typed text being echoed back so both uarts Tx and Rx path should be ok.

For Input #2 do I need to type Input (#2)?

Best Rgds.

Teo
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1004
Location: France

france.gif
PostPosted: Sun May 23, 2021 10:33 am    Post subject: Reply with quote

hi
Quote:
For Input #2 do I need to type Input (#2)?


yes
Iuse lineinput to read from a file but is nearly the same
Code:
      Open Filetoread For Input As #ff
      Do
         Lineinput #ff , Sentence                                 ' read a line  line input is used to read a line of text from a file
      Loop Until Eof(ff) <> 0

and it works fine
same with debug
Code:
   Debug #usb , "wage:" ; Wage
where usb is the com port 1 or 2 (thanks EDC Wink )

maybe it is beside your problem but read that https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&p=78289&highlight=#78289
JP Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
mindstorm

Bascom Member



Joined: 04 Nov 2004
Posts: 11
Location: Singapore

singapore.gif
PostPosted: Mon May 24, 2021 10:05 am    Post subject: Reply with quote

Hi All

Thanks for all your inputs and I have implemented all of them into com 1 code and tested it is still working fine. Then I merely switch the text over to com 2 and it still doesn't work. That make it think it could be a hardware issue.

Olimex MT128 has an intermediate point for com 2 in TTL mode, after which it goes thru some transistor logics and converted to DB9(RS232). I tried out Mark's code using this DB9 port. Somehow the GPS with TTL level when feeding into the board has resulted in some issue. I don't have a scope onhand to see the problem but managed to borrow a GPS mouse (RS232) and patch it to the same board's DB9 connector and it works!

Thanks again and I really appreciate all the help from Bascom community. Cheers!

For those who are interested I have attached the amended code and Olimex board infor.

Thank you and best regards,

Teo

https://www.olimex.com/Products/AVR/Development/AVR-MT128/
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5278
Location: Holland

blank.gif
PostPosted: Mon May 24, 2021 10:22 am    Post subject: Reply with quote

ok like i thought : a hardware problem. this board has the tx/rx of the micro connected to the interface hardware. and it would be best if they had used jumpers. but when you do not need a connection to the pc, you could remove r5 and r6.

there is a difference between the tx/rx signals on the processor and the RS232 signals. you best check the help or a wiki.

i would pay attention to my earlier remarks. when you use input you expect that all the data is there. but is it? you only know when you had a start character and an end character.
the input will wait for cr+lf (depending on how you configured). when that does not arrive, the code stops at the input.
with a constant stream of data your code will probably work too.

_________________
Mark
Back to top
View user's profile Visit poster's website
mindstorm

Bascom Member



Joined: 04 Nov 2004
Posts: 11
Location: Singapore

singapore.gif
PostPosted: Mon May 24, 2021 12:00 pm    Post subject: Reply with quote

Hi Mark

I would wish R5 and R6 could be remove easily but they are hidden below the 16pins LCD module. Need a good desoldering iron which I don't have at the moment.

Too bad the GPS board that I bought comes in TTL only as I find the 4 pins header on Olimex which carries a +5V would conveniently power up this GPS board. If no choice need to use DB9 I would have to find another wire to power up a different made GPS board with RS232 output.

No issue with the GPS data, once GPS is on it will flow non stop and I have another ATmega128 using similar code never encounter problem.

Thank you very much.

Teo
Back to top
View user's profile
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 129

blank.gif
PostPosted: Mon May 24, 2021 1:01 pm    Post subject: Reply with quote

Hi
In that case, disconnect pins 27 and 28 of the processor from the PCB (heat and lift with tweezers) and connect RxD and TxD directly.
You don't need any expensive equipment to do this.
RS
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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