SERIN2 = ok, HSERIN = no!


Closed Thread
Results 1 to 29 of 29
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891

    Default SERIN2 = ok, HSERIN = no!

    Hello,

    I need some help to understand and make my two codes work.

    I'm reading serial data from a GPS module connected directly (no level shifter / no MAX232) to my PIC18F2420.

    As it works fine in a common serial way using SERIN2 command, the same adapted to EUART code won't work. In the HSERIN version, the program will stuck at the HSERIN command.

    I've put both code versions herunder.

    What am I doing wrong in code HSERIN?



    SERIN2 working
    Code:
    'Config Directive settings for MPASM (fuses) for 18F2420
    @ __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    @ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_OFF_2L & _BORV_0_2L
    @ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_1_2H
    @ __CONFIG _CONFIG3H, _MCLRE_OFF_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_PORTBE_3H
    @ __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    @ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
    @ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    @ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
    @ __CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
    @ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
    @ __CONFIG _CONFIG7H, _EBTRB_OFF_7H & _DEVID1 & _IDLOC0
     
    'Registers
    ADCON1  = %00001111  'Turn off all AD's (= "_PBADEN_OFF_3H")        
    TRISC   = %10000000  'GPS module's TX
     
    '-------------------------------------------------------------------------------
    ' DEFINEs
    DEFINE OSC 8
     
    DEFINE LCD_DREG PORTB  'LCD data port 
    DEFINE LCD_DBIT 0      'LCD data starting PORT.bit (0 or 4)
    DEFINE LCD_RSREG PORTB 'LCD register select port 
    DEFINE LCD_RSBIT 4     'LCD register select bit 
    DEFINE LCD_EREG PORTB  'LCD enable port 
    DEFINE LCD_EBIT 5      'LCD enable bit 
    DEFINE LCD_BITS 4      'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2     'Number lines on LCD 
     
    '-------------------------------------------------------------------------------
    INIT:
    GPS_D     VAR BYTE(80)  'Incomming data bit array
    LED0      VAR PORTA.5   'alive LED
    GPSfrom   VAR PORTC.7   'serial data FROM GPS module
    GPSto     VAR PORTC.6   'serial data TO GPS module
    GPSbps    VAR WORD      'GPS module's baudrate
    GPSbps    = 32852       'Open,True,N,9600bps (TTL level)
     
    '-------------------------------------------------------------------------------
    ' DOGM LCD display specific settings
    PAUSE 1000              'Time to settle Vdd
    LCDOUT $FE, $29         'Function Set: 4 bits bus mode
    LCDOUT $FE, $1C         'Bias set
    LCDOUT $FE, $52         'Power control + Contrast (HiByte)(for 5V=$52/3,3V=55)
    LCDOUT $FE, $69         'Follower control  (5V=$69/3,3V=6D)
    LCDOUT $FE, $78         'Contrast (LowByte)
     
    '-------------------------------------------------------------------------------
    ' Main loop
     
    LCDOUT $FE,2,"SERIN2"
     
    MAIN:
     
      SERIN2 GPSfrom,GPSbps,[WAIT("$GPGGA,"),STR GPS_D\6]
      
      LCDOUT $FE,2,GPS_D(0),GPS_D(1),":",GPS_D(2),GPS_D(3),":",GPS_D(4),GPS_D(5)
      
      TOGGLE LED0
     
      GOTO MAIN:


    HSERIN not working
    Code:
    'Config Directive settings for MPASM (fuses) for 18F2420
    @ __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H ;_OSC_INTIO7_1H
    @ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_OFF_2L & _BORV_0_2L
    @ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_1_2H
    @ __CONFIG _CONFIG3H, _MCLRE_OFF_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_PORTBE_3H
    @ __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    @ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
    @ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    @ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
    @ __CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
    @ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
    @ __CONFIG _CONFIG7H, _EBTRB_OFF_7H & _DEVID1 & _IDLOC0
     
    'Registers
    ADCON1  = %00001111     'Turn off all AD's (= "_PBADEN_OFF_3H")        
    TRISC   = %11000000     'stated by DS(!)
    RCSTA   = %10010010     'enable serial port, enable continuous receive, automatic clear overrun error
    TXSTA   = %00100000     'enable transmit, BRGH=0
    SPBRG   = 51            '9600 Baud @ 8MHz, 0.16%
    SPBRGH  = 0
    BAUDCON = %01001000
     
    '-------------------------------------------------------------------------------
    ' DEFINEs
    DEFINE OSC 8
     
    DEFINE LCD_DREG PORTB   'LCD data port 
    DEFINE LCD_DBIT 0       'LCD data starting PORT.bit (0 or 4)
    DEFINE LCD_RSREG PORTB  'LCD register select port 
    DEFINE LCD_RSBIT 4      'LCD register select bit 
    DEFINE LCD_EREG PORTB   'LCD enable port 
    DEFINE LCD_EBIT 5       'LCD enable bit 
    DEFINE LCD_BITS 4       'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2      'Number lines on LCD 
     
    '-------------------------------------------------------------------------------
    INIT:
    GPS_D     VAR BYTE(80)  'Incomming data bit array
    LED0      VAR PORTA.5   'alive LED
     
    '-------------------------------------------------------------------------------
    ' DOGM LCD display specific settings
    PAUSE 1000              'Time to settle Vdd
    LCDOUT $FE, $29         'Function Set: 4 bits bus mode
    LCDOUT $FE, $1C         'Bias set
    LCDOUT $FE, $52         'Power control + Contrast (HiByte)(for 5V=$52/3,3V=55)
    LCDOUT $FE, $69         'Follower control  (5V=$69/3,3V=6D)
    LCDOUT $FE, $78         'Contrast (LowByte)
     
    '-------------------------------------------------------------------------------
    ' Main loop
    LCDOUT $FE,2,"HSERIN"
     
    MAIN:
      HSERIN [WAIT("$GPGGA,"),STR GPS_D\6]
     
      LCDOUT $FE,2,GPS_D(0),GPS_D(1),":",GPS_D(2),GPS_D(3),":",GPS_D(4),GPS_D(5)
      
      TOGGLE LED0
     
      GOTO MAIN:
    Roger

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    EDIT: Your baud looks good.

    At first I didn't see your BRG16 =1, but Steves Picmulticalc is still good. I'll see if I can find anything real

    Steves PicMultiCalc tool works great for this, and give you text results you can just paste in to your code. Just enter OSC speed, baudrate, and press the go button.

    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 12 ' 9600 Baud @ 8MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically


    http://www.picbasic.co.uk/forum/cont....-PICMultiCalc
    Last edited by ScaleRobotics; - 20th March 2012 at 14:21.
    http://www.scalerobotics.com

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    ... I used PICMulticalc and pasted its results in my first post's HSERIN code; unfortunately it doesn't work.
    Roger

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Could it be hardware related? Pull-up or current-limitting resistors?

    What about the Mode setting (True VS Inverted)?

    Robert


    EDIT: You use Open,True,N,9600bps for SERIN, that's inverted.

    You use BAUDCON = %01001000 for HSERIN, bit 5, 0 = non-inverted Data/Receive Polarity.


    There could be other stuff, but that's all I got.
    Last edited by Demon; - 20th March 2012 at 15:26.

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Hi Demon,

    I tried all that already. Neither a new chip nor data polarity will change anything; HSERIN won't work...while SERIN2 does :-/
    Roger

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    BAUDCON bit 3

    BRG16: 16-Bit Baud Rate Register Enable bit
    1 = 16-bit Baud Rate Generator – SPBRGH and SPBRG
    0 = 8-bit Baud Rate Generator – SPBRG only (Compatible mode), SPBRGH value ignored

    Don't you want 8-bit?

    Robert
    Last edited by Demon; - 20th March 2012 at 16:27. Reason: Removed unnecessary stuff
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    I tried BAUDCON = %10000000 if this is what you mean. No luck either.
    Roger

  8. #8
    Join Date
    Oct 2011
    Posts
    54


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    According to datasheet table 18-1 Baud rate formulas

    BRGH = 0 baud rate formula Fosc/[64(n+1)]

    BRGH = 1 baud rate formula Fosc/[16(n+1)]

    You appear to be using the formula for BRGH = 1 while setting BRGH = 0
    I think you should try setting BRGH to 1

    Phil

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    I think BAUDCON should be ... %00111000 for inverted levels and BRG16.
    DT

  10. #10
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    ...still not working.

    Just to make sure I'm not wrong with the ports: I use PIC18F2420's PORTC.7 as RX. This means, the TX pin from the GPS module is connected to PORTC.7.

    Here's the code again:
    Code:
    'Config Directive settings for MPASM (fuses) for 18F2420
    @ __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H ;_OSC_INTIO7_1H
    @ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_OFF_2L & _BORV_0_2L
    @ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_1_2H
    @ __CONFIG _CONFIG3H, _MCLRE_OFF_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_PORTBE_3H
    @ __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    @ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
    @ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    @ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
    @ __CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
    @ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
    @ __CONFIG _CONFIG7H, _EBTRB_OFF_7H & _DEVID1 & _IDLOC0
     
    'Registers
    ADCON1  = %00001111     'Turn off all AD's (= "_PBADEN_OFF_3H")        
    TRISC   = %11000000     'stated by DS(!)
    RCSTA   = %10010010     'enable serial port, enable continuous receive, automatic clear overrun error
    TXSTA   = %00100000     'enable transmit, BRGH=0
    SPBRG   = 51            '9600 Baud @ 8MHz, 0.16%
    SPBRGH  = 0
    BAUDCON = %00111000
     
    '-------------------------------------------------------------------------------
    ' DEFINEs
    DEFINE OSC 8
     
    DEFINE LCD_DREG PORTB   'LCD data port 
    DEFINE LCD_DBIT 0       'LCD data starting PORT.bit (0 or 4)
    DEFINE LCD_RSREG PORTC  'LCD register select port 
    DEFINE LCD_RSBIT 4      'LCD register select bit 
    DEFINE LCD_EREG PORTC   'LCD enable port 
    DEFINE LCD_EBIT 5       'LCD enable bit 
    DEFINE LCD_BITS 4       'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2      'Number lines on LCD 
     
    '-------------------------------------------------------------------------------
    INIT:
    GPS_D     VAR BYTE(80)  'Incomming data bit array
    LED0      VAR PORTA.5   'alive LED
     
    '-------------------------------------------------------------------------------
    ' DOGM LCD display specific settings
    PAUSE 1000              'Time to settle Vdd
    LCDOUT $FE, $29         'Function Set: 4 bits bus mode
    LCDOUT $FE, $1C         'Bias set
    LCDOUT $FE, $52         'Power control + Contrast (HiByte)(for 5V=$52/3,3V=55)
    LCDOUT $FE, $69         'Follower control  (5V=$69/3,3V=6D)
    LCDOUT $FE, $78         'Contrast (LowByte)
     
    '-------------------------------------------------------------------------------
    ' Main loop
     
    LCDOUT $FE,2,"HSERIN"
     
    MAIN:
     
      HSERIN [WAIT("$GPGGA,"),STR GPS_D\6]
     
      LCDOUT $FE,2,GPS_D(0),GPS_D(1),":",GPS_D(2),GPS_D(3),":",GPS_D(4),GPS_D(5)
      
      TOGGLE LED0
    
      GOTO MAIN:
    Roger

  11. #11
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    If I remove the WAIT modifier following the HSERIN command, I will receive data and see it.

    But, just if I would have a wrong setting (i.e. wrong baudrate or polarity), I get strange characters on the LDC display.

    What's the missing/wrong setting....
    Roger

  12. #12
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Finally I made it work by using a MAX232 between the GPS module and the PIC.

    My conclusion is that the use of USART (HSERIN/HSEROUT) will set higher and lower voltage thresholds on the PIC's pins as it does when using "simple" serial communication via SERIN/SEROUT commands. Couldn't find anything about that in the DS...or am I blind?

    I go back to SERIN2 and its reduced number of components application


    The "working" code is:
    Code:
    'Config Directive settings for MPASM (fuses) for 18F2420
    @ __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H ;_OSC_INTIO7_1H
    @ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_OFF_2L & _BORV_0_2L
    @ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_1_2H
    @ __CONFIG _CONFIG3H, _MCLRE_OFF_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_PORTBE_3H
    @ __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    @ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
    @ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    @ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
    @ __CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
    @ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
    @ __CONFIG _CONFIG7H, _EBTRB_OFF_7H & _DEVID1 & _IDLOC0
     
    'Registers
    ADCON1  = %00001111     'Turn off all AD's (= "_PBADEN_OFF_3H")        
    TRISC   = %11000000     'stated by DS(!)
    RCSTA   = %10010010     'enable serial port, enable continuous receive, automatic clear overrun error
    TXSTA   = %00000000     'disable transmit, BRGH=0
    BAUDCON = %01101000
    SPBRG   = 51            '9600 Baud @ 8MHz, 0.16%
    SPBRGH  = 0
     
    '-------------------------------------------------------------------------------
    ' DEFINEs
    DEFINE OSC 8
     
    DEFINE LCD_DREG PORTB   'LCD data port 
    DEFINE LCD_DBIT 0       'LCD data starting PORT.bit (0 or 4)
    DEFINE LCD_RSREG PORTC  'LCD register select port 
    DEFINE LCD_RSBIT 4      'LCD register select bit 
    DEFINE LCD_EREG PORTC   'LCD enable port 
    DEFINE LCD_EBIT 5       'LCD enable bit 
    DEFINE LCD_BITS 4       'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2      'Number lines on LCD 
     
    '-------------------------------------------------------------------------------
    INIT:
    GPS_D   VAR BYTE(80)    'Incomming data bit array
    LED0    VAR PORTA.5     'alive LED
     
    '-------------------------------------------------------------------------------
    ' DOGM LCD display specific settings
    PAUSE 1000              'Time to settle Vdd
    LCDOUT $FE, $29         'Function Set: 4 bits bus mode
    LCDOUT $FE, $1C         'Bias set
    LCDOUT $FE, $52         'Power control + Contrast (HiByte)(for 5V=$52/3,3V=55)
    LCDOUT $FE, $69         'Follower control  (5V=$69/3,3V=6D)
    LCDOUT $FE, $78         'Contrast (LowByte)
     
    '-------------------------------------------------------------------------------
    ' Main loop
     
    LCDOUT $FE,2,"HSERIN"
      
    MAIN:
      
      HSERIN [WAIT("$GPGGA,"),STR GPS_D\6]
     
      LCDOUT $FE,2,GPS_D(0),GPS_D(1),":",GPS_D(2),GPS_D(3),":",GPS_D(4),GPS_D(5)
      
      TOGGLE LED0
     
      GOTO MAIN:
    Roger

  13. #13
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Your chip is listed as one of the PIC18F chips that can be inverted by setting the BAUDCON RXDTP and TXCKP bits. So if you want, you can go without the max232.

    http://www.picbasic.co.uk/forum/showthread.php?t=10361
    http://www.scalerobotics.com

  14. #14
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    That's the first thing I checked in his latest code. He has bit 5 in BAUDCON set to 1; inverted.

    I only got more confused with this thread, more than usual anyways. And to make things worse I'm using a hybrid USART without MAX232 in my current project. Good thing for fortunate souls that share code.

    Robert

  15. #15
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Well I am a bit confused too. It looks like he is inverting it, and using a max232, and has success with that (If I am reading it right). So, if that is the case, don't invert it, and don't use a max232.
    http://www.scalerobotics.com

  16. #16
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Quote Originally Posted by ScaleRobotics View Post
    ... So, if that is the case, don't invert it, and don't use a max232.

    That's what I was going to post, but thought I'd sound even more weird than usual.

    I see where my debugging went wrong; I relied on his comments, not his settings.

    Code:
    GPSbps    = 32852       'Open,True,N,9600bps (TTL level)
    He said TRUE (non-inverted) but then contradicted with N (inverted) in his comment. It can't be both. I was looking for T or N, to compare against the table in PBP manual.

    Using PIC Multicalc:
    9600, open, inverted, no parity = 49236
    9600, open, true, no parity = 32852

    The working SERIN was using non-inverted, that would explain why inverting a MAX232 would work.

    Does that make sense?

    Robert

  17. #17
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    The "N" in his comment is for No parity.
    As in "8,N,1"
    Dave
    Always wear safety glasses while programming.

  18. #18
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    That's possible, but that only explains why I got confused trying to follow his settings.

    The fact remains that he was using non-inverted in SERIN, and then trying inverted in HSERIN at the end, no?

    He shouldn't have to use a MAX232 with HSERIN if his GPS worked with SERIN non-inverted. Or is he on to something with HSERIN creating higher voltages than SERIN? (I have no idea about that).

    Robert


    EDIT: Look at SERIN in the PBP manual, that's where I got N as being inverted. His comment didn't mention a stop bit so I didn't catch on as it meaning 8N1.
    Last edited by Demon; - 23rd March 2012 at 15:10.

  19. #19
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    I Think HSERIN only speaks TRUE and likes a nice pull up resistor, just to keep it honest. The max232 would invert it, NO?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  20. #20
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,796


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Some PIC have the option to select true or inverted.

    Ioannis

  21. #21
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Based on the code in post #12, I removed the WAIT modifier to be able to see what happens on each try (= display anything data that comes into the PIC): HSERIN[STR GPS_D\6].

    Quote Originally Posted by Archangel View Post
    ...and likes a nice pull up resistor...
    I removed the MAX232, added a 10k pull-up on PORTC.7 (PIC's RX pin) and changed BAUDCON to % 01001000 (not inverted). It works now!!!


    I re-modified the code to: HSERIN [WAIT("$GPGGA,"),STR GPS_D\6]

    I now can see "HH:MM:SS" as it should.

    Nevertheless, I have my PIC running for more than an hour now and it often hangs (= time is no incrementing every second anymore) and starts overs maybe 10 or 20 seconds later. Seems that the data signal is just at the limit the PIC can "read" it properly. This does not happen in my SERIN2 mode.

    With the oscilloscope, I measure 4,7VDC for the highest data signal level on PORTC.7 while the PIC and the GPS module are powered by the PICKit2 and its 4,95VDC from USB.

    I think I will choose to stay on the SERIN2 version since it looks more "reliable" and, as already said, needs less components.
    Last edited by flotulopex; - 25th March 2012 at 11:08. Reason: typo
    Roger

  22. #22
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Quote Originally Posted by flotulopex View Post
    Nevertheless, I have my PIC running for more than an hour now and it often hangs (= time is no incrementing every second anymore) and starts overs maybe 10 or 20 seconds later.
    That sounds more like a USART buffer overflow.
    If it isn't cleared ... it will hang.

    Try adding ...

    DEFINE HSER_CLROERR 1 ' clear overflow automatically
    DT

  23. #23
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Quote Originally Posted by Ioannis View Post
    Some PIC have the option to select true or inverted.

    Ioannis
    Don't know what I saw, I thought he was working with a 16F628 . . . still I did not know this anyway. Thanks to you and Walter.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  24. #24
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Yup! Adding "DEFINE HSER_CLROERR 1" has solved the "hanging" problem.

    As I previously set the RCSTA.1 = 1, I wrongly thought this would handle the automatic overrun. I should have noticed the "Read-Only" flag on this bit in the datasheet.

    BTW, what exactly does "DEFINE HSER_CLROERR" 1 do? Where can I find information about what other DEFINE commands do?

    NB: my apologise Demon; I missed your advice for a pull-up in an early post

    Final working code is HSERIN-EUART-test_18F2420.zip
    Roger

  25. #25
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Quote Originally Posted by flotulopex View Post
    Yup! Adding "DEFINE HSER_CLROERR 1" has solved the "hanging" problem.

    As I previously set the RCSTA.1 = 1, I wrongly thought this would handle the automatic overrun. I should have noticed the "Read-Only" flag on this bit in the datasheet.

    BTW, what exactly does "DEFINE HSER_CLROERR" 1 do? Where can I find information about what other DEFINE commands do?

    NB: my apologise Demon; I missed your advice for a pull-up in an early post

    Final working code is Attachment 6366
    From the book "As the hardware buffer only has 2 byte input buffer, it can easily overflow if charactors are not read from it often enough. When this happens, the USART stops accepting new characters and needs to be reset. This error can be reset by toggling the CREN bit in the RCSTA register. A DEFINE can be used to automatically clear this error. However you will not know that an error has occured and characters may have been lost."
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  26. #26
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Quote Originally Posted by Archangel View Post
    ...However you will not know that an error has occured and characters may have been lost.

    Ah, and this must be where a checksum comes it to play?

    Robert

  27. #27
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    ...Where can I find information about what other DEFINE commands do?
    Can someone please tell?
    Roger

  28. #28
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,518


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Believe it or not but they are actually listed in the manual. I know - who would've thought... ;-)
    In my 2.60 book they are in Appendix B and in the PBP3 book they are in section 8.7

    And, DEFINE is not a command in that it does not execute at runtime. It's a compiler directive that tells the compiler how and what code to generate. This means that you can not use DEFINE to change a setting (like for example the parity for the USART) at runtime.

    /Henrik.

  29. #29
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: SERIN2 = ok, HSERIN = no!

    Thanks ;-)
    Roger

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts