Hserout2 does not work on PIC18F47K40


Today 18:40
Forum: GPS
Starter: david
Views: 0
Replies: 3
Today 18:19
Forum: Proton Plus Compiler v3
Starter: Les
Views: 0
Replies: 16
Today 15:54
Forum: GPS
Starter: SimonJA
Views: 0
Replies: 14
Go to last post By: tumbleweed
Today 14:37
Forum: The Lounge
Starter: towlerg
Views: 0
Replies: 1
Go to last post By: fanie
Today 14:10
Forum: The Lounge
Starter: John Drew
Views: 0
Replies: 12
Today 12:55
Forum: The Lounge
Starter: fanie
Views: 0
Replies: 18
Today 02:12
Forum: The Lounge
Starter: towlerg
Views: 0
Replies: 5
Today 01:13
Forum: The Lounge
Starter: Tim
Views: 0
Replies: 25
+ Reply to Thread
Results 1 to 6 of 6

Thread: Hserout2 does not work on PIC18F47K4015 days old

  1. #1
    Junior Member gtv_pic's Avatar
    Join Date
    Nov 2005
    Posts
    36
    Thumbs Up
    Received: 0
    Given: 1
    Total Downloaded
    4.38 GB

    0 Not allowed!

    Default Hserout2 does not work on PIC18F47K40

    I continue to have problems in the PIC18F47K40 and the serial port 2, I am not able to send characters or respond to reception interception.
    The code used is:
    Code:
    '++++++++++++++++++++++[Tipo de Procesador]+++++++++++++++++++++++++++++++++++++
    ' Tipo de Procesador
    Device =  18F47K40
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Declare Xtal                  11.0592   ' Velocidad Real 11.059.200Hz
    Declare Optimiser_Level             0   ' Tipo Optimizacion del Compilador
    Declare Dead_Code_Remove         True   ' Elimina el Codigo Sobrante
    '++++++++++++++++++++++[Genericas]++++++++++++++++++++++++++++++++++++++++++++++
    Declare Show_System_Variables =  True   ' Ver Variables Internas en Simulador
    Declare Reminders             = False   ' Anula comentarios del compilador
    Declare PLL_Req               =  True   ' Multiplicar Oscilador X4.
    Declare Label_Bank_Resets     =  True 
    Declare Stack_Size            =    20   ' Reserva Espacio en la Pila.
    Declare Float_Rounding        = False   ' Redondeo en los calculos   
    Declare Reminders             =  True   ' Habilita comentarios del compilador
    Declare Watchdog              = FALSE   ' El Compilador NO pone CLRWDT 
    Declare FSR_CONTEXT_SAVE      =  True   ' Guardar Variables Antes de Interupcion
    Declare Icd_Req               =  True   ' Reservar Espacio para ICD2
    Declare Bootloader            = False   ' No Permite la Carga del Puerto Serie
    Declare Create_Coff           =  True   ' Crear Fichero .COF
    Declare All_Digital           =  True   ' Todos los Pines Digitales
    '    
    '
    Dim Cuenta As Dword
    Dim Aux_C2              As Byte             ' Auxiliar Buffer Puerto Serie 2
    Dim LBuffer2            As Byte             ' Numero C.en Buffer Puerto Serie 2
    Dim Buffer2[25]         As Byte             ' Buffer del Puerto Serie 2
    
    
    Symbol LED_1            =  PORTB.3      ' Led 1 del Micro
    Symbol LED_2            =  PORTB.4      ' Led 2 del Micro
    '
    '++++++++++++++++++++++[Comunicacion Serie Puerto 2]++++++++++++++++++++++++++++
    '                 Puerto Serie TTL de BLUETOOTH o ETHERNET 
    Declare HserOut2_Pin          PORTB.6   ' Pin TX del Puerto 2
    Declare HserIn2_Pin           PORTB.7   ' Pin RX del Puerto 2
    Declare Hserial2_Baud          9600     ' Velocidad del Puerto Serie
    '
    '++++++++++++++++++++++[Registro RCSTA2]++++++++++++++++++++++++++++++++++++++++
    RCSTA2.0 = 0    ' RX9D = Lectura del 9 Bit 
    RCSTA2.1 = 0    ' OERR = Lectura de Error en comunicacion puerto 2 
    RCSTA2.2 = 0    ' FERR = Lectura de Error en comunicacion puerto 2 
    RCSTA2.3 = 0    ' ADDEN= Funcion Solo con 9 Bit
    RCSTA2.4 = 1    ' CREN  Permiso Lectura continua del puerto 2
    RCSTA2.5 = 0    ' SREN  Solo Funcionamiento en Modo Sincrono
    RCSTA2.6 = 0    ' ADDEN Funcionamiento a 9 Bit
    RCSTA2.7 = 1    ' SPEN  Puerto Serie habilitado
    '++++++++++++++++++++++[Registro TXSTA2]++++++++++++++++++++++++++++++++++++++++
    TXSTA2.0 = 0    ' TX9D  9 bit a transmitir
    TXSTA2.1 = 0    ' TRMT  1 Indicacion en TXT cuando esta vacio Buffer de salida
    TXSTA2.2 = 0    ' BRGH  Dividir entre 64=0 Con 1 Divide entre 16     
    TXSTA2.3 = 0    ' SENDB
    TXSTA2.4 = 0    ' SYNC  Comunicacion ASINCRONA
    TXSTA2.5 = 1    ' TXEN  Transmision Habilitada
    TXSTA2.6 = 0    ' TX9   Transmision a 8 Bit
    TXSTA2.7 = 0    ' CSCR  Sin Funcion en Comunicacion Asincrona
    '++++++++++++++++++++++[Registro BAUDCON2]++++++++++++++++++++++++++++++++++++++
    BAUDCON2 = 000000
    '++++++++++++++++++++++[Definicion Velocidad Comunicacion Puerto 2]+++++++++++++
    ' Ajuste Velocidad comunicacion Puerto Serie 1 (Bluetooth o Ethernet)
    ' La velocidad de comunicacion se calcula 
    ' ((Frecuencia del micro/velocidad deseada)/64)+1 -> TXSTA.2 sea 0
    ' ((Frecuencia del micro/velocidad deseada)/16)+1 -> TXSTA.2 sea 1
    ' Se esta multiplicando la velocidad (11059200) X 4
    ' Velocidad Deseada 9600 | ((44236800 / 9600)/64)-1 = 71
    SPBRG2  = 71        ' Calculo de la velocidad de comunicacion
    '
    '++++++++++++++++++++++[Definicion del PORTA]+++++++++++++++++++++++++++++++++++
    TRISA.0 = 1             ' ENTRADA Analogica Tension  24Vcc
    TRISA.1 = 1             ' ENTRADA Analogica Tension 5Vcc de Micro
    TRISA.2 = 1             ' ENTRADA Analogica Referencia de CERO Vcc Entradas Analogicas
    TRISA.3 = 1             ' ENTRADA Analogica Referencia de 5Vcc Entradas Analogicas
    TRISA.4 = 0             ' SALIDA  LED de OK en Placa
    TRISA.5 = 1             ' ENTRADA FC Cerrar
    'TRISA.6                ' Oscilador
    'TRISA.7                ' Oscilador
    ' +++++++++++++++++++++[Definicion del PORTB]+++++++++++++++++++++++++++++++++++
    TRISB.0 = 1             ' ENTRADA RESERVA                
    TRISB.1 = 1             ' ENTRADA SCL2 I2C2
    TRISB.2 = 1             ' ENTRADA SDA2 I2C2
    TRISB.3 = 0             ' SALIDA  LED 1 DEL MICRO
    TRISB.4 = 0             ' SALIDA  LED 2 DEL MICRO    
    TRISB.5 = 1             ' ENTRADA STATE DEL BLUETOOTH 
    TRISB.6 = 0             ' SALIDA  TX USRT2 Transmision  BLUETOOTH
    TRISB.7 = 1             ' ENTRADA RX UART2 Recepcion    BLUETOOTH
    '++++++++++++++++++++++[Definicion del PORTC]+++++++++++++++++++++++++++++++++++
    TRISC.0 = 1             ' ENTRADA LED Paro
    TRISC.1 = 1             ' ENTRADA RESERVA
    TRISC.2 = 0             ' SALIDA  PWM Salida Analogica 0-10Vcc
    TRISC.3 = 0             ' SALIDA  TX1EN RS485 Enabled Transmision RS485
    TRISC.4 = 0             ' SALIDA  RELE Orden de Abrir
    TRISC.5 = 0             ' SALIDA  RELE Orden de Cerrar
    TRISC.6 = 0             ' SALIDA  TX USRT1 Transmision RS485
    TRISC.7 = 1             ' ENTRADA RX UART1 Recepcion   RS485
    '++++++++++++++++++++++[Definicion del PORTD]+++++++++++++++++++++++++++++++++++
    TRISD.0 = 1             ' ENTRADA RESERVA
    TRISD.1 = 1             ' ENTRADA Circuito de Seguridad ENCODER
    TRISD.2 = 0             ' SALIDA  KEY del BLUETOOTH
    TRISD.3 = 0             ' SALIDA  Circuito de Seguridad ENCODER
    TRISD.4 = 0             ' SALIDA  Rele de FRENO
    TRISD.5 = 1             ' ENTRADA Foto celula         
    TRISD.6 = 1             ' ENTRADA SWITCH 1       
    TRISD.7 = 1             ' ENTRADA SWITCH 2         
    '++++++++++++++++++++++[Permiso a las Interupciones]++++++++++++++++++++++++++
    '   Puerto Serie 2
    PIR3.7      = 1         ' RC2IF 
    PIE3.7      = 1         ' RC2IE 
    IPR3.7      = 1         ' RC2IP
    '
    '++++++++++++++++++++++[Dirrecion de Sal por Interrupcion]++++++++++++++++++++++
    On_Hardware_Interrupt Interrupcion      ' Define Salto en Caso de Interrupcion
    '++++++++++++++++++++++[Salta Tras Interrupcion]++++++++++++++++++++++++++++++++
    GoTo TrasInterupcion                    ' Salta Tras la Rutina Interrupcion
    '++++++++++++++++++++++[Rutina de Interupcion]**********************************
    Interrupcion:       
    '
    Context Save                            ' Salva Registros Antes de Interrupcion
    '
    '++++++++++++++++++++++[INT Puerto Serie 2]+++++++++++++++++++++++++++++++++++++
    If PIR3.7 = 1 Then              ' Interupcion por Puerto Serie 2 
        Toggle LED_1                
        PIE3.7 = 0                  ' Borra la Bandera de Interrupcion
        If RCSTA2.2 = 1 Then RCSTA2.4 = 0   ' Si Hay Error Borra Comunicacion.  OERR
        If RCSTA2.1 = 1 Then RCSTA2.4 = 0   ' Si Hay Error Borra Comunicacion.  FERR
        If RCSTA2.4 = 1 Then        ' Si NO hay Error Comunicacion
            Aux_C2 = RCREG2         ' Lee Caracter del Buffer
            Buffer2[LBuffer2] = Aux_C2  ' Incorpara Caracter al Buffer
            Inc LBuffer2            ' Incrementa Caracteres en Buffer
        Else
            Aux_C2 = RCREG2         ' Lee el Caracter del Buffer Para Vaciarlo
        End If
        If RCSTA2.4 = 0 Then        ' Si la Comunicacion NO Activa la Activa
            RCSTA2.4 = 1            ' Activa el Puerto Serie
        End If
    End If
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    '
    Context Restore                 ' Retorna de la Interupcion
    '++++++++++++++++++++++[TraS Interupcion]+++++++++++++++++++++++++++++++++++++++
    TrasInterupcion:
    INTCON.5    = 1                 ' IPEN
    INTCON.6    = 0                 ' PEIE
    INTCON.7    = 1                 ' GIE Permiso General de Interupciones 
    
    
    '++++++++++++++++++++++[RUTINA PRINCIPAL]+++++++++++++++++++++++++++++++++++++++
    
    
    LED_1 = 0
    LED_2 = 0
    
    
    Nucleo_Principal:
    Inc Cuenta
    If Cuenta > 300000 Then
        HSerOut2 ["Caracteres en Buffer ",Dec4 LBuffer2,10,13]
        Cuenta = 0
        Toggle LED_2                       
    End If
    
    
    GoTo Nucleo_Principal
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    What am I doing wrong?
    Any help please

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,902
    Thumbs Up
    Received: 174
    Given: 163
    Total Downloaded
    3.24 GB

    0 Not allowed!

    Default Re: Hserout2 does not work on PIC18F47K40

    Not wanting to teach you to suck eggs but have you confirmed that the device is running at the same speed as your Xtal declaration?

    Do you get an output that is at the wrong speed or no output?
    George.

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Junior Member gtv_pic's Avatar
    Join Date
    Nov 2005
    Posts
    36
    Thumbs Up
    Received: 0
    Given: 1
    Total Downloaded
    4.38 GB

    0 Not allowed!

    Default Re: Hserout2 does not work on PIC18F47K40

    My English is not very good so I will try to explain the problem better
    Effectively the glass used is 11.0592.00 hz which I think is multiplied by 4 in the instruction
    Declare PLL_Req = True '


    In the program sent if I cancel the instruction
    HSerOut2 ["Characters in Buffer", Dec4 LBuffer2,10,13]
    LED_2 flashes correctly.
    If the instruction is LED_2 does not flash and I do not know what the program is doing, no characters will be sent through the port.


    At the same time the LED_1 that is in the interruption of the serial port 2 never indicates the reception of characters by said port.


    Thank you very much for the help.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,068
    Thumbs Up
    Received: 336
    Given: 126
    Total Downloaded
    1.52 GB

    0 Not allowed!

    Default PIC18F47K40 PPS setting for USART2 RX on PORTB.7

    The 18F47K40 device has PPS (Peripheral Pin Select), so it will need to be configured for USART2 RX.

    The compiler does this automatically if the program is using the Hrsin2 or Hserin2 commands, and the pin has been declared, but if not, it is up to the user to setup the PPS. The same for the HrsoutX and HseroutX commands.

    Try this to setup USART2 RX for PORTB.7:

    Code:
    RX2PPS = $0F
    RB7PPS = PPS_Fn_DT2
    It hasn't been tested, but looks OK. The PPS constants to load into the PPS SFR can be found in the device's .def file.

    For the 18F47K40 device they are:
    Code:
    '[PPS Defs Start]---------------------------------------------------------------------
    $define PPS_Fn_ADGRDB 23
    $define PPS_Fn_ADGRDA 22
    $define PPS_Fn_DSM 21
    $define PPS_Fn_CLKR 20
    $define PPS_Fn_TMR0 19
    $define PPS_Fn_SDO2 18
    $define PPS_Fn_SDA2 18
    $define PPS_Fn_SCK2 17
    $define PPS_Fn_SCL2 17
    $define PPS_Fn_SDO1 16
    $define PPS_Fn_SDA1 16
    $define PPS_Fn_SCK1 15
    $define PPS_Fn_SCL1 15
    $define PPS_Fn_C2OUT 14
    $define PPS_Fn_C1OUT 13
    $define PPS_Fn_DT2 12
    $define PPS_Fn_TX2 11
    $define PPS_Fn_CK2 11
    $define PPS_Fn_DT1 10
    $define PPS_Fn_TX1 9
    $define PPS_Fn_CK1 9
    $define PPS_Fn_PWM4 8
    $define PPS_Fn_PWM3 7
    $define PPS_Fn_CCP2 6
    $define PPS_Fn_CCP1 5
    $define PPS_Fn_CWG1D 4
    $define PPS_Fn_CWG1C 3
    $define PPS_Fn_CWG1B 2
    $define PPS_Fn_CWG1A 1
    '[PPS Defs End]---------------------------------------------------------------------
    Last edited by Les; 6th January 2019 at 16:17.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Junior Member gtv_pic's Avatar
    Join Date
    Nov 2005
    Posts
    36
    Thumbs Up
    Received: 0
    Given: 1
    Total Downloaded
    4.38 GB

    0 Not allowed!

    Default Re: Hserout2 does not work on PIC18F47K40

    Thank you very much Les, I thank you very much for your help and dedication but it remains the same.
    Incorporate the instructions into the code
    RX2PPS = $ 0F
    RB7PPS = PPS_Fn_DT2
    According to You tell me and the problem remains the same, having the instruction
    HSerOut2 ["Caracteres en Buffer ", Dec4 LBuffer2,10,13]
    The active processor is lost and does not send or receive characters through the serial port.
    the program stayed that way
    Code:
    '++++++++++++++++++++++[Tipo de Procesador]+++++++++++++++++++++++++++++++++++++
    ' Tipo de Procesador
    Device =  18F47K40
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Declare Xtal                  11.0592   ' Velocidad Real 11.059.200Hz
    Declare Optimiser_Level             0   ' Tipo Optimizacion del Compilador
    Declare Dead_Code_Remove         True   ' Elimina el Codigo Sobrante
    '++++++++++++++++++++++[Genericas]++++++++++++++++++++++++++++++++++++++++++++++
    Declare Show_System_Variables =  True   ' Ver Variables Internas en Simulador
    Declare Reminders             = False   ' Anula comentarios del compilador
    Declare PLL_Req               =  True   ' Multiplicar Oscilador X4.
    Declare Label_Bank_Resets     =  True 
    Declare Stack_Size            =    20   ' Reserva Espacio en la Pila.
    Declare Float_Rounding        = False   ' Redondeo en los calculos   
    Declare Reminders             =  True   ' Habilita comentarios del compilador
    Declare Watchdog              = FALSE   ' El Compilador NO pone CLRWDT 
    Declare FSR_CONTEXT_SAVE      =  True   ' Guardar Variables Antes de Interupcion
    Declare Icd_Req               =  True   ' Reservar Espacio para ICD2
    Declare Bootloader            = False   ' No Permite la Carga del Puerto Serie
    Declare Create_Coff           =  True   ' Crear Fichero .COF
    Declare All_Digital           =  True   ' Todos los Pines Digitales
    '    
    '
    Dim Cuenta As Dword
    Dim Aux_C2              As Byte             ' Auxiliar Buffer Puerto Serie 2
    Dim LBuffer2            As Byte             ' Numero C.en Buffer Puerto Serie 2
    Dim Buffer2[25]         As Byte             ' Buffer del Puerto Serie 2
    
    
    Symbol LED_1            =  PORTB.3      ' Led 1 del Micro
    Symbol LED_2            =  PORTB.4      ' Led 2 del Micro
    '
    '++++++++++++++++++++++[Comunicacion Serie Puerto 2]++++++++++++++++++++++++++++
    '                 Puerto Serie TTL de BLUETOOTH o ETHERNET 
    Declare HserOut2_Pin          PORTB.6   ' Pin TX del Puerto 2
    Declare HserIn2_Pin           PORTB.7   ' Pin RX del Puerto 2
    Declare Hserial2_Baud          9600     ' Velocidad del Puerto Serie
    RX2PPS                          = $0F 
    RB7PPS                   = PPS_Fn_DT2
    '
    '++++++++++++++++++++++[Registro RCSTA2]++++++++++++++++++++++++++++++++++++++++
    RCSTA2.0 = 0    ' RX9D = Lectura del 9 Bit 
    RCSTA2.1 = 0    ' OERR = Lectura de Error en comunicacion puerto 2 
    RCSTA2.2 = 0    ' FERR = Lectura de Error en comunicacion puerto 2 
    RCSTA2.3 = 0    ' ADDEN= Funcion Solo con 9 Bit
    RCSTA2.4 = 1    ' CREN  Permiso Lectura continua del puerto 2
    RCSTA2.5 = 0    ' SREN  Solo Funcionamiento en Modo Sincrono
    RCSTA2.6 = 0    ' ADDEN Funcionamiento a 9 Bit
    RCSTA2.7 = 1    ' SPEN  Puerto Serie habilitado
    '++++++++++++++++++++++[Registro TXSTA2]++++++++++++++++++++++++++++++++++++++++
    TXSTA2.0 = 0    ' TX9D  9 bit a transmitir
    TXSTA2.1 = 0    ' TRMT  1 Indicacion en TXT cuando esta vacio Buffer de salida
    TXSTA2.2 = 0    ' BRGH  Dividir entre 64=0 Con 1 Divide entre 16     
    TXSTA2.3 = 0    ' SENDB
    TXSTA2.4 = 0    ' SYNC  Comunicacion ASINCRONA
    TXSTA2.5 = 1    ' TXEN  Transmision Habilitada
    TXSTA2.6 = 0    ' TX9   Transmision a 8 Bit
    TXSTA2.7 = 0    ' CSCR  Sin Funcion en Comunicacion Asincrona
    '++++++++++++++++++++++[Registro BAUDCON2]++++++++++++++++++++++++++++++++++++++
    BAUDCON2 = 000000
    '++++++++++++++++++++++[Definicion Velocidad Comunicacion Puerto 2]+++++++++++++
    ' Ajuste Velocidad comunicacion Puerto Serie 1 (Bluetooth o Ethernet)
    ' La velocidad de comunicacion se calcula 
    ' ((Frecuencia del micro/velocidad deseada)/64)+1 -> TXSTA.2 sea 0
    ' ((Frecuencia del micro/velocidad deseada)/16)+1 -> TXSTA.2 sea 1
    ' Se esta multiplicando la velocidad (11059200) X 4
    ' Velocidad Deseada 9600 | ((44236800 / 9600)/64)-1 = 71
    SPBRG2  = 71        ' Calculo de la velocidad de comunicacion
    '
    '++++++++++++++++++++++[Definicion del PORTA]+++++++++++++++++++++++++++++++++++
    TRISA.0 = 1             ' ENTRADA Analogica Tension  24Vcc
    TRISA.1 = 1             ' ENTRADA Analogica Tension 5Vcc de Micro
    TRISA.2 = 1             ' ENTRADA Analogica Referencia de CERO Vcc Entradas Analogicas
    TRISA.3 = 1             ' ENTRADA Analogica Referencia de 5Vcc Entradas Analogicas
    TRISA.4 = 0             ' SALIDA  LED de OK en Placa
    TRISA.5 = 1             ' ENTRADA FC Cerrar
    'TRISA.6                ' Oscilador
    'TRISA.7                ' Oscilador
    ' +++++++++++++++++++++[Definicion del PORTB]+++++++++++++++++++++++++++++++++++
    TRISB.0 = 1             ' ENTRADA RESERVA                
    TRISB.1 = 1             ' ENTRADA SCL2 I2C2
    TRISB.2 = 1             ' ENTRADA SDA2 I2C2
    TRISB.3 = 0             ' SALIDA  LED 1 DEL MICRO
    TRISB.4 = 0             ' SALIDA  LED 2 DEL MICRO    
    TRISB.5 = 1             ' ENTRADA STATE DEL BLUETOOTH 
    TRISB.6 = 0             ' SALIDA  TX USRT2 Transmision  BLUETOOTH
    TRISB.7 = 1             ' ENTRADA RX UART2 Recepcion    BLUETOOTH
    '++++++++++++++++++++++[Definicion del PORTC]+++++++++++++++++++++++++++++++++++
    TRISC.0 = 1             ' ENTRADA LED Paro
    TRISC.1 = 1             ' ENTRADA RESERVA
    TRISC.2 = 0             ' SALIDA  PWM Salida Analogica 0-10Vcc
    TRISC.3 = 0             ' SALIDA  TX1EN RS485 Enabled Transmision RS485
    TRISC.4 = 0             ' SALIDA  RELE Orden de Abrir
    TRISC.5 = 0             ' SALIDA  RELE Orden de Cerrar
    TRISC.6 = 0             ' SALIDA  TX USRT1 Transmision RS485
    TRISC.7 = 1             ' ENTRADA RX UART1 Recepcion   RS485
    '++++++++++++++++++++++[Definicion del PORTD]+++++++++++++++++++++++++++++++++++
    TRISD.0 = 1             ' ENTRADA RESERVA
    TRISD.1 = 1             ' ENTRADA Circuito de Seguridad ENCODER
    TRISD.2 = 0             ' SALIDA  KEY del BLUETOOTH
    TRISD.3 = 0             ' SALIDA  Circuito de Seguridad ENCODER
    TRISD.4 = 0             ' SALIDA  Rele de FRENO
    TRISD.5 = 1             ' ENTRADA Foto celula         
    TRISD.6 = 1             ' ENTRADA SWITCH 1       
    TRISD.7 = 1             ' ENTRADA SWITCH 2         
    '++++++++++++++++++++++[Permiso a las Interupciones]++++++++++++++++++++++++++
    '   Puerto Serie 2
    PIR3.7      = 1         ' RC2IF 
    PIE3.7      = 1         ' RC2IE 
    IPR3.7      = 1         ' RC2IP
    '
    '++++++++++++++++++++++[Dirrecion de Sal por Interrupcion]++++++++++++++++++++++
    On_Hardware_Interrupt Interrupcion      ' Define Salto en Caso de Interrupcion
    '++++++++++++++++++++++[Salta Tras Interrupcion]++++++++++++++++++++++++++++++++
    GoTo TrasInterupcion                    ' Salta Tras la Rutina Interrupcion
    '++++++++++++++++++++++[Rutina de Interupcion]**********************************
    Interrupcion:       
    '
    Context Save                            ' Salva Registros Antes de Interrupcion
    '
    '++++++++++++++++++++++[INT Puerto Serie 2]+++++++++++++++++++++++++++++++++++++
    If PIR3.7 = 1 Then              ' Interupcion por Puerto Serie 2 
        Toggle LED_1                
        PIE3.7 = 0                  ' Borra la Bandera de Interrupcion
        If RCSTA2.2 = 1 Then RCSTA2.4 = 0   ' Si Hay Error Borra Comunicacion.  OERR
        If RCSTA2.1 = 1 Then RCSTA2.4 = 0   ' Si Hay Error Borra Comunicacion.  FERR
        If RCSTA2.4 = 1 Then        ' Si NO hay Error Comunicacion
            Aux_C2 = RCREG2         ' Lee Caracter del Buffer
            Buffer2[LBuffer2] = Aux_C2  ' Incorpara Caracter al Buffer
            Inc LBuffer2            ' Incrementa Caracteres en Buffer
        Else
            Aux_C2 = RCREG2         ' Lee el Caracter del Buffer Para Vaciarlo
        End If
        If RCSTA2.4 = 0 Then        ' Si la Comunicacion NO Activa la Activa
            RCSTA2.4 = 1            ' Activa el Puerto Serie
        End If
    End If
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    '
    Context Restore                 ' Retorna de la Interupcion
    '++++++++++++++++++++++[TraS Interupcion]+++++++++++++++++++++++++++++++++++++++
    TrasInterupcion:
    INTCON.5    = 1                 ' IPEN
    INTCON.6    = 0                 ' PEIE
    INTCON.7    = 1                 ' GIE Permiso General de Interupciones 
    
    
    '++++++++++++++++++++++[RUTINA PRINCIPAL]+++++++++++++++++++++++++++++++++++++++
    
    
    LED_1 = 0
    LED_2 = 0
    
    
    Nucleo_Principal:
    Inc Cuenta
    If Cuenta > 300000 Then
        HSerOut2 ["Caracteres en Buffer ",Dec4 LBuffer2,10,13]
        Cuenta = 0
        Toggle LED_2                       
    End If
    
    
    GoTo Nucleo_Principal
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    With these instructions I differ the port, is not it enough?
    Code:
    Declare HserOut2_Pin          PORTB.6   ' Pin TX del Puerto 2
    Declare HserIn2_Pin           PORTB.7   ' Pin RX del Puerto 2
    Declare Hserial2_Baud          9600     ' Velocidad del Puerto Serie
    thank you very much for your help

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,068
    Thumbs Up
    Received: 336
    Given: 126
    Total Downloaded
    1.52 GB

    0 Not allowed!

    Default Re: Hserout2 does not work on PIC18F47K40

    The first thing you need to do is create a simplified program that uses the standard Hrsin2 and Hrsout2 commands or Hserin2 and Hserout2 commands. For example, a simple infinite loop that receives a byte from USART2, via a serial terminal, then transmits the byte received to the serial terminal. This will prove that the commands are working as they should if the character is displayed on the terminal as it is pressed on the keypad. Then advance the code bit by bit, but keep testing as you go along.

    This is the only way you will get an answer for yourself, instead of producing a large piece of code with interrupts etc, then asking "why"? :-)

    Whenever I write programs, I start with the simple form of it, with debugging and testing, then progress with the complexity of the code, debugging and testing all along. Then when something does not work as it should, you know what caused it to go wrong.

    I've also noticed most of the declares used are simply not required, and some may cause problems if the fuses are not set correctly. For example, try it with an Xtal of 10 or 16 etc, and disable PLL via the declare, which in some devices is not enough to do the switching, and is now a redundant declare. See Johngb's excellent fuse configurator plugin. Once it works with a known crystal and a known frequency, then adjust the speed of the device.
    Last edited by Les; 6th January 2019 at 20:15.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Problem with Serial Port 1 on PIC18F47K40
    By gtv_pic in forum Proton Plus Compiler v3
    Replies: 8
    Last Post: 9th December 2018, 17:28
  2. I2C PIC18f47K40
    By krizpin in forum Master Synchronous Serial Port (MSSP) module / 3-wire SPI / I2C / Master and Slave modes
    Replies: 2
    Last Post: 23rd January 2018, 22:27
  3. PIC18F47K40 + Proton Devboard
    By Sean_Goddard in forum Proton Development Board
    Replies: 0
    Last Post: 8th October 2017, 14:54
  4. PIC 18F8722 Hserin2/Hserout2 problems
    By fgcity in forum Proton Plus Compiler v3
    Replies: 11
    Last Post: 1st March 2012, 10:58
  5. HSerout2 - Configurations
    By fgcity in forum Proton Plus Compiler v3
    Replies: 17
    Last Post: 18th January 2012, 11:27

Members who have read this thread since 21st January 2019, 14:15 : 0

Actions :  (Set Date)  (Clear Date)

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