News:

;) This forum is the property of Proton software developers

Main Menu

18F47Q84 serial communication

Started by Amateurtje, May 24, 2025, 11:45 AM

Previous topic - Next topic

Amateurtje

After a lot of issues I got something on my screen with my new 18F47Q84.. Now, some of the interrupts, communications etc are still not worink, so I go through them 1 by 1)

I have a very simple test program made  (also with chatgpt, but he does not know a lot of proton..) for serial communication on uart1. This has the rx on rc6. Very basic. However, i do not see any signal coming from the rc6 port.. Anybody any idea?



Device = 18F47Q84

Declare Xtal = 40
Declare HRSOut1_Pin = PORTC.6    ' Verplicht voor HRSOut1 om te werken

Config_Start
    RSTOSC = EXTOSC
    FEXTOSC = HS
    LVP = OFF
    XINST = OFF
    PPS1WAY = OFF
Config_End

' UART1 setup (RC6 = TX, RC7 = RX)
U1CON0 = %00010000           ' TXEN = 1
U1CON1 = %10000000           ' RXEN = 1
U1BRGL = 68                  ' 57600 baud bij 40 MHz
U1BRGH = 0

U1RXPPS = %00011111          ' RC7 = RX
RC6PPS = %001000             ' RC6 = TX (functiecode UART1 TX)

TRISC.6 = 0                  ' TX als output
TRISC.7 = 1                  ' RX als input

Main:
    HRSOut1 "UART1 OK",13
    DelayMS 1000
    GoTo Main

trastikata

Hello Amateurtje,

if I may suggest to try unlocking the PPS first before you change pin functions. Once the PPS ha been assigned, set the port direction i.e. input or output.

Amateurtje

Hi Trastikata,

Thanks for the input. Unfortunatly this did bring anything.

My latest testprogram is integrated with the LCD so that I cna see something but unfortunatly, there is still nothing coming from the Comport. I measured the complete line and it is nicely connected with PortC.6....

Device = 18F47Q84

Declare Xtal = 40


