Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

HSERIN SERIN SERIN2

Status
Not open for further replies.

camerart

Well-Known Member
Hi,

Can anyone tell me the differences between HSERIN SERIN SERIN2 please. I'm trying to interface NMEA data coming in on 1 pin. PIC16F648A in Oshonsoft

I have read that HSERIN means hardware, but what does that actually mean?

Camerart.
 
Hi C,
HSERIN uses the PIC's internal UART module,, SERIN is a software UART
Eric
 
Hi C,
HSERIN uses the PIC's internal UART module,, SERIN is a software UART
Eric
Hi Eric,

I have been reading about them, but I still don't understand how I choose which one?

For example, I've been trying different suggestions on this program. The words in the brackets, always show on the LCD screen, but the data doesn't. What I want is the Longitude, Latitude and altitude for further calculations. There are lots of commented out 'debris' in the program. At the moment I have a GPS module sending out NMEA data to a PIC pin, as it seems like the data is getting read (No MAX 232). Later the pin will have a radio receiver connected to it.
(Hope you don't mind the question expanding:))
Here is the code:

'software UART receives data stream at 4800 baud and when code GGA is detected we capture 42 bytes
'in array a(42) then send these to the PC via hardware UART at 9600 baud

Dim start_code(2) As Byte 'enables scan of the last 3 characters received
Dim a(42) As Byte 'save the data stream we need in here
Dim x As Word
Dim i As Byte
Dim j As Byte
Dim gga As Byte
Dim data As Byte
Dim latdeg As Byte
Dim latmin As Byte
Dim londeg As Byte
Dim lonmin As Byte

Hseropen 9600 'for sending captured string to PC
WaitMs 1000

Hserout "Ready - waiting for an GGA (decimal 71 71 65) - then save 42 bytes ", CrLf, CrLf
'> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >.
Define CONF_WORD = 0x3f41 'XTL
Define CLOCK_FREQUENCY = 4 'Changed from 12
AllDigital

'Define osc 4
CMCON = 7
OPTION_REG.7 = 0 'Enable Pull-Up's
Dim led As Bit 'PORTA.2 'flash per second

Define LCD_DREG = PORTB 'Port for LCD Data
Define LCD_DBIT = 4 'Use upper 4 bits of Port
Define LCD_RSREG = PORTA 'Port for RegisterSelect (RS) bit
Define LCD_RSBIT = 2 'Port Pin for RS bit (pin9)
Define LCD_EREG = PORTA 'Port for Enable (E) bit
Define LCD_EBIT = 4 'Port Pin for E bit (pin7)
Define LCD_BITS = 4 'Using 4-bit bus
Define LCD_LINES = 4 'Using 2 line Display
Define LCD_CHARS = 16 'ADDED
Define LCD_COMMANDUS = 2000 'Command Delay (uS)
Define LCD_DATAUS = 50 'Data Delay (uS)

'Define osc 4
CMCON = 7
OPTION_REG.7 = 0 'Enable Pull-Up's

'Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
TRISA = %00000000
'TRISA.0 = 0 'Pin 17 as SPARE
'TRISA.1 = 0 'Pin 18 as LED
'TRISA.2 = 0 'Pin 1 as RS
'TRISA.3 = 0 'Pin 2 as R/W If Define LCD_READ_BUSY_FLAG = 0 then R/W can be connected to GND.
'TRISA.4 = 0 'Pin 3 as E
'TRISA.5 = 0 'Pin 4 as SPARE
'TRISA.6 = 0 'Pin 16 as XTL clock
'TRISA.7 = 0 'Pin 15 as XTL clock

'port B
TRISB = %01000000
'TRISB.0 = 0 'Pin 6 as SPARE
'TRISB.1 = 1 'Pin 7 as GPS RX
'TRISB.2 = 0 'Pin 8 as Not used wrong voltage TX
'TRISB.3 = 0 'Pin 9 as SPARE
'TRISB.4 = 0 'Pin 10 as LCD D4
'TRISB.5 = 0 'pin 11 as LCD D5
'TRISB.6 = 0 'Pin 12 as LCD D6
'TRISB.7 = 0 'Pin 13 as LCD d6
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<,,,,,
loop:
Toggle led
'move the received bytes up the start_code array
For i = 2 To 1 Step -1
j = i - 1
start_code(i) = start_code(j)
Next i

Serin PORTB.1, 9600, start_code(0)

'if GGA received start to save the data stream in a(42)
If start_code(2) = 71 And start_code(1) = 71 And start_code(0) = 65 Then Goto read_now Else Goto loop

read_now:

For x = 1 To 42
Serin PORTB.1, 9600, a(x)
Next x
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Lcdinit
Lcdout $fe, 1 'Clear Screen
WaitMs 500
For x = 1 To 42
'Lcdout $fe, $80, " GPS Decoder "[[[IF THIS IS IN THE LOOP GPS "DECODER Decoder"]]]
'Lcdout "Value: ", a(x) '*
Lcdout "(", gga, ") = ", latdeg, latmin, londeg, lonmin
Next x
WaitMs 500
'Lcdout $fe, $c0, " RECEIVED ", #latdeg, latmin, londeg, lonmin
WaitMs 2000
Lcdout $fe, 1
Goto loop
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

'Hserout CrLf, "42 characters saved after start code GGA follow", CrLf
'WaitMs 500
'For x = 1 To 42
'Hserout a(x) 'spit the array elements down the rs232 hardware UART
'Next x
'Hserout CrLf, CrLf
'WaitMs 500
'Goto loop
 
Hi,
I have not run your program.... yet.

I would advise you to use the HSERIN [ internal UART] module in your programs.
It will be easier to change the Baud rates etc, while you experiment.

Using the Serin means you will have write and debug all the software timing routines, which will a be pain and you will not gain any timing advantage.

If however, you need two or more RS232 inputs to your PIC, you have to use Hserin and Serin.

Why do you have such long Wait delays in your program.??

E
 
'software UART receives data stream at 4800 baud and when code GGA is detected we capture 42 bytes
'in array a(42) then send these to the PC via hardware UART at 9600 baud

hi,
You state the RXR is 4800 baud, but the program is for 9600 baud.?

loop:
Toggle led_a2
'move the received bytes up the start_code array ; why is this section before you receive any data.??
For i = 2 To 1 Step -1
j = i - 1
start_code(i) = start_code(j)
Next i

Serin PORTB.1, 9600, start_code(0)

'if GGA received start to save the data stream in a(42)
If start_code(2) = 71 And start_code(1) = 71 And start_code(0) = 65 Then; what are the ASCII characters for 71,71,65 .?
Goto read_now
Else
Goto loop
Endif

read_now:
For x = 1 To 42
Serin PORTB.1, 9600, a(x)
Next x
 
Hi,
I have not run your program.... yet.

I would advise you to use the HSERIN [ internal UART] module in your programs.
It will be easier to change the Baud rates etc, while you experiment.

Using the Serin means you will have write and debug all the software timing routines, which will a be pain and you will not gain any timing advantage.

If however, you need two or more RS232 inputs to your PIC, you have to use Hserin and Serin.

Why do you have such long Wait delays in your program.??

E

Hi E, (This is connected to another thread: GPS Data tracker for antenna aiming)

I'm quite limited in programming skills, but I am able to modify existing examples found online, and this program is made from a few cut and pastes .

I doubt I will need more than one input. (Apart from opto feedback later on).

As for 'long Wait delays', they were just cut and pasted.

[I've just read your latest reply. It looks as though I've posted a mess. I'll post an earlier version, that might be less messy]

C.
 
hi,
Please post a complete a GGA string and any other strings you expect on the Serin PORTB.1
E
 
Hi E,

Here's a tidier program, sorry for the first! I've attached a photo of the result in the circuit. Where the '2s' are on the LCD, the numbers change and the indicator LED flashes.

E

'16f684A xtl

Define CONF_WORD = 0x3f41 'XTL
Define CLOCK_FREQUENCY = 4 'Changed from 12
AllDigital

'Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY

TRISA = %00000000
'TRISA.0 = 0 'Pin 17 as RLED
'TRISA.1 = 0 'Pin 18 as SPARE
'TRISA.2 = 0 'Pin 1 as RS
'TRISA.3 = 0 'Pin 2 as R/W If Define LCD_READ_BUSY_FLAG = 0 then R/W can be connected

to GND.
'TRISA.4 = 0 'Pin 3 as E
'TRISA.5 = 0 'Pin 4 as SPARE
'TRISA.6 = 0 'Pin 16 as XTL clock
'TRISA.7 = 0 'Pin 15 as XTL clock

'port B
TRISB = %01000000
'TRISB.0 = 0 'Pin 6 as SPARE
'TRISB.1 = 1 'Pin 7 as GPS RX
'TRISB.2 = 0 'Pin 8 as Not used wrong voltage TX
'TRISB.3 = 0 'Pin 9 as SPARE
'TRISB.4 = 0 'Pin 10 as LCD D4
'TRISB.5 = 0 'pin 11 as LCD D5
'TRISB.6 = 0 'Pin 12 as LCD D6
'TRISB.7 = 0 'Pin 13 as LCD d6

Dim temp1 As Byte
Dim gll As Byte
Dim x As Byte
Dim i As Byte

Define LCD_BITS = 4 'For 4 pins not 8
Define LCD_DREG = PORTB
Define LCD_DBIT = 4 'For 4-7 bits
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 2
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 3
Define LCD_EREG = PORTA
Define LCD_EBIT = 4
Define LCD_READ_BUSY_FLAG = 1 'Possibly connect to ground instead?
Lcdinit

loop:
WaitMs 50
For x = 1 To 10
Serin PORTB.1, 9600, gll, i,
Next x
Lcdcmdout LcdClear
Lcdout "(", gll, ") = ", gll, '#data
Lcdcmdout LcdLine2Home
Lcdout "Value: ", #temp1
Toggle RA1
WaitMs 100
Goto loop
 

Attachments

  • LCD GPS XTL16F648A 280414 1330.jpg
    LCD GPS XTL16F648A 280414 1330.jpg
    284.5 KB · Views: 447
hi,
Please post a complete a GGA string and any other strings you expect on the Serin PORTB.1
E
Hi E,
I will need Latitude, Longitude and Altitude, and are in a GGA sentence.
Cheers, C

$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47

Where:
GGA Global Positioning System Fix Data
123519 Fix taken at 12:35:19 UTC
4807.038,N Latitude 48 deg 07.038' N
01131.000,E Longitude 11 deg 31.000' E
1 Fix quality: 0 = invalid
1 = GPS fix (SPS)
2 = DGPS fix
3 = PPS fix
4 = Real Time Kinematic
5 = Float RTK
6 = estimated (dead reckoning) (2.3 feature)
7 = Manual input mode
8 = Simulation mode
08 Number of satellites being tracked
0.9 Horizontal dilution of position
545.4,M Altitude, Meters, above mean sea level
46.9,M Height of geoid (mean sea level) above WGS84
ellipsoid
(empty field) time in seconds since last DGPS update
(empty field) DGPS station ID number
*47 the checksum data, always begins with *
 
hi C,
I used the '$' to initiate the string test and capture, you will never have two NEMA strings being received at the same instant.

So test for the '$' character, save the whole string, then if required test for the GGA string, if valid process the string
If you only ever expect the $GPGGA section of the transmission on the serial input.?? Then parse out the N , E , M segments of the string

[tell me, where is your actual data string from and does have other string prefixes???]
 
hi C,
I used the '$' to initiate the string test and capture, you will never have two NEMA strings being received at the same instant.

So test for the '$' character, save the whole string, then if required test for the GGA string, if valid process the string
If you only ever expect the $GPGGA section of the transmission on the serial input.?? Then parse out the N , E , M segments of the string

[tell me, where is your actual data string from and does have other string prefixes???]

Hi E,

I've removed the second SERIN.

I'm afraid I don't understand most of your comments: Test for the $.......Test for the GGA string......process the string...................parse out the N, E, M segments, sorry!

I think each object (satellite etc) might send different strings, that the receiving program filters out which one is needed, but I'm not sure.

For NMEA information here is a good source: http://aprs.gids.nl/nmea/

C.
 
Hi,
Looking at your application, I would do it this way.

Use the internal UART to read the NMEA string.

Set the Hserin, UART to Interrupt on receiving a character, go to to ISR [intr service routine], IF the Character is $ then read the remainder of the string into a buffer array.
IF the Buffer string has the prefix GPGGA then its the one you want.

IIRC the string terminated with a CR LF code.??

Once you have the full string, look at the Index Pointer of your buffer array to find the Nnnnnn, Eeeeee and Mmmm values and then process them.

You can use the TX output of the Hserout to talk to your PC

E
 
Hi,
Looking at your application, I would do it this way.

Use the internal UART to read the NMEA string.

Set the Hserin, UART to Interrupt on receiving a character, go to to ISR [intr service routine], IF the Character is $ then read the remainder of the string into a buffer array.
IF the Buffer string has the prefix GPGGA then its the one you want.

IIRC the string terminated with a CR LF code.??

Once you have the full string, look at the Index Pointer of your buffer array to find the Nnnnnn, Eeeeee and Mmmm values and then process them.

You can use the TX output of the Hserout to talk to your PC

E

E,
Ok, thanks. I'll work through it.

I took the choice to program the PIC then test it in the circuit, but you mention "talk to your computer" Can you clarify please, apart from the programming, how much of what you suggest is done on the computer?

C
 
'software UART receives data stream at 4800 baud and when code GGA is detected we capture 42 bytes
'in array a(42) then send these to the PC via hardware UART at 9600 baud
C
I was just repeating what you planned to do, ie;then send these to the PC via hardware UART at 9600 baud

So hardware UART reads the incoming data and the same UART sends the data to the PC
E
 
C
I was just repeating what you planned to do, ie;then send these to the PC via hardware UART at 9600 baud

So hardware UART reads the incoming data and the same UART sends the data to the PC
E
C
I was just repeating what you planned to do, ie;then send these to the PC via hardware UART at 9600 baud

So hardware UART reads the incoming data and the same UART sends the data to the PC
E
Hi E,

I'm managing to confuse you as well as myself, with my way of working. I'm not good at programming, so I find examples, then copy and paste them into my program to see the results. The sentence; 'then send these to the PC via hardware UART at 9600 baud' was pasted into my program and commented out.

Sorry for the confusion!

I'll try and re-write my program, in a better way, and try to incorporate your suggestions as best as I can then post it again.

Thanks, C.
 
hi C,
Dont worry about confusion, we all get that way at sometime.;)

Post your code when ready

E
 
hi C,
Dont worry about confusion, we all get that way at sometime.;)

