News:

Let's find out together what makes a PIC Tick!

Main Menu

Issue with 16F15376 Uart pps

Started by JonW, Jan 14, 2023, 05:03 PM

Previous topic - Next topic

JonW

There seems to be an issue with the PPS and PIC16F15376

Code here gives the errors that RX2PPS is undefined and even if i add RX2PPS to the PPI file it still errors trying to setup RX3PPS but this does not exist.  I am presuming HRSIN = UART1 and HRSIN2 = UART2


'------------------------------------------------------------------------------------------------
'                                        COMPILER SETUP
'------------------------------------------------------------------------------------------------
Device = 16F15376
Declare Xtal = 32

Declare CCP1_Pin PORTC.1
Declare CCP2_Pin PORTC.2

Declare HRSIn_Pin  PORTC.6
Declare HRSOut_Pin PORTC.7
Declare HSerial_Terminator = CRLF
Declare Hserial_Baud   = 115200


Declare HRSIn2_Pin  PORTD.1
Declare HRSOut2_Pin PORTD.0
'DECLARE HSERIAL1_TERMINATOR = CRLF
Declare Hserial2_Baud   = 19200

'------------------------------------------------------------------------------------------------
'                                       INCLUDE FILES
'------------------------------------------------------------------------------------------------

'------------------------------------------------------------------------------------------------
'                                       CONSTANTS AND ALIAS
'------------------------------------------------------------------------------------------------
 Symbol RX1_BUFERSIZE = 20


'------------------------------------------------------------------------------------------------
'                                    VARIABLE DECLARATION
'------------------------------------------------------------------------------------------------
Dim bTEMP       As Byte
Dim wTEMP       As Word
Dim ltemp       As Long
Dim dTEMP       As Dword
'------------------------------------------------------------------------------------------------
'                                      PORT DECLARATION
'------------------------------------------------------------------------------------------------
 Dim LED1       As LATE.0


'------------------------------------------------------------------------------------------------
'                                    RESET & DEVICE SETUP
'------------------------------------------------------------------------------------------------

RRESET:
        INTCON  =   %00000000
        PIE0    =   %00000000
        PIE1    =   %00000000
        PIR0    =   %00000000
        PIR3    =   %00000000           ' RC1 & RC2 IF
        TRISA =     %00000000           ' ALL OUTPUT
        TRISB =     %01000001           ' SEE PORT MAP
        TRISC =     %10000000           ' SERIAL PORT
        WPUA =      %00000000           ' NO PULLUPS
        WPUB =      %00000000           ' NO PULLUPS
        WPUC =      %00000000           ' NO PULLUPS
'------------------------------------------------------------------------------------------------
'                                        PPS SETUP
'------------------------------------------------------------------------------------------------
'NOTE THE COMPILER SHOULD AUTOMATICALLY SET THE CORRESPONDING PPS FOR ALL INBULT HARDWARE FUNCTIONS

'------------------------------------------------------------------------------------------------
'                                          MAIN CODE
'------------------------------------------------------------------------------------------------

MAINLOOP:
        DelayMS   500
        Toggle    LED1
        HRSOut     "HELLO UART1"
        HRSOut2    "HELLO UART2"
        GoTo      MAINLOOP


'------------------------------------------------------------------------------------------------
'                                          PROCEDURES
'------------------------------------------------------------------------------------------------



'------------------------------------------------------------------------------------------------
'                                            TABLES
'------------------------------------------------------------------------------------------------


'-------------------------------------------------------------------------------
'**** Added by Fuse Configurator ****
' Use the Fuses Tab to change these settings

Config1 FEXTOSC_OFF, RSTOSC_HFINT32, CLKOUTEN_OFF, CSWEN_ON, FCMEN_ON
Config2 MCLRE_ON, PWRTE_OFF, LPBOREN_ON, BOREN_SBOREN, BORV_LO, ZCD_OFF, PPS1WAY_OFF, STVREN_ON
Config3 WDTCPS_WDTCPS_31, WDTE_SWDTEN, WDTCWS_WDTCWS_7, WDTCCS_SC
Config4 BBSIZE_BB512, BBEN_OFF, SAFEN_OFF, WRTAPP_OFF, WRTB_OFF, WRTC_OFF, WRTSAF_OFF, LVP_ON
Config5 CP_OFF

'**** End of Fuse Configurator Settings ****
'------------------


Compiler ASM setting up RX3PPS


; UART2_ACTUALBAUD = 19230.77
; UART2_BAUDERROR = 0.16
    MOVLB 0X14
    BCF BAUD2CON,PP_BRG16
    MOVLW 0X67
    MOVWF SP2BRG
    CLRF SP2BRGH
    MOVLW 0X24
    MOVWF TX2STA
    MOVLW 0X90
    MOVWF RC2STA
; CONFIGURE HRSOUT2 PPS
    MOVLB 0X3E
    MOVLW _PPS_FN_TX2
    MOVWF RD0PPS
; CONFIGURE HRSIN2 DEFAULT PPS
    MOVLW 0X19
    MOVLB ((RX2PPS)>>7)
    MOVWF RX2PPS
