strange problem with HSERIN


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Aug 2010
    Posts
    10

    Default strange problem with HSERIN

    I'm trying to transfer a working program from a 16f887 to a 18f85j11.
    I'm working with PBP 2.60.

    The program works well on the 16f887, but i'm having a problem with the serial communication on the 18f85j11.

    The program seems to hang, or get really slow when I insert the HSerin command into the program. Even when the program NEVER jumps to the RS232 Label the program is really slow. When I comment out the Hserin (and still don't jump to the rs232 label) , the program works nicely.

    What can the problem be?

    Thanks in advance.



    Code:
    RS232:
                    DIRECTION = 0        ' send or receive bit	
    	HSerin 1,GO,[WAIT("$"),BUFF]
    	IF BUFF = ADRESS Then
    		OK = 1
    		For I = 1 TO AANTAL
    		  HSerin [DATI]
    		  BUFFER(I) = DATI 
    		Next
    	EndIF

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you comment out the entire routine, or never jump to it, it should have zero effect on anything. If your code falls-through into the routine, then it may, but it's tough to help diagnose without seeing all your code, and knowing what you have set for config options, hardware, etc.

    The more info you post, the more likely you are to get help.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Aug 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Well, thats the strange thing about this.

    It does not matter if I jump to the routine or not.
    It only matters if I comment out the HSERIN command.

    Can It be something with the initialisation of the chip and the USART?

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    That is strange. Can you post more information as mentioned above?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    I had issues with serial comms when moving code from an 16F877A to an 18F4580. Turns out it was due to the crystal. I had been using a 20Mhz with an OSC 48 defined - when used with the 18F the program would still run but serial comms at 115200 was garbage - following advice from forum members I changed the xtal to 12Mhz and ran with the HS_PLL defined and same OSC defined and that worked for me.

    As Bruce stated, post up your complete code or at least the defines and what Xtal you are using

  6. #6
    Join Date
    Aug 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    I will post the code tomorrow morning, I do not have it available where I'm at the moment.

  7. #7
    Join Date
    Aug 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    This is the program code. the hserin2 is only used. I'm using a 20Mhz OSC.

    the tx_enable is connected to TG0 (pin5)
    the rx2 is connected to RG2 (pin7)
    the tx2 is connected to RG1 (pin6)

    Code:
      
    
     'PIC18F85J11 mainboard grafisch display
       
       DEFINE HSER_TXSTA 24H
       DEFINE HSER_RCSTA 90H
       DEFINE HSER_SPBRG 4
       DEFINE HSER_CLROERR 1
       
       DEFINE HSER2_TXSTA 24H
       DEFINE HSER2_RCSTA 90H
       DEFINE HSER2_SPBRG 4
       DEFINE HSER2_CLROERR 1
       
       'DEFINE ADC_BITS  8
       'DEFINE ADC_CLOCK  3
       'DEFINE ADC_SAMPLEUS 50
       
       DEFINE OSC 20
       
       DEFINE LCD_DREG PORTE
       DEFINE LCD_DBIT 0
       DEFINE LCD_RSREG PORTF
       DEFINE  LCD_RSBIT 4
       DEFINE LCD_EREG PORTG
       DEFINE LCD_EBIT 4 
       DEFINE LCD_BITS 8
       DEFINE LCD_LINES 2
       DEFINE LCD_COMMANDUS 2000
       DEFINE LCD_DATAUS 50
       
       
       ADCON1  = 15
       ADCON0   = 0
       CMCON   = 7
       T0CON  = %11000011
       INTCON  = %10100000
       INTCON2  = %00000100
      
       TRISA  = %10111111
       TRISB  = %00000001   
       TRISC  = %10000000
       TRISD  = %01000000
       TRISE  = %00000000
       TRISF   = %00000110
       TRISG   = %00000000
       TRISH   = %10110100
       TRISJ   = %00000001
       
       INP_OUTP21 VAR PORTA.0
       INP_OUTP22 VAR PORTA.1
       INP_OUTP23 VAR PORTA.2
       INP_OUTP24 VAR PORTA.3
       INP_OUTP25 VAR PORTA.4
       INP_OUTP26 VAR PORTA.5
       XTAL_0  VAR PORTA.6
       XTAL_1  VAR PORTA.7
       
       INP_OUTP27 VAR PORTB.0
       IR_DATA  VAR PORTB.1
       INP_OUTP28 VAR PORTB.2
       INP_OUTP29 VAR PORTB.3
       INP_OUTP30 VAR PORTB.4
       INP_OUTP31 VAR PORTB.5
       PRG_CLK  VAR PORTB.6
       PRG_DTA  VAR PORTB.7
       
       INP_OUTP32 VAR PORTC.0
       RES_01  VAR PORTC.1
       RES_02  VAR PORTC.2
       SCL_ROM  VAR PORTC.3
       SDA_ROM  VAR PORTC.4
       RES_03  VAR PORTC.5
       RF_TX  VAR PORTC.6
       RF_RX  VAR PORTC.7
       
       RES_04  VAR PORTD.0
       RES_05  VAR PORTD.1
       RES_06  VAR PORTD.2
       RES_07  VAR PORTD.3
       INP_OUTP01 VAR PORTD.4
       INP_OUTP02 VAR PORTD.5
       INP_OUTP03 VAR PORTD.6
       INP_OUTP04 VAR PORTD.7
       
       D0_DISPLAY VAR PORTE.0
       D1_DISPLAY VAR PORTE.1
       D2_DISPLAY VAR PORTE.2
       D3_DISPLAY VAR PORTE.3
       D4_DISPLAY VAR PORTE.4
       D5_DISPLAY VAR PORTE.5
       D6_DISPLAY VAR PORTE.6
       D7_DISPLAY VAR PORTE.7
       
       DISPL_EN1 VAR PORTF.1
       DISPL_EN2 VAR PORTF.2
       RES_08  VAR PORTF.3
       DISPL_RS VAR PORTF.4
       RES_09  VAR PORTF.5
       RES_10  VAR PORTF.6
       RES_11  VAR PORTF.7
       
       TX_ENABLE VAR PORTG.0
       TX_RS485 VAR PORTG.1
       RX_RS485 VAR PORTG.2
       RES_12  VAR PORTG.3
       DISPL_EN VAR PORTG.4
       
       INP_OUTP05 VAR PORTH.0
       INP_OUTP06 VAR PORTH.1
       INP_OUTP07 VAR PORTH.2
       INP_OUTP08 VAR PORTH.3
       INP_OUTP09 VAR PORTH.4
       INP_OUTP10 VAR PORTH.5
       INP_OUTP11 VAR PORTH.6
       INP_OUTP12 VAR PORTH.7
       
       INP_OUTP13 VAR PORTJ.0
       INP_OUTP14 VAR PORTJ.1
       INP_OUTP15 VAR PORTJ.2
       INP_OUTP16 VAR PORTJ.3
       INP_OUTP17 VAR PORTJ.4
       INP_OUTP18 VAR PORTJ.5
       INP_OUTP19 VAR PORTJ.6
       INP_OUTP20 VAR PORTJ.7
       
       I  VAR BYTE
       K  VAR BYTE
       TELLER  VAR BYTE
       ADRESS  VAR BYTE
       AANTAL  VAR BYTE
       LCDBUFI  VAR BYTE [6]
       LCDBUFO  VAR BYTE [6]
       BUFFERI  VAR BYTE [6]
       BUFFERO  VAR BYTE [6]
       STARTCHAR VAR BYTE
       DATO  VAR BYTE
       DATI  VAR BYTE
       BUFF  VAR BYTE
       OK  VAR BIT
       
       
       Pause 500
          
       Clear
       FLAGS = 0
       
       LCDOut $FE,$1,  "DISPLAY"
       LCDOut $FE,$C0, "TEST" 
       
       Pause 500
       
       TX_ENABLE = 1
       STARTCHAR = "$"
     
     
    BEGIN: 
       For K = 240 TO 240
        teller = teller + 1   
        ADRESS = K
        AANTAL = 1 
        buffero(K) = teller
        GoSub WEGSCHRIJVEN
        PauseUs 200
        ADRESS = K
        AANTAL = 1 
        GoSub OPHALEN 
        IF OK = 1 Then
         lcdbufO(K) = bufferi(K)
         LCDBUFI(K) = BUFFERO(K)
         GoSub LCD 
         OK = 0
        GoTo HIER1
        EndIF
       LCDBUFO(K) = 0
       LCDBUFI(K) = 0
       GoSub LCD
    HIER1:  Next
     
       GoTo BEGIN
       
    'SUBROUTINES
      
    WEGSCHRIJVEN:
     
       DATO = STARTCHAR : GoSub CHAROUT
       DATO = ADRESS : GoSub CHAROUT
       DATO = "W" : GoSub CHAROUT
       For I = 1 TO AANTAL   
        DATO = BUFFERO(I) : GoSub CHAROUT
       Next 
       Return
       
    OPHALEN:
       OK = 0
       DATO = STARTCHAR : GoSub CHAROUT
       DATO = ADRESS : GoSub CHAROUT
       DATO = "R" : GoSub CHAROUT
       PauseUs 100
       TX_ENABLE = 0 
       HSerin2 1,GO,[WAIT("$"),BUFF]
       IF BUFF = ADRESS Then
        OK = 1
        For I = 1 TO AANTAL
        HSerin2 [DATI]
        BUFFERi(I) = DATI 
       Next
       EndIF
    GO:     
       PauseUs 50
       TX_ENABLE = 1
       Return
    CHAROUT: 
       TX_ENABLE = 1
       HSerout2 [DATO]
       Return
     
       
    LCD:   
       
       GoSub USE_LCD1
       LCDOut $FE,$80, "ADRES       1    2"
       LCDOut $FE,$94, "   3    4    5"
       LCDOut $FE,$C0, "DATA    ",HEX LCDBUFO(1),"  ",HEX LCDBUFO(2)
       LCDOut $FE,$D4, HEX LCDBUFO(3),"  ",LCDBUFO(4),"  ",LCDBUFO(5)
       GoSub USE_LCD2
       LCDOut $FE,$80, "DATA    ",HEX LCDBUFI(1),"  ",HEX LCDBUFI(2)
       LCDOut $FE,$94, HEX LCDBUFI(3),"  ",LCDBUFI(4),"  ",LCDBUFI(5)
        
       Return   
       
    USE_LCD1:
           Input DISPL_EN1
           Low   DISPL_EN2
       Return
     
    USE_LCD2:
          Low   DISPL_EN1
           Input DISPL_EN2
       Return
     
    USE_BothLCD:
           Input DISPL_EN1
           Input DISPL_EN2
       Return 
          
       End

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


    Did you find this post helpful? Yes | No

    Default

    This is the program code. the hserin2 is only used. I'm using a 20Mhz OSC.
    HSERIN2 is only used for chips with two hardware serial ports/
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Aug 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    HSERIN2 is only used for chips with two hardware serial ports/
    The 18f85j11 has 2 serial ports. 1 EUSART and 1 AUSART. I should be able to use this command.

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


    Did you find this post helpful? Yes | No

    Default

    OOPPSS

    Maybe this???
    The pins of the AUSART module are multiplexed with
    the functions of PORTG (RG1/TX2/CK2 and
    RG2/RX2/DT2, respectively). In order to configure
    these pins as an AUSART:
    • bit SPEN (RCSTA2<7>) must be set (= 1)
    • bit TRISG<2> must be set (= 1)
    • bit TRISG<1> must be cleared (= 0) for
    Asynchronous and Synchronous Master modes
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default idle state

    Hi Beginner,
    One thing to check is the port's idle state. HSER* requires the port to idle HIGH so you will need a pull up resistor or the port will likely hang the program.
    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.

  12. #12
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    One thing to check is the port's idle state. HSER* requires the port to idle HIGH so you will need a pull up resistor or the port will likely hang the program.
    Joe,

    Thanks for the heads up on that, but most of the samples I've come across have something like
    Code:
     IF RCIF THEN GOSUB xxxxx
    or
     IF RCIF=1 THEN GOSUB xxxxx
    If the pins are tied high then this will cause the code to constantly loop to the sections that deal with the comms. would it not be better to tie the pins to ground via resistors ?

  13. #13
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    The USART RX pin should definitely idle high, but this routine has some major issues;
    Code:
    BEGIN: 
       For K = 240 TO 240  ' <-- BIG problem here
        teller = teller + 1   
        ADRESS = K
        AANTAL = 1 
        buffero(K) = teller  ' <-- there is no buffero(240)
        GoSub WEGSCHRIJVEN
        PauseUs 200
        ADRESS = K
        AANTAL = 1 
        GoSub OPHALEN 
        IF OK = 1 Then
         lcdbufO(K) = bufferi(K) ' <-- same issue here
         LCDBUFI(K) = BUFFERO(K) ' <-- and here
         GoSub LCD 
         OK = 0
        GoTo HIER1
        EndIF
       LCDBUFO(K) = 0
       LCDBUFI(K) = 0
       GoSub LCD
    HIER1:  Next
    K = 240, but your largest array variables are only 6 bytes. I.E. buffero(0) to buffero(5) would be the last byte available in your buffero array.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  14. #14
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Uhmm... just looked at the schematic in the EasyPIC5 manual, the RX line is connected direct to the R1Out pin on the Max232 - the TX pin to the T1in pin which is tied to Vcc via 1K resistor. I assume the MAX232 will handle the logic level of the RX pin ?

  15. #15
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I assume the MAX232 will handle the logic level of the RX pin ?
    Yes it will. The MAX232 has an internal pull-down on the R1in side of the inverter http://www.rentron.com/Files/bMAX232.gif
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  16. #16
    Join Date
    Aug 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    The USART RX pin should definitely idle high, but this routine has some major issues;
    Code:
    BEGIN: 
       For K = 240 TO 240  ' <-- BIG problem here
        teller = teller + 1   
        ADRESS = K
        AANTAL = 1 
        buffero(K) = teller  ' <-- there is no buffero(240)
        GoSub WEGSCHRIJVEN
        PauseUs 200
        ADRESS = K
        AANTAL = 1 
        GoSub OPHALEN 
        IF OK = 1 Then
         lcdbufO(K) = bufferi(K) ' <-- same issue here
         LCDBUFI(K) = BUFFERO(K) ' <-- and here
         GoSub LCD 
         OK = 0
        GoTo HIER1
        EndIF
       LCDBUFO(K) = 0
       LCDBUFI(K) = 0
       GoSub LCD
    HIER1:  Next
    K = 240, but your largest array variables are only 6 bytes. I.E. buffero(0) to buffero(5) would be the last byte available in your buffero array.
    I tried to change the For K = 240 TO 240 to For K = 0 TO 5 , but it does not make any difference.

    The chip still keeps running VERY slow (like 25 seconds startup time) when I'm using the HSERIN command.

    ---------------------

    The RS232 schematic is ok, I'm using the same for other PCB's with 16f887 and 16f882 chips where it works fine.
    ----------------------

    Also changing the bit TRISG<2> = 1 does not solve this problem.

    Any more suggestions?

  17. #17
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    I did some tests with that chip and also using a rs485 chip to test. You talked about rs232 and a direction (TX_ENABLE) and when I look at the code I think it's RS485, but that is not an issue.
    I also discovered that indeed the chip will not startup when using HSERIN and the RX pin of the uart is high.
    I put a 10K resistor from the RX pin of the picchip to ground and now the program is starting up normaly.
    I hope it will help you.

Members who have read this thread : 0

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