Post your code when ready

E

Hi E,
Ok, here's today's effort!

I can watch the correct sentence starting with $GPGGA, on the SIM RX shift reg, RX buffer1 and RX buffer2, then it appears on the LCD in DEC form (I have to use a conversion sheet to check)

It doesn't work in the circuit, nothing appears.

I haven't found the ISR or understand your comment 'IIRC the string serminated with a CD LF code' or understand how to look at the index pointer of the buffer array. Unless this is if it is inputed to a PC. If this is necessary I will set it up!

C
'GPS LCD XTL 16f684A GGA

Define CONF_WORD = 0x3f41 'XTL
Define CLOCK_FREQUENCY = 4
Define LCD_BITS = 4 'For 4 pins not 8
Define LCD_DREG = PORTB
Define LCD_DBIT = 4 'For 4-7 bits
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 2
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 3
Define LCD_EREG = PORTA
Define LCD_EBIT = 4
Define LCD_READ_BUSY_FLAG = 1 'Possibly connect to ground instead?
Lcdinit
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<,
'Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'Define PIE1 = $00100000
AllDigital
Hseropen 9600

TRISA = %00000000
'TRISA.0 = 0 'Pin 17 as RLED
'TRISA.1 = 0 'Pin 18 as SPARE
'TRISA.2 = 0 'Pin 1 as RS
'TRISA.3 = 0 'Pin 2 as R/W If Define LCD_READ_BUSY_FLAG = 0 then R/W can be connected to GND.
'TRISA.4 = 0 'Pin 3 as E
'TRISA.5 = 0 'Pin 4 as SPARE
'TRISA.6 = 0 'Pin 16 as XTL clock
'TRISA.7 = 0 'Pin 15 as XTL clock