Config_Start
 '' FEXTOSC = OFF    ;Oscillator not enabled
 '' RSTOSC = HFINTOSC_64MHZ    ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
  FEXTOSC = HS    ;Oscillator not enabled
  RSTOSC = EXTOSC    ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1

  CLKOUTEN = OFF    ;CLKOUT function is disabled
  PR1WAY = OFF    ;PRLOCKED bit can be set and cleared repeatedly
  CSWEN = OFF    ;The NOSC and NDIV bits cannot be changed by user software
  JTAGEN = OFF    ;Disable JTAG Boundary Scan mode, JTAG pins revert to user functions
  FCMEN = OFF    ;Fail-Safe Clock Monitor disabled
  FCMENP = OFF    ;FSCM timer will not set FSCMP bit or OSFIF interrupt on Primary XTAL failure
  FCMENS = OFF    ;FSCM timer will not set FSCMS bit or OSFIF interrupt on Secondary XTAL failure
  MCLRE = EXTMCLR    ;If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
  PWRTS = PWRT_OFF    ;PWRT is disabled
  MVECEN = OFF    ;Interrupt contoller does not use vector table to prioritze interrupts
  IVT1WAY = OFF    ;IVTLOCKED bit can be cleared and set repeatedly
  LPBOREN = OFF    ;Low-Power BOR disabled
  BOREN = SBORDIS    ;Brown-out Reset enabled , SBOREN bit is ignored
  BORV = VBOR_1P9    ;Brown-out Reset Voltage (VBOR) set to 1.9V
  ZCD = OFF    ;ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
  PPS1WAY = OFF    ;PPSLOCKED bit can be set and cleared repeatedly (subject to the unlock sequence)
  STVREN = OFF    ;Stack full/underflow will not cause Reset
  LVP = OFF    ;HV on MCLR/VPP must be used for programming
  XINST = OFF    ;Extended Instruction Set and Indexed Addressing Mode disabled
  WDTCPS = WDTCPS_31    ;Divider ratio 1:65536; software control of WDTPS
  WDTE = OFF    ;WDT Disabled; SWDTEN is ignored
  WDTCWS = WDTCWS_7    ;window always open (100%); software control; keyed access not required
  WDTCCS = SC    ;Software Control
  BBSIZE = BBSIZE_512    ;Boot Block size is 512 words
  BBEN = OFF    ;Boot block disabled
  SAFEN = OFF    ;SAF disabled
  WRTB = OFF    ;Boot Block not Write protected
  WRTC = OFF    ;Configuration registers not Write protected
  WRTD = OFF    ;Data EEPROM not Write protected
  WRTSAF = OFF    ;SAF not Write Protected
  WRTAPP = OFF    ;Application Block not write protected
  BOOTPINSEL = RC5    ;CRC on boot output pin is RC5
  BPEN = OFF    ;CRC on boot output pin disabled
  ODCON = OFF    ;Pin drives both high-going and low-going signals
  Cp = OFF    ;PFM and Data EEPROM code protection disabled
  BOOTSCEN = OFF    ;CRC on boot will not include the boot area of program memory in its calculation
  BOOTCOE = HALT    ;CRC on boot will stop device if error is detected in boot areas
  APPSCEN = OFF    ;CRC on boot will not include the application area of program memory in its calculation
  SAFSCEN = OFF    ;CRC on boot will not include the SAF area of program memory in its calculation
  DATASCEN = OFF    ;CRC on boot will not include data EEPROM in its calculation
  CFGSCEN = OFF    ;CRC on boot will not include the configuration fuses in its calculation
  COE = HALT    ;CRC on boot will stop device if error is detected in non-boot areas
  BOOTPOR = OFF    ;CRC on boot will not run
  BCRCPOLT = hFF    ;Bits 31:24 of BCRCPOL are 0xFF
  BCRCPOLU = hFF    ;Bits 23:16 of BCRCPOL are 0xFF
  BCRCPOLH = hFF    ;Bits 15:8 of BCRCPOL are 0xFF
  BCRCPOLL = hFF    ;Bits 7:0 of BCRCPOL are 0xFF
  BCRCSEEDT = hFF    ;Bits 31:24 of BCRCSEED are 0xFF
  BCRCSEEDU = hFF    ;Bits 23:16 of BCRCSEED are 0xFF
  BCRCSEEDH = hFF    ;Bits 15:8 of BCRCSEED are 0xFF
  BCRCSEEDL = hFF    ;Bits 7:0 of BCRCSEED are 0xFF
  BCRCEREST = hFF    ;Bits 31:24 of BCRCERES are 0xFF
  BCRCERESU = hFF    ;Bits 23:16 of BCRCERES are 0xFF
  BCRCERESH = hFF    ;Bits 15:8 of BCRCERES are 0xFF
  BCRCERESL = hFF    ;Bits 7:0 of BCRCERES are 0xFF
  CRCPOLT = hFF    ;Bits 31:24 of CRCPOL are 0xFF
  CRCPOLU = hFF    ;Bits 23:16 of CRCPOL are 0xFF
  CRCPOLH = hFF    ;Bits 15:8 of CRCPOL are 0xFF
  CRCPOLL = hFF    ;Bits 7:0 of CRCPOL are 0xFF
  CRCSEEDT = hFF    ;Bits 31:24 of CRCSEED are 0xFF
  CRCSEEDU = hFF    ;Bits 23:16 of CRCSEED are 0xFF
  CRCSEEDH = hFF    ;Bits 15:8 of CRCSEED are 0xFF
  CRCSEEDL = hFF    ;Bits 7:0 of CRCSEED are 0xFF
  CRCEREST = hFF    ;Bits 31:24 of CRCERES are 0xFF
  CRCERESU = hFF    ;Bits 23:16 of CRCERES are 0xFF
  CRCERESH = hFF    ;Bits 15:8 of CRCERES are 0xFF
  CRCERESL = hFF    ;Bits 7:0 of CRCERES are 0xFF
Config_End

Declare Optimiser_Level = 3

U1RXPPS = %00011111          ' RC7 = RX
RC6PPS = %001000            ' RC6 = TX (functiecode UART1 TX)
Declare HRSOut1_Pin = PORTC.6    ' Verplicht voor HRSOut1 om te werken

TRISA = %11110000                                ;
TRISB = %11001111                                ; PORTB connected to LCD
TRISC = %10010110                                ;
TRISD = %10001010
TRISE = %00001101
Declare LCD_Lines 4                          ;TMR0
Declare LCD_DTPin  PORTA.0
Declare LCD_ENPin  PORTB.5
Declare LCD_RSPin  PORTB.4
  Symbol Hoofdstroom = PORTC.0
  Symbol DTA = PORTD.5    ; op 14  output
Symbol Clock=PORTD.4    ; op pin 11  output
Symbol Latch = PORTC.5    ; op pin 12  output
Symbol swAAN  = 0 
 
' UART1 setup (RC6 = TX, RC7 = RX)
U1CON0 = %00010000          ' TXEN = 1
U1CON1 = %10000000          ' RXEN = 1
U1BRGL = 68                  ' 57600 baud bij 40 MHz
U1BRGH = 0
''Declare uart1_baudrate = 57600  ' Verplicht voor HRSOut1 om te werken


