News:

;) This forum is the property of Proton software developers

Main Menu

PIC16F15324 ASM UART Error

Started by PaoloFAP, Apr 22, 2024, 01:05 PM

Previous topic - Next topic

PaoloFAP

__hrsout1__
    movlb 0x0E
    btfss PIR1,PP_TX1IF
    bra $ - 1
    movlb 0x02
    movwf TXREG
    movlb 0x00
    bsf STATUS,0
    return

TX1IF is in PIR3

How can resolve it ?

top204

#1
What compiler version are you using?

Even with the earlier version 4.0.3.7, the assembler code is correct and uses PIR3:

__hrsout1__
    movlb 0x0E
    btfss PIR3,PP_TX1IF
    bra $ - 1
    movlb 0x02
    movwf TXREG
    movlb 0x00
    bsf STATUS,0
    return

And with the latest update of 4.0.3.8 and "upgrade" of 4.0.4.0, the assembler code is still correct:

__hrsout1__
    movlb 0x0E
    btfss PIR3,PP_TX1IF
    bra $ - 1
    movlb 0x02
    movwf TXREG
    movlb 0x00
    bsf STATUS,0
    return

In the device's PPI file, it has a directive for some devices to tell the compiler to use PIR3 and not the normal PIR1:

PIR3_TXRX=1    ; Whether the device requires PIR3 intead of PIR1 for the USART

And a type for different devices that need a different mechanism for peripherals:

UART_TYPE=1    ; The type of UART library to use for the device

Make sure you are using the latest version of the compiler, because microchip continuously change how devices operate. I have to jump through hoops to try and find the secrets of new devices that are not abvious and not clearly documented, unless a datasheet is scoured and compared with many others for a tiny change in an SFR.

PaoloFAP

; Code Produced by the Positron8 Compiler. Version 4.0.3.3
; Created and Written by Les Johnson.
; Compiler version for Paolo Faverzani

buy in 2023 ... now I upgrade to the  last version

PaoloFAP

RAM_BANKS=7     ; Amount of User RAM Banks (1 - 34)
UART_TYPE=1     ; The type of UART library to use for the device
UART=2          ; Amount of UARTs. 0, 1, or 2
USB=0           ; Whether the device has USB capabilities that the compiler supports
FLASH_WRITE=1   ; Whether the device has Self Modifying support. 0 = No, 1 = Read and Write, 2 = Read no Write
MSSP=1          ; 0 = None, 1 = Single MSSP, 2 = Dual MSSP, 3 = SSP Only, 0xFF = Unsuitable for the compiler
MSSP_TYPE=1     ; The type of MSSP library to use for the device
HPWM=2          ; Amount of PWM channels
HPWM_TYPE=1     ; The type of HPWM library to use for the device
BLOCK=32        ; Size of the Code Memory Write Segment (in Words)
ERASE=32        ; Size of the Code Memory Erase Segment (in Words)
OSCCALADDR=0    ; Address of the Oscillator Calibration Data
DEBUG=1         ; Whether the Device has Debug Capabilities (1 or 0)
PPS=1           ; Whether the device has PPS (Peripheral Pin Select))
PPS_TYPE=1      ; The type of PPS to use for the device
VCTR_ISR=0      ; Whether the device supports vectored interrupts (1 or 0)
PIR3_TXRX=1     ; Whether the device requires PIR3 intead of PIR1 for the USART
EE_ADDR=0xF000  ; The starting address of on-board eeprom
[INFOEND]

PaoloFAP

Updating to 4.0.3.8 problem solving

PaoloFAP

__hrsout1__
    movlb 0x0E
    btfss PIR3,PP_TX1IF
    bra $ - 1
    movlb 0x02
    movwf TXREG
    movlb 0x00
    bsf STATUS,0
    return

PaoloFAP

#6
After updating REDE = 0 not executed
now EUSART Trasmit data and REDE = 0 was executed

;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Device = 16F15324

Config1 FEXTOSC_OFF, RSTOSC_HFINT32, CLKOUTEN_OFF, CSWEN_OFF, FCMEN_OFF
Config2 MCLRE_ON, PWRTE_ON, LPBOREN_OFF, BOREN_OFF, BORV_LO, ZCD_OFF, PPS1WAY_ON, STVREN_OFF
Config3 WDTCPS_WDTCPS_31, WDTE_OFF, WDTCWS_WDTCWS_7, WDTCCS_SC
Config4 BBSIZE_BB512, BBEN_OFF, SAFEN_OFF, WRTAPP_OFF, WRTB_OFF, WRTC_OFF, WRTSAF_OFF, LVP_OFF
Config5 CP_OFF

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------
Declare Xtal = 32

Declare LCD_Type = 0
Declare LCD_DTPin PORTC.0
Declare LCD_ENPin = PORTA.5
Declare LCD_RSPin = PORTA.4
Declare LCD_Interface = 4
Declare LCD_Lines = 1

Declare Hserial_Baud = 9600
Declare HSerOut_Pin = PORTC.4
Declare HSerIn_Pin = PORTC.5

Dim FlashString1 As Flash8 = "VB_1317N", 0
Dim FlashString2 As Flash8 = "Bil_Test", 0
Dim FlashString3 As Flash8 = "JIG V1.0", 0

Dim bur[12] As Byte

Symbol REDE = PORTA.2

Symbol DIP1 = PORTC.0
Symbol DIP2 = PORTC.1
Symbol DIP3 = PORTC.2
Symbol DIP4 = PORTC.3