'port B
TRISB = %01000000
'TRISB.0 = 0 'Pin 6 as SPARE
'TRISB.1 = 1 'Pin 7 as GPS RX
'TRISB.2 = 0 'Pin 8 as Not used wrong voltage TX
'TRISB.3 = 0 'Pin 9 as SPARE
'TRISB.4 = 0 'Pin 10 as LCD D4
'TRISB.5 = 0 'pin 11 as LCD D5
'TRISB.6 = 0 'Pin 12 as LCD D6
'TRISB.7 = 0 'Pin 13 as LCD d6

Dim x As Byte
Dim i As Byte
'Dim lon As Byte
'Dim lat As Byte

'$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
loop:
WaitMs 50
For x = 1 To 65
Hserin i,
Lcdout #i,
Lcdcmdout LcdClear
Next x
Toggle RA1
WaitMs 100
Goto loop
 
hi C,
I have a draft program working using RX interrupts to capture the string into a buffer, I will post when its debugged.

If you are using the Hardware UART TOOL in the IDE, are you aware that you can Copy and Paste the $GPGGA.......... string into the UART text box.??
If you want to send the Line Feed Code at the end of the string you have to send 0A using the Send Hex... its a pain.
E

EDIT: Dont use # hash sign in front it will turn it into a Decimal!!
 