TRISC.6 = 0                  ' TX als output
TRISC.7 = 1                  ' RX als input
Symbol CREN1 = U1CON0.4
Symbol TXEN1 = U1CON0.5;Symbol TXEN1 = TXSTA.5

Clear
DelayMS 1000
Cls
DelayMS 500

    DTA = 1                                            ;A0
        Clock = 1                                          ;A1
        Latch = 0 

 Hoofdstroom=swAAN
Main:
      Print "HALLO"
     
          CREN1 = 0
    TXEN1 = 1
    HRSOut1 "UART1 OK",13
    DelayMS 1
    DelayMS 1
    TXEN1 = 0
  ''  PORTC.6 = 1
    CREN1 = 1
      ''HRSOut1 "UART1 OK",13
    DelayMS 1000
 
Print At 3,2, "Hallo"
GoTo Main


I need these DTA,CLock,LAtch and Hoofdstroom to power the lcd on my pcb but  nothing happens on the uart. Without closing and opening the TXen1 it does not come to the second print command, so it blocks the program... With this code it displays nicely the print commands, but not 1 pulse on the rc6...

RGV250

As Trastikata says, you have to unlock the PPS which you are not doing in your program.

This is an example from a program I have, I believe this method does the unlock for you.
    PPS_Output(cOut_Pin_RP3, cOut_Fn_U1TX)  ' Make Pin RB3 U1TX
It was from a 16 bit prog but it is probably the same.

Bob

Amateurtje

Hi Bob, I do not know where of how I can use in proton:

 PPS_Output(cOut_Pin_RP3, cOut_Fn_U1TX)  ' Make Pin RB3 U1TX

But does the following not the settings of the PPS?:

U1RXPPS = %00011111          ' RC7 = RX
RC6PPS = %001000             ' RC6 = TX (functiecode UART1 TX)

RGV250

Hi,
I don't know as I have only used it in PIC24.

One thing I have noticed is you are using software serial to set the port up but it is not needed with hardware serial.
This is all you need to set the BAUD rate
    Declare Hserial_Baud = 57600             ' UART1 baud rate

Bob

Amateurtje

#6
I thought so also, so I tried but chatgpt was saying this but also, trying some different things :)..

I just found out:

With just toggling port C.7 and PortC.6, only portc.7 is toggling... I cna not imagine I might have a broken chip but i am going to change the chip while this is really strange...... MAybe I am spending days with a broken pic  ;D

I will let you know :

EDIT:
Changed the PIC:, The toggle script now works perfectly.:PortC.6 is for sure connected perfectly...--> Still NO TTL coming from pic.... pffff

trastikata

It's always good advice to check the datasheet ...

- it looks like the PPS is unlocked by default, thus no PPS unlocking is required.
- However the PPS seems to be incorrectly assigned.

I'll let you re-check the PPS assignment before I post what I think should be the registers settings.  ;)

trastikata

Quote from: Amateurtje on May 24, 2025, 05:07 PMBut does the following not the settings of the PPS?:

U1RXPPS = %00011111          ' RC7 = RX
RC6PPS = %001000            ' RC6 = TX (functiecode UART1 TX)

OK, here's what I get from the datasheet:

U1RXPPS = %010111            ' RC7 = RX
RC6PPS = 0x20                ' RC6 = TX (functiecode UART1 TX) 0x20 = %00100000

Amateurtje

I just removed them and it started to work. Of course now tested your assignment and it also worked. Stupid from me not to re-check this.. Thanks a lot...nice.. With this I hope to get my 2 comports to work again.. (this assignment i will need for sure for my second port :))

evenry day that I get 1 step closer to get it to work again is a good day... Thanks

Sommi

Will hrsout5 be supported in the near future?
KISS - keep it simple and stupid

Amateurtje

this code has an interrupt receive and a transmit on 57600 baud.. IT works for me:
Device = 18F47Q84

Declare Xtal = 40


