Menu

PPS and the Xpress - A look at the PPS Tool in Practice.

2018-03-13
2018-03-13
  • Chris Roper

    Chris Roper - 2018-03-13

    Context: This was initially written in response to a forum question about the Xpress evaluation board and SPI. It is archived here by request.

    Ignore the naming of the Pins, that has nothing to do with the Microcontroller.

    I bet that got your attention, now let me explain why:

    Look closely at the Xpress Board and you will see two labels per Pin. The Outer labels, such as RB0, RC7 ... etc. are the actual device Pins. The inner Labels, AN, PWM ... etc, are just placeholders for MikroBUS compatible Plugin Modules, known as Click Boards. They are a modern equivalent to Shields but are not dependent on a particular development board or device family.

    See Here: https://www.mikroe.com/click for information on, and a selection of, Click Boards.

    Initially most, if not all, of the Microcontroller Pins are set for Digital I/O and the peripherals are unallocated.

    You can decide which Pins you want to use for which peripherals, such as SPI or I2C etc. and then allocate them with the PPS Tool that is built into GCBASIC.

    Any unallocated Pins remain available for Digital I/O.

    If you were planning to use a Click Board then you would use the GCBASIC PPS Tool to allocate the Peripherals you need to the Corresponding Labels on the MikroBUS footprint.

    If you are using your own hardware then you can use whatever pins suit your application for whatever purpose.

    Generally I tend to still allocate according to the MikroBUS labels but that is entirely your choice. For this example though I will use the MikroBUS Labels as a guide.

    By starting your journey with SPI you have chosen the hardest place to start, but let's tackle that challenge:

    If you look at the Xpress board again notice that the SPI interface is Labeled as:

    RB3 <-> SCK
    RB4 <-> MISO
    RB5 <-> MOSI

    Now we use the PPS Tool to Allocate those Pins to the Peripheral.

    Notice that the board only indicates labels for One SPI Port, but the PIC16F18855 contains two SPI ports, you can choose which one to use or you could use both by allocating the second SPI module to alternative Pins.

    Open the PPS Tool, the Toolbar Button between “flash” and “terminal”.
    Be patient, it takes some time to read all the XML files and draw the display.

    The Image below shows the PPS Tool after completing all of the following steps.
    It may look very different when it initially loads, don’t let that worry you.

    Select the PIC (Top Left) as 16F18855

    First we will allocate the SPI Clock to the PIN RB3.

    Go Down To PPS Outputs:

    In the Peripheral output drop down list (It is a long list) scroll down to SCK1 (or 2 if you prefer the second SPI module) and select it. Then from the adjacent drop down list labeled Pin select RB3.

    Now Click the “Add” button below the PIN you selected.

    It will generate code on the Right, just ignore that for now.

    If you look at the bottom Left of the PPS Tool you will see a Pinout Diagram of the Device you selected. Now notice how, as you add Peripherals to Pins they change colour to indicate that they are in use.

    That diagram is a handy guide when you are trying to fit several peripheral devices on a low pin count device and a handy guide to which pins are still available as Digital I/O. It can also assist you in routing your Printed Circuit Board as you can often change a pin allocation rather than have to reroute a trace.

    Note:
    Different device manufactures use different pin names for the same thing in SPI.

    To add to the confusion the industry decided to create a standard for all new entrants.
    But the rest, which is 90% of the manufacturers, are free to continue as they were.

    MikroBUS (and Arduino) being newcomers, uses the Standard, Microchip still uses its own names.

    Here is as a comparison to help clarify:

    If you are working in SPI Master Mode, which is the default, then SDI is Serial Data In and is equivalent to MISO (Master In Slave Out) and SDO is Serial Data Out or MOSI (Master Out Slave In).

    So to allocate the MISO (SDI) pin:

    Go Up To PPS Inputs then, from the Peripheral input List, select SDI1 and the Pin as RB4

    Then Click the “Add” button below the PIN you selected.

    Finally we allocate MOSI (SDO) to RB5:

    Go back down to PPS Outputs and select Peripheral Output as SDO1 and pin as RB5.

    Then Click the “Add” button below the PIN you selected.

    And we are done, the PPS Tool should look similar to this:

    If all you needed was the SPI port you would be finished, however, on the Xpress board it is always useful to have the USART allocated to the onboard serial bridge to assist in debugging. This is how we add it:

    PPS Inputs:
    From the Peripheral input List, select RX and the Pin as RC1, Then Add.
    PPS Outputs:
    Select Peripheral Output as TX and pin as RC0, Then Add.

    Press the Copy Button below the Code window and paste it into your code near the top, so that the PIN’s are allocated before you use them.

        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.5.11
        'PinManager data: v1.55
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
    
        Sub InitPPS
    
                'Module: EUSART
                RXPPS = 0x0011    'RC1 > RX
                RC0PPS = 0x0010    'TX > RC0
                TXPPS = 0x0010    'RC0 > TX (bi-directional)
                'Module: MSSP1
                RB3PPS = 0x0014    'SCK1 > RB3
                SSP1CLKPPS = 0x000B    'RB3 > SCK1 (bi-directional)
                SSP1DATPPS = 0x000A    'RB2 > SDI1
                SSP1DATPPS = 0x000C    'RB4 > SDI1
                RB5PPS = 0x0015    'SDO1 > RB5
    
        End Sub
        'Template comment at the end of the config file
    

    Notice that the EUSART has been placed before the MSSP code despite the order you entered them.
    To the compiler the PPS order is not relevant and the Tool decides on the order to use.

    If you needed any other Peripherals allocated you would normally do them all at the same time. Unused peripherals, however, don’t need to be allocated freeing pins for Standard I/O functions. Which is why I said elsewhere that this board requires you to know and understand the hardware requirements of the target application and not, as Arduino does, the development board.

    So with PPS the Xpress board adapts to your application, you don't have to adapt your application to suit the Xpress board.

    I hope that helps clarify, and gives you a better Idea of why Even and I like to recommend this board, even though it is far more advanced than most beginners would expect.

    Cheers
    Chris

     

    Last edit: Chris Roper 2018-03-13
  • Anobium

    Anobium - 2018-03-13

    Please do not post to this thread - open new threads for feedback etc. I want to keep this as information ONLY thread.

    I will delete posts to this thread.

     
  • stan cartwright

    stan cartwright - 2018-03-13
     

    Last edit: stan cartwright 2018-03-13

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.