• AVR Freaks

Hot!SPI resources in MCC

Author
_dex
Starting Member
  • Total Posts : 86
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
2020/02/14 01:47:46 (permalink)
0

SPI resources in MCC

I have 16 bit PICs: 33EP and 24FJ and I would like to use SPI to read the data from the sensor. I will use one of them, they are similar in SPI part. Ideal would be to use a DMA to increase the performance. I have few, maybe trivial questions:
1.Whats the difference between these two SPI resources in MCC, I mean:
SPI [Foundation Services Library mu MCHP, Inc.]
and
SPI [PIC24 / dsPIC33 / PIC32MM MCUs by MCHP, Inc.]
 
2. If I use MCC generated SPI code, Do I have to take care of the Chip Select/Slave Select Pin personally? or is this all done by the library, whenever I am calling any Exchange functions like:
SPI2_Exchange8bitBuffer();
 
3.SPI section in FRM 24/33 says:
If the device has a Peripheral Pin Select (PPS) feature, the SCKx pin mustbe mapped as both input and output in Master mode.
I have the clock signal on my scope but I see this PIN is set by the MCC only as output:
  /****************************************************************************
     * Set the PPS
     ***************************************************************************/
    __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS

    RPOR9bits.RP19R = 0x000A; //RG8->SPI2:SDO2
    RPINR22bits.SDI2R = 0x001A; //RG7->SPI2:SDI2
    RPOR13bits.RP27R = 0x000C; //RG9->SPI2:SS2OUT
    RPOR10bits.RP21R = 0x000B; //RG6->SPI2:SCK2OUT

    __builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS

 
RPORxx stands for the outputs so where is the RPINRxx definition line ? Have they forgotten in MCC to set it as input or am I to tired?
 
4. Perhaps there is any description or AN talking about this questions or working project with DMA?
post edited by _dex - 2020/02/14 07:25:34
#1

2 Replies Related Threads

    pr.mchp
    Starting Member
    • Total Posts : 38
    • Reward points : 0
    • Joined: 2015/03/23 06:20:48
    • Location: 0
    • Status: offline
    Re: SPI resources in MCC 2020/02/18 22:01:28 (permalink)
    0
    Hi
    1) SPI in MCC uses enhanced mode of operation. DMA can not be used while SPI is operating in enhanced mode.
    2) MCC provides the flexibility for the user to select the SS pin and the same will get reflected in the generated pinmanager.c file. Depending on the application needs, the user has to manually control this pin. 
    3) In case of PPS(majorly the dsPICs), the SCKx pin must be mapped as both input and output in Master mode. Can you please mention the specific device, in which you observed that the generated code didnt have the expected implementation. Verified with dsPIC33EP128GS808, and the implementation works as expected.
     
     
    /****************************************************************************
    * Set the PPS
    ***************************************************************************/
    __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS
    RPINR20bits.SDI1R = 0x0011; //RA1->SPI1:SDI1
    RPOR1bits.RP18R = 0x0005; //RA2->SPI1:SDO1
    RPOR0bits.RP16R = 0x0006; //RA0->SPI1:SCK1
    RPOR1bits.RP19R = 0x0007; //RA3->SPI1:SS1
    RPINR20bits.SCK1INR = 0x0010; //RA0->SPI1:SCK1
    __builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS
    #2
    _dex
    Starting Member
    • Total Posts : 86
    • Reward points : 0
    • Joined: 2008/03/19 13:57:34
    • Location: 0
    • Status: offline
    Re: SPI resources in MCC 2020/02/20 04:07:32 (permalink)
    0
    Thank you for your answer, to be honest I still do not know whats the difference - question 1?
    Would you be so kind and clarify it, or redirect to any available documentation if such exist?
     
    Why there are two resources, I have not seen any description. Is one better than the other one, is one using Interrupts and the second one software implementation. Is this for backward compatibility with some other libraries. From My observation none of them is using interrupts even there is ISR defined  - I have commented the entire definitions of:
    void spi2_isr(void) and
    void spi2_setSpiISR(void(*handler)(void))
    and the code was compiled and running, seems  there is no interrupts or I wrongly initialized the SPI by calling spi2_open(). Thats my guess I am not so advanced, have only a little ASM experience where everything is much simpler.

    Answering to your question: SPI2 Master, Fresh projects
    For 33FJ1024GB610 these are outputs
      
     __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS

        RPINR20bits.SDI1R = 0x001A; //RG7->SPI1:SDI1
        RPOR9bits.RP19R = 0x0007; //RG8->SPI1:SDO1
        RPOR13bits.RP27R = 0x0009; //RG9->SPI1:SS1OUT
        RPOR10bits.RP21R = 0x0008; //RG6->SPI1:SCK1OUT

        __builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS


    and
    33EP256MC506, which is now completely not configuring any PINs for SPI1, before I have USED SPI2 where I had to manually defined SCK2 as output (I did only as output). So now for SPI1 by MCHP and by Foundation(both) the enitre PPS section in pin_manager.c is missing. Fresh project SPI1 by MCHP, Master in 16 bit mode, system Clock defined as Primary 8MHz plus the fastest prescaler settings.
    But this could be due to fixex SPI1 pins, but with SPI2 is the same.
    After closing and new opened MPLABX 5.30; MCC Core v4.85; XC16 1.41; Packs 1.1.33; Library 1.166.0
    post edited by _dex - 2020/02/23 09:21:31
    #3
    Jump to:
    © 2020 APG vNext Commercial Version 4.5