strange problem with HSERIN


Closed Thread
Results 1 to 17 of 17

Hybrid View

  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

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