hi C,
Try this.
NOTE : I have terminated the string with a '?' character as a temporary substitute for the LF [ saves using the send hex]

Copy the string shown at the Top of the program and Paste it into the UART Send String Box, DONT include the Rem at the start.

I have left some of your Dim's statements in, needs a tidy up.

Code:
'software uart receives data stream at 4800 baud And when code gga is detected we capture 42 bytes
'in array a(42) then send these to the PC via hardware UART at 9600 baud

'COPY and PASTE this string.
'$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47?


Define SIMULATION_WAITMS_VALUE = 1

Dim chr As Byte
Dim rxi As Byte
Dim txi As Byte
Dim start_code(2) As Byte  'enables scan of the last 3 characters received

Dim str1(42) As Byte  'save the data stream we need in here


Dim i As Byte
Dim j As Byte
Dim gga As Byte
Dim data As Byte
Dim latdeg As Byte
Dim latmin As Byte
Dim londeg As Byte
Dim lonmin As Byte

'> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >.
Define CONF_WORD = 0x3f41  'XTL
Define CLOCK_FREQUENCY = 4  'Changed from 12
AllDigital

'Define osc 4
CMCON = 7
OPTION_REG.7 = 0  'Enable Pull-Up's
Dim led_a2 As Bit  'PORTA.2 'flash per second

