Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Config for extra UARTS 2560

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

Bascom Member



Joined: 10 Feb 2014
Posts: 74
Location: Melbourne

australia.gif
PostPosted: Thu Nov 07, 2019 5:59 am    Post subject: Config for extra UARTS 2560 Reply with quote

Hi guys,
I'm resurrecting an old GPS project from a few years ago for a different product.

This new project uses UART #3 (the fourth one) as the comms port for the GPS data.
Uart #0 is a comms port to a PC,
Mega 2560 @ 16Mhz
Latest Bascom version

It's a standard gtop013 GPS module @ default 9600 baud - tested, working spitting out nmea sentences.


Below is the main routine...

Code:

$swstack = 1000
$framesize = 1000
$baud = 9600
$baud1 #4 = 9600

Enable Interrupts

Config Submode = New
Config Date = Dmy , Separator = /
Config Clock = Soft
Config Serialin = Buffered , Size = 200
Config Serialin3 = Buffered , Size = 200

Open "COM3:" For binary As #4

wait 1 ' gps booting

$include "gpsroutines.inc"
$include "GpsDeclarations.inc"
$include "gpsroutines.inc"

Do
   Call Getstring()

   F1 = Commapos(2 , Gpgga)       'lat
   F2 = Commapos(3 , Gpgga)       'n/s
   F3 = Commapos(4 , Gpgga)       'lon
   F4 = Commapos(5 , Gpgga)       'e/w
   Sats = Commapos(7 , Gpgga)       ' SATS IN VIEW
   F5 = Commapos(9 , Gpgga)       'altitude
   F6 = Commapos(10 , Gpgga)       'meters
   Timez = Commapos(1 , Gprmc)
   Valid = Commapos(2 , Gprmc)       'A OR V    VALID FIX = A
   F7 = Commapos(7 , Gprmc)       'Speed In Knots
   F8 = Commapos(8 , Gprmc)       'TRACK ANGLE
   Datez = Commapos(9 , Gprmc)

   Latt = Convert(f1 , F2)
   Lon = Convert(f3 , F4)
  ' Dist = 3ddistance( -8.763979 , 115.170276 , Latt , Lon , 1 , 1)
  ' Alarm = Anchor( -8.763979 , 115.170276 , Latt , Lon , P1 , P2)
  'Head = Bearing( -37.819571 , 144.941557 , -33.872817 , 151.222786 )
  'Alarm = 166


 print, valid

Loop

End


Close #4


Below is the routine for parsing the Comm4 data.
the print statements are only there for testing -
ischarwaiting #4 never sees data in the buffer.
I've gone through all the docs, help files, samples etc and tried everything I can think of
but still cant get any comms on #4 (or 3 or 2)

Any help appreciated
Cheers
Simon

Code:

$nocompile
'----------------------------------------------------------------------------------------------------------------------
'----------------------------------------------------------------------------------------------------------------------
'below loads gpgga and gprmc nmea sentances into global variables called as such

Dim Gpgga As String * 80
Dim Gprmc As String * 80

Sub Getstring()
   Local Ggps As String * 5 : Local Gps1 As String * 80  : Local Ch As string*1