Dim DIP As Byte

Dim flag As Byte
Dim timeout As Byte

Dim err1 As Byte
Dim dat1 As Byte

Dim temp As Byte

Dim mstb As Byte
Dim madd As Byte
Dim mcom As Byte
Dim mlng As Byte
Dim mcks As Byte
Dim msum As Byte
Dim mlsb As Byte

Symbol stbok = flag.0
Symbol addok = flag.1
Symbol comok = flag.2
Symbol lngok = flag.3
Symbol chkok = flag.4
Symbol endok = flag.5
Symbol eradd = flag.6
Symbol erchk = flag.7

Dim ready As Byte

Dim r As Byte
Dim x As Byte
Dim y As Byte
Dim z As Byte
Dim ip As Byte
Dim iz As Byte

Dim BILAD As Byte

ANSELA = 0
ANSELC = 0

Input PORTC
Output PORTA

LATA = 0
LATC = 0

PORTA = 0
PORTC = 0

init:

'timer2 used for rx timeout 1,5 ms
T2CON = %01011001 ' pre 32 post 10
PR2 = 124 ' 125 uS x 10 1,25 ms
T2CLKCON = 2 ' clock timer fosc
T2HLT = %11100000 ' mode0 sincronized
TMR2 = 0

PIE3.5 = 1 ' int on recive uart1
PIE4.2 = 1 ' int on timer2 timeout
INTCON.6 = 1 ' int on periperal

On_Hardware_Interrupt GoTo Int_hand

init1:

ip = 0
iz = 0

ready = 0
flag = 0
err1 = 0

temp = PORTC
DIP = temp & %000011

Select Case DIP
      Case 0
      BILAD = 48
      Case 1
      BILAD = 49
      Case 2
      BILAD = 50
      Case 3
      BILAD = 51
End Select

' clear disply and start

Cls
Cursor 1,1
Print FlashString1
DelayMS 2000
Cursor 1,1
Print FlashString2
DelayMS 2000
Cursor 1,1
Print FlashString3
DelayMS 2000

Cursor 1,1
Print "BILA =", Dec2 BILAD

REDE = 1
r = 1

Select Case DIP
    Case 0
    HRSOut $0A,$30,$3B,$00,$95
    Case 1
    HRSOut $0A,$31,$3B,$00,$94
    Case 2
    HRSOut $0A,$32,$3B,$00,$93
    Case 3
    HRSOut $0A,$33,$3B,$00,$92
End Select

DelayUS 100

REDE = 0
r = 0

INTCON.7 = 1 ' enable int
T2CON.7 = 1

While timeout = 0
Wend

If timeout = 1 Then
    If flag = %00111111 Then
        If ready > 0 Then
            Cursor 1,1
            Print "BILA__OK"
        Else
            Cursor 1,1
            Print "Ready =0"
        EndIf
    Else
        Cursor 1,1
        Print "Flag= ",Hex2 flag
    EndIf
EndIf

main:

If err1.1 = 1 Then
    RC2STA.4 = 0
    RC2STA.4 = 1
    err1 = 0
EndIf

GoTo main


Int_hand:
Context Save

If PIR3.5 = 1 Then ' rxbyte pronto
    TMR2 = 0 ' clear timeout
    err1 = RC1STA & %00000110
    dat1 = RC1REG

    If r = 0 Then
        ip = ip + 1
        bur[ip] = dat1

        If endok = 1 Then
            timeout = 1
            GoTo scarta
        EndIf

        iz = iz + 1
        Select Case iz

        Case 1
        If dat1 <> $0A Then
            iz = 0
            ready = 0
        Else
            stbok = 1
            ready = 1
            T2CON.7 = 1 ' timer2 on
        EndIf

        Case 2
        If dat1 = $FF Then
            madd = dat1
            If ready > 0 Then
                ready = 2
            EndIf
        Else
            ready = 0
        EndIf

        Case 3
        If dat1 = $5A Then
            comok = 1
            mcom = dat1
            If ready > 0 Then
              ready = 3
            EndIf
        Else
            ready = 0
        EndIf

        Case 4
        If dat1 = 5 Then
            mlng = 5
            mlsb = 9
            lngok = 1
            If ready > 0 Then
                ready = 4
            EndIf
        Else
            ready = 0
        EndIf

        Case 5
        If mlsb = 9 Then
            msum = madd + mcom + mlng + dat1
            If ready > 0 Then
                ready = 5
            EndIf
        EndIf

        Case Else
        If iz > mlsb Then
            timeout = 1
            T2CON.7 = 0
            GoTo scarta
        EndIf

        If iz < mlsb Then
            msum = msum + dat1
            If ready > 0 Then
                ready = ready + 1
            EndIf
        Else
            msum = msum + dat1
            T2CON.7 = 0
            endok = 1
            If msum = 0 Then
                chkok = 1
                If ready > 0 Then
                    ready = ready + 1
                EndIf
            Else
                chkok = 0
                erchk = 1
                ready = 0
            EndIf
        EndIf
        EndSelect
    EndIf
scarta:
EndIf

If PIR4.2 = 1 Then
    PIR4.2 = 0
    T2CON.7 = 0
    TMR2=0
    timeout = 1
EndIf

Context Restore


PaoloFAP

Sorry

before updating REDE = 0 not executing
Serial data not trasmitting

After updating all is ok