• AVR Freaks

Hot!How to transfer from PORTSetBits... to PLIB_PORTS_Set...

Author
NotTooSmart
Junior Member
  • Total Posts : 101
  • Reward points : 0
  • Joined: 2011/11/15 11:19:37
  • Location: 0
  • Status: offline
2019/07/04 06:20:15 (permalink)
0

How to transfer from PORTSetBits... to PLIB_PORTS_Set...

Hi There,
In the old, this worked well for me:
PORTSetBits(IOPORT_B,BIT_14|BIT_12|BIT_8|BIT_6);
But in Harmony2  the compiler v2.15 gives error with this:
PLIB_PORTS_Set(PORTS_ID_0, IOPORT_B,BIT_14|BIT_12|BIT_8|BIT_6);
What is the proper format? 
Please, advice. Thanks
#1

8 Replies Related Threads

    Paul PortSol
    Super Member
    • Total Posts : 455
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: How to transfer from PORTSetBits... to PLIB_PORTS_Set... 2019/07/04 08:11:51 (permalink)
    0
    Use MHC pin manager to define your pin, and MHC will create a nice set of Macros for the pin (GPIO, GPIO_OUT, LED_HI, etc.). I follow my pin names with underscore '_' for readability in generated macros.
    After generate do a search for your pin name and you'll find the header file with the new macros. 
    Different macros depending on pin type.
    You can create your own macros using similar style, but its nice having them clearly in MHC Pin Manager as easier to see on the chip footprint (Screen capture and give to the PCB layout people, which for me is myself).
     
    Paul
    #2
    NotTooSmart
    Junior Member
    • Total Posts : 101
    • Reward points : 0
    • Joined: 2011/11/15 11:19:37
    • Location: 0
    • Status: offline
    Re: How to transfer from PORTSetBits... to PLIB_PORTS_Set... 2019/07/04 09:45:23 (permalink)
    0
    Thanks, Paul,
     
    Here is what I found in the Systen_port_static.c:
     
    void SYS_PORTS_Set( PORTS_MODULE_ID index, PORTS_CHANNEL channel,
                        PORTS_DATA_TYPE value,
                        PORTS_DATA_MASK mask )
    {
        PLIB_PORTS_Set( index, channel, value, mask );
    }
     
    I understand PORTS_MODULE_ID and PORTS_CHANNEL but the others PORTS_DATA_TYPE and PORTS_DATA_MASK I do not know what to put there.
     
    What I want a macro equivalent to the old  PORTSetBits(IOPORT_B, BIT_14|BIT_12|BIT_8|BIT_6), it appears that Harmony does not have it...   Can a macro be built that works like PortSetBits?  Anybody?
     
    Thanks
    post edited by NotTooSmart - 2019/07/04 10:18:47
    #3
    Paul PortSol
    Super Member
    • Total Posts : 455
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: How to transfer from PORTSetBits... to PLIB_PORTS_Set... 2019/07/04 10:19:08 (permalink)
    0
    Oops, didn't realize you were after port access versus pin access, I've been lost in PCB design lately and only just switching back to coding...
     
    Only thing I got on code sample is Port read and combine several chunks into a 32bit word (For parallel 32 UART Rx in software):
    // Combined PostShiftMASK (0xFFFFFFFF)
    #define D_PORT_K_PostShiftMASK (0x000000FF)
    #define D_PORT_J_PostShiftMASK (0x00F4FF00)
    #define D_PORT_E_PostShiftMASK (0x000B0000)
    #define D_PORT_H1_PostShiftMASK (0x03000000)
    #define D_PORT_H2_PostShiftMASK (0x0C000000)//Normal: (0xFC000000) Diag4bit:(0x0C000000)
    #define D_PORT_K_Shift (0) //NoShift
    #define D_PORT_J_Shift (8) //<<8
    #define D_PORT_E_Shift (16)//<<16
    #define D_PORT_H1_Shift (22)//<<22
    #define D_PORT_H2_Shift (16)//<<16
    sSwRxSamples.u32pinSample = ((PLIB_PORTS_Read(PORTS_ID_0, PORT_CHANNEL_K) << D_PORT_K_Shift) & D_PORT_K_PostShiftMASK);//Combine Ports to SwRx[32]
    sSwRxSamples.u32pinSample |= ((PLIB_PORTS_Read(PORTS_ID_0, PORT_CHANNEL_J) << D_PORT_J_Shift) & D_PORT_J_PostShiftMASK);
    sSwRxSamples.u32pinSample |= ((PLIB_PORTS_Read(PORTS_ID_0, PORT_CHANNEL_E) << D_PORT_E_Shift) & D_PORT_E_PostShiftMASK);
    sSwRxSamples.u32pinSample |= ((PLIB_PORTS_Read(PORTS_ID_0, PORT_CHANNEL_H) << D_PORT_H1_Shift) & D_PORT_H1_PostShiftMASK);
    sSwRxSamples.u32pinSample |= ((PLIB_PORTS_Read(PORTS_ID_0, PORT_CHANNEL_H) << D_PORT_H2_Shift) & D_PORT_H2_PostShiftMASK);
    vSwRxDecode(sSwRxSamples.u32pinSample);//Samples to Bytes
     
    I'd expect port set to be similar, so maybe:
    void SYS_PORTS_Set( PORTS_MODULE_ID index, PORTS_CHANNEL channel,PORTS_DATA_TYPE value,PORTS_DATA_MASK mask);
    SYS_PORTS_Set(PORTS_ID_0, PORT_CHANNEL_K, BitValues, MaskBitsToAffect);
    //Mask likely ones means affect those bits, but do recommend testing on something safe before driving connected hardware.
     
    Paul
    #4
    NotTooSmart
    Junior Member
    • Total Posts : 101
    • Reward points : 0
    • Joined: 2011/11/15 11:19:37
    • Location: 0
    • Status: offline
    Re: How to transfer from PORTSetBits... to PLIB_PORTS_Set... 2019/07/04 10:49:25 (permalink)
    0
    Thanks, Paul, lots of code, but still not very clear how to handle BitValues and  MaskBitsToAffect. Perhaps a particular sample will clarify my confusion...  
    Using: 
    SYS_PORTS_Set(PORTS_ID_0, PORT_CHANNEL_B, BitValues, MaskBitsToAffect);
    supposing that I want to set bit 2,4,8 bits of PORTB to "1" while not changing the others. What do I enter on BitValues and MaskBitsToAffect? I will appreciate if you could outwrite the sample.
     
    Thanks for helping; or anyone else?
    post edited by NotTooSmart - 2019/07/04 12:35:38
    #5
    Paul PortSol
    Super Member
    • Total Posts : 455
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: How to transfer from PORTSetBits... to PLIB_PORTS_Set... 2019/07/05 04:50:27 (permalink)
    0
    SYS_PORTS_Set(PORTS_ID_0, PORT_CHANNEL_B, -1, MaskBitsToAffect);
    * bit 2,4,8 = 0x10010010 = 0x92 (if meant bit numbers like 876543210)
    * bit 2,4,8 = 0x00001110 = 0x0E (if meant bits with values of 2,4,8)
    * -1 maps to all bits set for any datasize
    SYS_PORTS_Set(PORTS_ID_0, PORT_CHANNEL_B, -1, 0x92); //Set selected Bits
    SYS_PORTS_Set(PORTS_ID_0, PORT_CHANNEL_B, 0,  0x92); //Clear selected Bits
    SYS_PORTS_Set(PORTS_ID_0, PORT_CHANNEL_B, uValue, 0x92); //Set selected Bits to passed value
     
    Just try it and see what works. As long as nothing connected to the port then you shouldn't damage anything.
    You can use the read function to check actual pin states.
    Ensure you got pins set in MHC pin manager for Out or In(option:Pullup/Pulldown).
     
    Paul
                 
     
    #6
    moser
    Super Member
    • Total Posts : 481
    • Reward points : 0
    • Joined: 2015/06/16 02:53:47
    • Location: Germany
    • Status: offline
    Re: How to transfer from PORTSetBits... to PLIB_PORTS_Set... 2019/07/08 06:31:18 (permalink)
    0
    In the end, "value" and "mask" are just bitwise-AND-ed together.
     
    PLIB_INLINE_API void PLIB_PORTS_Set(PORTS_MODULE_ID index, PORTS_CHANNEL channel, PORTS_DATA_TYPE value, PORTS_DATA_MASK mask)
    {
         PORTS_Set_MCU32_PPS(index, channel, value, mask);
    }

    PLIB_TEMPLATE void PORTS_Set_MCU32_PPS( PORTS_MODULE_ID index , PORTS_CHANNEL channel , PORTS_DATA_TYPE value , PORTS_DATA_MASK mask )
    {
        
        *(&LATBSET + (channel - 1) * 0x40) = (value & mask);
     
    }

     
    However, the one is supposed to select the pins, which you want to set in the port, and the other, the value, which defines, which bit needs to get set. However, its up to you to decide how you want to use it. Usually, you will only use one of mask or value.
     
    Note, you have:
    PLIB_PORTS_Write()   - just write the values for the complete port into the LAT  (e.g. by using LATB directly)
    PLIB_PORTS_Set() - only sets selected bits. (e.g. by using LATBSET)
    PLIB_PORTS_Clear() - only clears selected bits. (e.g. by using LATBCLR)
    PLIB_PORTS_Toggle() - only toggles selected bits. (e.g. by using LATBINV)
     
    Hint: Just add the function in question to your code, and then CTRL+Leftclick it.
    #7
    ric
    Super Member
    • Total Posts : 22715
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: How to transfer from PORTSetBits... to PLIB_PORTS_Set... 2019/07/08 15:40:47 (permalink)
    0
    moser...
    Hint: Just add the function in question to your code, and then CTRL+Leftclick it.

    (... and hope MPLABX is in a good mood to play along. ;) )

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    cbeif
    Starting Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2012/05/09 14:28:30
    • Location: 0
    • Status: offline
    Re: How to transfer from PORTSetBits... to PLIB_PORTS_Set... 2019/07/08 17:03:22 (permalink)
    0
    Parameters:
    index - Identifier for the device instance to be configured
    channel - Identifier for the PORT channel: A, B, C, etc.
    value - Consists of information about which port bit has to be set
    mask - Identifies the bits which could be intended for setting
    Returns:
    None.
    Example:
    <code>

    MY_VALUE - 0x1234
    PORTS_DATA_MASK myMask = (PORTS_DATA_MASK)0x00FF;

    // Set the MY_CHANNEL bit positions 2,4 and 5 (0x0034 = b0000 0000 0011 0100)
    SYS_PORTS_Set(MY_PORTS_INSTANCE, MY_CHANNEL, MY_VALUE, myMask);
    #9
    Jump to:
    © 2019 APG vNext Commercial Version 4.5