'CLEAR BUFFER, LOOPS 'TILL NOTHING LEFT
   While Ischarwaiting (#4) > 0
      Ch = Inkey (#4)
      print " we have data in buffer"         '<-- debug -----this never prints
      Wend

    print "no data in buffer"                        '<-- debug...   this prints


   Ggps = ""          'CLEAR GGPS variable JUST IN CASE
   While Ggps <> "GPGGA"    ' <---------- the sentance we want
      Do
         Ch = Inkey (#4)
      Loop Until Ch = "$"         '<  -------sentance start
      Input #4 , Gps1  Noecho       'GET A FULL SENTENCE  and load in into gps1
      Ggps = Left(gps1 , 5)              'suck out the header and CHECK IT FOR A MATCH  (top of wend)
   Wend

   Gpgga = Gps1

   Ggps = ""          'CLEAR GGPS JUST IN CASE
   While Ggps <> "GPRMC"
      Do
      Ch = Inkey (#4)
      Loop Until Ch = "$"
      Input #4 , Gps1 Noecho       'GET A FULL SENTENCE
      Ggps = Left(gps1 , 5)       'CHECK IT FOR A MATCH, nmea sentance header that is
   Wend
   Gprmc = Gps1

Toggle Togglebit

End Sub

 


(BASCOM-AVR version : 2.0.8.2 )
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Thu Nov 07, 2019 7:46 am    Post subject: Re: Config for extra UARTS 2560 Reply with quote

snipsnip wrote:
Code:
$baud1 #4 = 9600

That's quite creative usage of the baud-directive, do you have any reference of such usage?
Your code hides important stuff within the includes, I suggest to simplify it, so it can be actually checked.
It may as well be that your creativity hinders proper function, if your task would have been to 'complete the row of numbers', and given is: baud = first uart, baud1 = second, then your completion for the fourth one is a failure.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5915
Location: Holland

blank.gif
PostPosted: Thu Nov 07, 2019 9:28 am    Post subject: Reply with quote

look in the help at CONFIG COM. It accepts the baud as parameter.
and when you need to change at run time use BAUD not to be confused with $BAUD

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

Bascom Member



Joined: 10 Feb 2014
Posts: 74
Location: Melbourne

australia.gif
PostPosted: Thu Nov 07, 2019 9:50 am    Post subject: Reply with quote

Thanks guys,

Ive copied the rs232buffer1 file from the samples directory
and moved the GPS input to com 1

but I'm still not getting any input to the serial buffer.

Could it have something to do with the bootloader?
I'll get to the shops tomorrow and pick up a usbasp to try.

Code:
$regfile = "m2560def.dat"                                   ' specify the used micro
$crystal = 16000000                                          ' used crystal frequency
$hwstack = 200                                               ' default use 32 for the hardware stack
$swstack = 200                                               ' default use 10 for the SW stack
$framesize = 40                                             ' default use 40 for the frame space
$baud = 9600

Config Com2 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin1 = Buffered , Size = 200

dim Nm As string*5

Open "com2:" For Binary As #1
Enable Interrupts

Print  "Start"

Do
  If Ischarwaiting(#1) = 1 Then                            'was there a char?
      Nm = inkey(#1)                                      'get it
      Print  Nm                                         'print it
   End If

   Wait 1                                                   'wait 1 second
Loop
Close #1
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5915
Location: Holland

blank.gif
PostPosted: Thu Nov 07, 2019 10:13 am    Post subject: Reply with quote

i dont know which boot loader you use.
i would suggest to start with the m2560.bas sample from the SAMPLES\CHIPS folder.

it uses all 4 com ports.

and otherwise : just make a simple echo program that will echo all back.

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

Bascom Member



Joined: 10 Feb 2014
Posts: 74
Location: Melbourne

australia.gif
PostPosted: Fri Nov 08, 2019 4:50 am    Post subject: Reply with quote

Thanks guys,

Turns out it was the bootloader (arduino)
fuse bits etc.

I've dumped it and it's almost ok now Smile



Cheers
Simon
Back to top
View user's profile
snipsnip

Bascom Member



Joined: 10 Feb 2014
Posts: 74
Location: Melbourne

australia.gif
PostPosted: Fri Nov 08, 2019 5:26 am    Post subject: Re: Config for extra UARTS 2560 Reply with quote

my bad.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5915
Location: Holland

blank.gif
PostPosted: Mon Nov 11, 2019 11:47 am    Post subject: Reply with quote

the help was not very clear. I changed it :

Action
Changes the baud rate for the hardware UART.


Syntax
BAUD = var


Syntax Software UART
BAUD #x , const


Remarks
Var
The baud rate that you want to use.
X
The channel number of the software UART.
Const
A numeric constant for the baud rate that you want to use.


[PICTURE notice.jpg] Do not confuse the BAUD statement with the $BAUD compiler directive.

And do not confuse $CRYSTAL and CRYSTAL

$BAUD overrides the compiler setting for the baud rate while BAUD will change the current baud rate.
So $BAUD is a global project setting in your source code while BAUD will change the baud rate during run time.
You could use BAUD to change the baud rate during run time after the user changes a setting.

BAUD = ... will work on the hardware UART.

BAUD #x, yyyy will work on the software UART.
When you use a software UART and change the baud rate at run time using BAUD, you must set the baud rate after the OPEN statements as well.
When you do not use BAUD, there is no need to set it. So for example :

Open "COMC.1:9600,8,N,1" For Output As #1
print #1 , "this is a test 9600" 'no need for BAUD since 1 baud rate is used

But when BAUD is changed :
Open "COMC.1:9600,8,N,1" For Output As #1
baud #1 , 9600 'we need to set it since we change baud at run time
print #1 , "this is a test 9600"

baud #1 , 115200
print #1 , "this is a test 115200"


and for baudx :

Action
Changes the baud rate for the specified hardware UART.


Syntax
BAUD = var
BAUD1 = var
BAUD2 = var
BAUD3 = var

Syntax Xmega
BAUD = var
BAUD1 = var
BAUD2 = var
BAUD3 = var
BAUD4 = var
BAUD5 = var
BAUD6 = var
BAUD7 = var


Xmega Syntax
BAUDx = constant


Remarks
Var
The baud rate that you want to use.
baud
COM1, USART0, xmega and normal AVR
baud1
COM2, USART1, xmega and normal AVR
baud2
COM2, USART2, xmega and normal AVR
baud3
COM3, USART3, xmega and normal AVR
baud4
COM4, USART4, xmega
baud5
COM5, USART5, xmega
baud6
COM6, USART6, xmega
baud7
COM7, USART7, xmega


Do not confuse the BAUD1 statement with the $BAUD1 compiler directive.

And do not confuse $CRYSTAL and CRYSTAL

$BAUD1 overrides the compiler setting for the baud rate while BAUD1 will change the current baud rate.
BAUD1 = ... will work on the hardware UART.
BAUDn = ... will work on the specified hardware UART.

mega
For the mega, the X represents the UART number. BAUD means, the first UART which you refer to with OPEN as COM1, BAUD1 the second UART, and BAUD3 is the last UART. A channel number is not supported.
You need to use a constant for the baud rate. Variables are not supported.


Xmega
For the xmega, the X represents the UART number. BAUD means, the first UART which you refer to with OPEN as COM1, BAUD1 the second UART, and BAUD7 is the last UART. A channel number is not supported.
For the Xmega you need to use a constant for the baud rate. Variables are not supported.


the help shows this in tables.

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