Config_Start
 '' FEXTOSC = OFF ;Oscillator not enabled
 '' RSTOSC = HFINTOSC_64MHZ ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
  FEXTOSC = HS ;Oscillator not enabled
  RSTOSC = EXTOSC ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1

  CLKOUTEN = OFF ;CLKOUT function is disabled
  PR1WAY = OFF ;PRLOCKED bit can be set and cleared repeatedly
  CSWEN = OFF ;The NOSC and NDIV bits cannot be changed by user software
  JTAGEN = OFF ;Disable JTAG Boundary Scan mode, JTAG pins revert to user functions
  FCMEN = OFF ;Fail-Safe Clock Monitor disabled
  FCMENP = OFF ;FSCM timer will not set FSCMP bit or OSFIF interrupt on Primary XTAL failure
  FCMENS = OFF ;FSCM timer will not set FSCMS bit or OSFIF interrupt on Secondary XTAL failure
  MCLRE = EXTMCLR ;If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
  PWRTS = PWRT_OFF ;PWRT is disabled
  MVECEN = OFF ;Interrupt contoller does not use vector table to prioritze interrupts
  IVT1WAY = OFF ;IVTLOCKED bit can be cleared and set repeatedly
  LPBOREN = OFF ;Low-Power BOR disabled
  BOREN = SBORDIS ;Brown-out Reset enabled , SBOREN bit is ignored
  BORV = VBOR_1P9 ;Brown-out Reset Voltage (VBOR) set to 1.9V
  ZCD = OFF ;ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
  PPS1WAY = OFF ;PPSLOCKED bit can be set and cleared repeatedly (subject to the unlock sequence)
  STVREN = OFF ;Stack full/underflow will not cause Reset
  LVP = OFF ;HV on MCLR/VPP must be used for programming
  XINST = OFF ;Extended Instruction Set and Indexed Addressing Mode disabled
  WDTCPS = WDTCPS_31 ;Divider ratio 1:65536; software control of WDTPS
  WDTE = OFF ;WDT Disabled; SWDTEN is ignored
  WDTCWS = WDTCWS_7 ;window always open (100%); software control; keyed access not required
  WDTCCS = SC ;Software Control
  BBSIZE = BBSIZE_512 ;Boot Block size is 512 words
  BBEN = OFF ;Boot block disabled
  SAFEN = OFF ;SAF disabled
  WRTB = OFF ;Boot Block not Write protected
  WRTC = OFF ;Configuration registers not Write protected
  WRTD = OFF ;Data EEPROM not Write protected
  WRTSAF = OFF ;SAF not Write Protected
  WRTAPP = OFF ;Application Block not write protected
  BOOTPINSEL = RC5 ;CRC on boot output pin is RC5
  BPEN = OFF ;CRC on boot output pin disabled
  ODCON = OFF ;Pin drives both high-going and low-going signals
  Cp = OFF ;PFM and Data EEPROM code protection disabled
  BOOTSCEN = OFF ;CRC on boot will not include the boot area of program memory in its calculation
  BOOTCOE = HALT ;CRC on boot will stop device if error is detected in boot areas
  APPSCEN = OFF ;CRC on boot will not include the application area of program memory in its calculation
  SAFSCEN = OFF ;CRC on boot will not include the SAF area of program memory in its calculation
  DATASCEN = OFF ;CRC on boot will not include data EEPROM in its calculation
  CFGSCEN = OFF ;CRC on boot will not include the configuration fuses in its calculation
  COE = HALT ;CRC on boot will stop device if error is detected in non-boot areas
  BOOTPOR = OFF ;CRC on boot will not run
  BCRCPOLT = hFF ;Bits 31:24 of BCRCPOL are 0xFF
  BCRCPOLU = hFF ;Bits 23:16 of BCRCPOL are 0xFF
  BCRCPOLH = hFF ;Bits 15:8 of BCRCPOL are 0xFF
  BCRCPOLL = hFF ;Bits 7:0 of BCRCPOL are 0xFF
  BCRCSEEDT = hFF ;Bits 31:24 of BCRCSEED are 0xFF
  BCRCSEEDU = hFF ;Bits 23:16 of BCRCSEED are 0xFF
  BCRCSEEDH = hFF ;Bits 15:8 of BCRCSEED are 0xFF
  BCRCSEEDL = hFF ;Bits 7:0 of BCRCSEED are 0xFF
  BCRCEREST = hFF ;Bits 31:24 of BCRCERES are 0xFF
  BCRCERESU = hFF ;Bits 23:16 of BCRCERES are 0xFF
  BCRCERESH = hFF ;Bits 15:8 of BCRCERES are 0xFF
  BCRCERESL = hFF ;Bits 7:0 of BCRCERES are 0xFF
  CRCPOLT = hFF ;Bits 31:24 of CRCPOL are 0xFF
  CRCPOLU = hFF ;Bits 23:16 of CRCPOL are 0xFF
  CRCPOLH = hFF ;Bits 15:8 of CRCPOL are 0xFF
  CRCPOLL = hFF ;Bits 7:0 of CRCPOL are 0xFF
  CRCSEEDT = hFF ;Bits 31:24 of CRCSEED are 0xFF
  CRCSEEDU = hFF ;Bits 23:16 of CRCSEED are 0xFF
  CRCSEEDH = hFF ;Bits 15:8 of CRCSEED are 0xFF
  CRCSEEDL = hFF ;Bits 7:0 of CRCSEED are 0xFF
  CRCEREST = hFF ;Bits 31:24 of CRCERES are 0xFF
  CRCERESU = hFF ;Bits 23:16 of CRCERES are 0xFF
  CRCERESH = hFF ;Bits 15:8 of CRCERES are 0xFF
  CRCERESL = hFF ;Bits 7:0 of CRCERES are 0xFF
 
