News:

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

Main Menu

Pic24HJ128GP502 PPS

Started by John Drew, Aug 28, 2022, 09:06 AM

Previous topic - Next topic

John Drew

Greetings all. I'm slowly going mad trying to sort out PPS for the USART module. I've read both the datasheet and the USART document on Microchip.
They help with setting up CTS and DSR but all I want to access is to define the TX pin. The pin is going to send data out at a slow pace to a modem chip. I'll add my own checksum. I think I have a grip on the registers to set, but PPS is another story :(

Has anyone done this?
John

top204

#1
Try this John. Untested, but looks OK:

    Device = 24HJ128GP502
    Declare Xtal = 32
'
' Setup USART1
'   
    Declare Hserial1_Baud = 9600
    Declare HRSOut1_Pin   = PORTB.14                ' Select which pin is to be used for TX with USART1
    Declare HRSIn1_Pin    = PORTB.15                ' Select which pin is to be used for RX with USART1
   
'---------------------------------------------------------------------
' The main program starts here
'
Main:
'
' Setup PPS for USART1 RX and TX

    PPS_Unlock()                                    ' Unlock the PPS (not always required when first powered up)           
    PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)         ' Set the TX pin to RP14 (PORTB.14)
    PPS_Input(cIn_Pin_RP15, cIn_Fn_U1RX)            ' Set the RX pin to RP15 (PORTB.15)

The PPS settings and values are in the device's ".def" file, which are all located here: "C:\Program Files (x86)\ProtonIDE\PDS\Includes\Defs\". In the "[PPS Defs Start]" section of the .def file.

Because the 16-bit devices use the RP and sometime RPI pin values, it is not as straightforward to choose the pin for the PPS (Peripheral Pin Select). That's why I have not added auto PPS setup in Positron16 yet, as I have done with Positron8, because not all RP and RPI values match the associated Port and Pin value for some inexplicable reason!

So look in the datasheet, and match the RPxx value to the required pin, and use that. On some PIC24 and dsPIC33 devices, only some pins can be used as inputs and some as outputs and some as inputs and outputs with PPS, so check the datasheet section for PPS input and output? The PPS values in the .def files are taken from Microchip data files, so they should match perfectly if a pin is able to perform both input and output, but with Microchip's dreadful reputaion in the past decade or so, one can never tell if their "official" information is actually correct!

John Drew

Thank you very much Les. That will get me going. Designing the circuit at this point but I can work it out now. A long way to go but one step at a time.
All the best from your friend down under.
John