Define LCD_DREG = PORTB  'Port for LCD Data
Define LCD_DBIT = 4  'Use upper 4 bits of Port
Define LCD_RSREG = PORTA  'Port for RegisterSelect (RS) bit
Define LCD_RSBIT = 2  'Port Pin for RS bit (pin9)
Define LCD_EREG = PORTA  'Port for Enable (E) bit
Define LCD_EBIT = 4  'Port Pin for E bit (pin7)
Define LCD_BITS = 4  'Using 4-bit bus
Define LCD_LINES = 4  'Using 2 line Display
Define LCD_CHARS = 16  'ADDED
Define LCD_COMMANDUS = 2000  'Command Delay (uS)
Define LCD_DATAUS = 50  'Data Delay (uS)

'Define osc 4
CMCON = 7
OPTION_REG.7 = 0  'Enable Pull-Up's

TRISA = %00000000
TRISB = %01000000

'$GGA 1234
Lcdinit


Hseropen 9600

INTCON.GIE = 1
INTCON.PEIE = 1
PIE1.RCIE = 1

Hserout "Ready - await  $", CrLf, CrLf

main:

Goto main

End                                              

On Interrupt
Save System

PIR1.RCIF = 0

Hserin chr
If chr = "$" Then ' test for string start
rxi = 0
Endif

str1(rxi) = chr
rxi = rxi + 1

If chr = "?" Then 'test for temporary LF code
For txi = 0 To rxi
Hserout str1(txi)
If str1(txi) = "," Then Hserout CrLf  ' a demo on how to break the string into chunks.!
Next txi

Endif

Resume
 

Attachments

  • AAesp01.gif
    AAesp01.gif
    15.6 KB · Views: 383
Hi,
This is a revised ISR, it uses the string location to pick off the N,E and M data

Code:
On Interrupt
Save System

PIR1.RCIF = 0

Hserin chr
If chr = "$" Then 'start 
rxi = 0
Endif

str1(rxi) = chr
rxi = rxi + 1

If chr = "?" Then 'temp LF
For txi = 14 To 23
Hserout str1(txi)
Next txi
Hserout CrLf

For txi = 25 To 35
Hserout str1(txi)
Next txi
Hserout CrLf

For txi = 46 To 52
Hserout str1(txi)
Next txi
Hserout CrLf
Endif

Resume
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top