Config_End

Declare Optimiser_Level = 3
TRISA = %11110000                                 ;
TRISB = %11001111                                 ; PORTB connected to LCD
TRISC = %10010110                                 ;
TRISD = %10001010
TRISE = %00001101

U1RXPPS = %010111            ' RC7 = RX
RC6PPS = 0x20                ' RC6 = TX (functiecode UART1 TX) 0x20 = %00100000

Declare Hserial1_Baud = 57600
Declare HRSOut1_Pin = PORTD.6    ' Verplicht voor HRSOut1 om te werken
Declare HRSIn1_Pin = PORTD.7    ' Verplicht voor HRSOut1 om te werken

U1BRGL = 42''57600      ' of 173 als je afrondt
U1BRGH = 0

Declare LCD_Lines 4                          ;TMR0
Declare LCD_DTPin  PORTA.0
Declare LCD_ENPin  PORTB.5
Declare LCD_RSPin  PORTB.4
  Symbol Hoofdstroom = PORTC.0
  Symbol DTA = PORTD.5     ; op 14  output
Symbol Clock=PORTD.4    ; op pin 11  output
Symbol Latch = PORTC.5    ; op pin 12  output
Symbol swAAN  = 0 
 
U1CON0 = %00010000     ' MODE=000 (Async 8-bit), TXEN=1
U1CON1 = %10000000     ' RXEN=1
U1CON2 = 0             ' Geen flow control
Symbol ontvang = U1RXB ''RCREG2

''staat nu hier op high priority, moet dna mss naar low voor uart
IPR4.0 = 1 ''(low) U1RXIP UART 1 Receive Interrupt Priority
IPR4.3=1 ''U1IP UART1 Interrupt Priority


PIE4.0  = 1''Bit 0 – U1RXIE UART 1 Receive Interrupt Enable
PIE4.2 = 1 ''Bit 2 – U1EIE UART1 Framing Error Interrupt Enable
PIE4.3 = 1 ''Bit 3 – U1IE UART1 Interrupt Enable
On_Hardware_Interrupt GoTo INTERRUPT_ROUTINE              ' WHERE TO GO ON AN INTERRUPT
 Dim InterruptByte As Byte
    Dim ff As Byte
 Symbol U2EIF = PIR4.2  '' framing error
 Symbol U1RXIF   = PIR4.0             ' Receive interrupt flag
 Symbol OERR = U1ERRIR
 Symbol FERR =  PIR4.2
$define __DEBUG_UART
$define __DEBUG_UART_SHOW_BAUD

Symbol CREN = U1CON0.4
Symbol TXEN = U1CON0.5;Symbol TXEN1 = TXSTA.5

Dim GIE As INTCON0.7
GIE =1
  Dim ByteIn As Byte     
Clear

DelayMS 1000
Cls
DelayMS 500

DTA = 1                                             ;A0
Clock = 1                                           ;A1
Latch = 0 

Hoofdstroom=swAAN
 
Main:
  TIMEOUT:
      Print "HALLO"
Print At 4,4, Dec ff
    CREN = 0
    TXEN = 1
     HRSOut1 255 ,ByteIn   ,1,10,100, 255    ,1,10,100,255    ,1,10,100,255    ,1,10,100
    DelayMS 1
    DelayMS 1
    TXEN = 0
    CREN = 1     
          DelayMS 100   
   Print At 2,3, Dec3 ByteIn
 
Print At 3,2, "Hallo"
GoTo Main


INTERRUPT_ROUTINE:
Context Save;   

If U1RXIF = 1 Then 
     InterruptByte =ontvang
    If U1ERRIR.1 = 1 Then   ' OERR = Overrun Error
        U1ERRIR = 0         ' Wissen van alle foutflags
     Else
  If FERR = 1 Or OERR = 1 Then
        CREN = 0
        FERR =0
        CREN=1
    Else
         ff=InterruptByte
   End If
  End If
End If

Context Restore