; CONFIGURE HRSOUT3 DEFAULT PPS
    MOVLB 0X3E
    MOVWF RC6PPS
; CONFIGURE HRSIN3 DEFAULT PPS
    MOVLW 0X17
    MOVLB ((RX3PPS)>>7)
    MOVWF RX3PPS
    MOVLB 0X00
    CLRF BPF   

Yasin

Hello, I assume it's a PPI file error.


Hope this can solve the problem
Dim RX2PPS As RX2DTPPS
Dim RX3PPS As RX2DTPPS

JonW

#2
Hi Yasin

Thanks for trying but I also tried something similar by adjusting the PPI files and although it compiles the FW hangs in the main routine.  I imagine the only way to work around is to manually configure the second Uart and PPS.

Seems to also be an issue with HRSOUT2 call in the checking of PIR4 register for TX2IF when its in PIR3 so the code is hanging

__hrsout2__
    movlb 0x0E
    btfss PIR4,PP_TX2IF
    bra $ - 1
    movlb 0x14
    movwf TX2REG
    movlb 0x00
    bsf STATUS,0
    return 


I can now get the code to run modifying the PPI adding what you posted in the main bas file or adding RX2PPS and pointing RX3PPS to RX2PPS register location in the PPI file of the processor and further editing the PPI PIR4 register pointing to PIR3 however, this will now limit PIR4 use within the compiler. 
But now  cannot get both UART1 and UART2 running at the same time with hrsout commands.  In addition the CCP1 and CCP2 don't seem to work at all with HPWM commands but I have not looked at the ASM yet.  Ill see if I can get these functions going through procs  in the short term


Hopefully this will be a quick fix for Les





top204

#3
Sorry about that Jon

Microchip have renamed some SFRs and also used different SFRs for the USARTs on thse devices.

I now have it sorted in the compiler's code generator, I think, because I do not have one of those devices, but it seems to match the datasheet and I have made some changes to the device's .ppi and .def files so it will use either SFR name.

For the HPWM, can you do me a favour please?

Issue the declare: "Declare HPWM_Type = ", and use values 1 to 9 in it, then compile and test, if it does not create assember errors. Each of these values creates new assembler code generation for the requirements of the many different mechanisms microchip have with the devices, so one of them may work, and some will give assembler errors for SFRs and bit names that are not present on that particular deivce, or the device uses a different PWM mechanism. Once I know which value works, I will alter the ppi file value. i.e. "HPWM_Type", if not, I will create, yet another assembler library routine for, yet another, change by microchip for no real reason, except to "change for the sake of change". :-)


JonW

Hi Les.

Thanks for the quick reply. Sure will try the hpwm options in the morning. Thought it would be the microchip random register generatior.  Must be a nightmare getting every command running on all the parts.

I did get the uarts going with procs and is a good exercise to become familiar with the hardware.  Played around with the PPS mapping uart outputs to multiple pins simultaneously. 

If you PM me your address I'll get a curiosity nano with a 16F15376 sent to you tomorrow.

Cheers

Jon


JonW

Hi Les

I tried the different PWM 1-9.  1 and 6 compile without errors however they both do not work.  Tried declaring with CCP1 and HPWM1 etc and makes no difference.  Note this device has a further 4 PWM channels 3 - 6 but again it states the device doesn't have enough PWM channels (presume its limited via PPI).


top204

Jon.... I cannot thank you enough. :-)

The three units arrived this morning. i.e. The 14-bit Nano, 18F Nano, and a very interesting ARM M0+ Nano board.

I'll get the compiler working correctly with the 16F15376, and test the new additions to the compiler's library routines with the 14-bit nano board.

As soon as I have the next update uploaded, I wil be checking out the ARM M0+ in assembler code, then I can get a feel of what it requires for a compiler. :-)


JonW

#7
You are very welcome, thought they would all come in handy!  The 18F analog part looks pretty cool with the new features and the M0, good luck with that, it will be microchipified =  :P  = mashed up
Thought I would tempt you and saw the ARM Nano... and know you like Analog so that 18F should be fun to play with.  They are a doddle to use, plug in and drag the hex over.  Also take a look at the Data Visualiser, not used it much but some of the boards have the SAMD MCU as the programmer so the visualiser can be used with some of the DGI pins.  You can send serial data to the visualiser and it can plot it.  The capture above used the terminal function through the Nano, its virtual com port needs DTR asserting otherwise the data wont come through the Nano host device, just remember this when you test out the Uarts.  I also sent you some code that gets the Uarts and the CCP1 & 2 working with the correct register setup, took me ages to figure out that the CCP modules need T2CLKCON setting to Fosc/4 for PWM otherwise they don't work.  You can get 120kHz with 8 bit resolution or 32kHz with 10bit @ 32MHz

Data Visualiser


enjoy

JonW

Hi Les

When you are building the new PPI can you add the declarations for the constants used in the DIA for the stored measured VREF and Temp sensor please.  Yet another pain in the ass having to access them via the NVM registers.

Jon