News:

;) This forum is the property of Proton software developers

Main Menu

Pic18F46Q43 RSIN issue

Started by Jamie, Mar 05, 2023, 05:39 PM

Previous topic - Next topic

Jamie

Hello Forum, I would like some help on receiving data on Uart1 of the 18F46Q43
I have it setup like this

Device 18F46Q43                 
Declare Xtal = 64
Declare Hserial1_Baud = 9600       
Declare HRSOut1_Pin = PORTC.6       
Declare HRSIn1_Pin = PORTC.7


Dim RXCommand as byte
Dim X as byte

Start:

HRSOutLn "Count ",dec X
RXCommand = HRSIn1, {500 , NoDATA}   'also tried RXCommand = HRSIn, {500 , NoDATA}
if RXCommand = 65 then
toggle led1
endif

NoDATA:
toggle led2
x = x + 1
goto start



Config_Start
    FEXTOSC = Off                 ' Oscillator not enabled
    RSTOSC = HFINTOSC_64MHZ       ' 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 = On                    ' Writing to NOSC and NDIV is allowed
    FCMEN = On                    ' Fail-Safe Clock Monitor enabled
    MCLRE = EXTMCLR               ' EXTERNAL RESET ENABLED
'    MCLRE = INTMCLR               ' MCLR pin enabled
    PWRTS = PWRT_64               ' PWRT set at 64ms
    MVECEN = Off                  ' Interrupt contoller does not use vector table to prioritze interrupts
    IVT1WAY = Off                 ' IVTLOCKED bit can be cleared and set repeatedly
    LPBOREN = On                  ' Low-Power BOR enabled
    BOREN = SBORDIS               ' Brown-out Reset enabled. SBOREN bit is ignored
    BORV = VBOR_2P85              ' Brown-out Reset Voltage (VBOR) set to 2.8V
    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 = On                   ' Stack full/underflow will 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
    Debug = Off                   ' Background Debugger 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
    Cp = Off                      ' PFM and Data EEPROM code protection disabled
Config_End



It transmits great but wont receive.

I've also tried
RXCommand = HRSIn1 and it just sits at this command.
I've tried an 18F46K22 and it works with the above code so I'm thinking the RX on the UART isnt being setup properly by me.

I've gone over the datasheet and dont see what i'm missing. I would appreciate any ideas.

Thanks

Jamie

Jamie

With the following code:

START:

HSerIn1 1000, NoDATA, [getbyte]
HRSOut "getbyte = ",Dec getbyte,13,10

If getbyte = 65 Then                          ' "D" - Upload memory banks via terminal
    High FW_Led
EndIf
If getbyte = 66 Then                          ' "D" - Upload memory banks via terminal
    Low FW_Led
EndIf
DelayMS 1000
GoTo START

NoDATA:

HRSOut "RX TIMEOUT, BYTE= ",Dec getbyte,13,10
DelayMS 500

GoTo START


it outputs:
getbyte = 65
getbyte = 65
getbyte = 65 over and over..

when I hit B its output changes to
RX TIMEOUT, BYTE= 65
RX TIMEOUT, BYTE= 65
RX TIMEOUT, BYTE= 65 over and over

Then if I hit B once more(twice total) its output is still
RX TIMEOUT, BYTE= 65
RX TIMEOUT, BYTE= 65
RX TIMEOUT, BYTE= 65 over and over

but when I reset the Pic it shows

getbyte = 66
getbyte = 66
getbyte = 66 over and over..

So it is receiving the B input but cant see why the program isn't working properly or why I have to hit B twice.

here is the uart code

; UART1_ACTUALBAUD = 9598.08
; UART1_BAUDERROR = 0.02
    MOVLB HIGH(U1CON0)
    MOVLW 0X82
    MOVWF U1BRGL
    MOVLW 0X06
    MOVWF U1BRGH
    MOVLW 0XB0
    MOVWF U1CON0
    MOVLW 0X80
    MOVWF U1CON1
; CONFIGURE HRSOUT1 PPS
    MOVLW _PPS_FN_TX1
    MOVFF WREG,RC6PPS
; CONFIGURE HRSIN1 PPS
    MOVLW 0X17
    MOVFF WREG,U1RXPPS
    MOVLB HIGH(U2CON0)
    MOVLW 0X67
    MOVWF U2BRGL
    CLRF U2BRGH
    MOVLW 0X00
    MOVWF U2CON0
    MOVLW 0X80
    MOVWF U2CON1
    MOVLB 5
    MOVLB HIGH(NVMCON1)
    CLRF NVMCON1,1

top204

See the post:

Positron Corrections Update 4.0.3.3-1.1.1.5

Microchip made some very subtle changes to the Q4x type devices when receiving, and I missed them.

I tested the corrections on a Q43 device and all seems to work nicely now.

Jamie

Thank you very much!!