• AVR Freaks

Hot!Question about MCC generated code for SPI using PIC24F

Author
ezedhill
Starting Member
  • Total Posts : 78
  • Reward points : 0
  • Joined: 2019/02/07 06:43:05
  • Location: 0
  • Status: offline
2019/07/09 11:34:34 (permalink)
0

Question about MCC generated code for SPI using PIC24F

I used the MCC to setup the SPI1 on a PIC24F. I can see the clock and CS signals, but no data on the MOSI line. I set the PIC up as the master in 8 bit mode. I'm using the function, SPI1_Exchange8bit( uint8_t data) to send data. I have it interfaced to an EVE TFT display. Any help would be appreciated. 
#1

9 Replies Related Threads

    katela
    Super Member
    • Total Posts : 1317
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: Question about MCC generated code for SPI using PIC24F 2019/07/09 12:17:17 (permalink)
    4 (1)
    Maybe if you could post your code and/or screenshots of your configurations, specify the exact PIC you are using and the versions of your tools. It's difficult to guess with so little info you have provided.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #2
    ezedhill
    Starting Member
    • Total Posts : 78
    • Reward points : 0
    • Joined: 2019/02/07 06:43:05
    • Location: 0
    • Status: offline
    Re: Question about MCC generated code for SPI using PIC24F 2019/07/09 13:49:27 (permalink)
    0
    Here is the main file.
     
    /**
      Generated main.c file from MPLAB Code Configurator

      @Company
        Microchip Technology Inc.

      @File Name
        main.c

      @Summary
        This is the generated main.c using PIC24 / dsPIC33 / PIC32MM MCUs.

      @Description
        This source file provides main entry point for system intialization and application code development.
        Generation Information :
            Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.95-b-SNAPSHOT
            Device : PIC24FJ256GB410
        The generated drivers are tested against the following:
            Compiler : XC16 v1.36
            MPLAB : MPLAB X v5.10
     */

    /*
        (c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this
        software and any derivatives exclusively with Microchip products.

        THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
        EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
        WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
        PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
        WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.

        IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
        INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
        WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
        BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
        FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
        ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
        THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.

        MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
        TERMS.
     */

    /**
      Section: Included Files
     */
    #define FCY 16000000 // half of Fosc

    #include <xc.h> // include processor files - each processor file is guarded.
    #include <libpic30.h>
    #include <pps.h>

    #include <spi.h>
    //#include "p24fj256gb410.h"
    //#include "FT8xx.h"
    #include "Library.h"
    #include "mcc_generated_files/system.h"
    #include "mcc_generated_files/spi1.h"
    #include "mcc_generated_files/pin_manager.h"


    #define LCD_320_240
    #define FT81x_ACTIVE 0x00

    // LCD display parameters
    uint16_t lcdWidth; // Active width of LCD display
    uint16_t lcdHeight; // Active height of LCD display
    uint16_t lcdHcycle; // Total number of clocks per line
    uint16_t lcdHoffset; // Start of active line
    uint16_t lcdHsync0; // Start of horizontal sync pulse
    uint16_t lcdHsync1; // End of horizontal sync pulse
    uint16_t lcdVcycle; // Total number of lines per screen
    uint16_t lcdVoffset; // Start of active screen
    uint16_t lcdVsync0; // Start of vertical sync pulse
    uint16_t lcdVsync1; // End of vertical sync pulse
    uint8_t lcdPclk; // Pixel Clock
    uint8_t lcdSwizzle; // Define RGB output pins
    uint8_t lcdPclkpol; // Define active edge of PCLK

    uint32_t ramDisplayList = RAM_DL; // Set beginning of display list memory
    uint32_t ramCommandBuffer = RAM_CMD; // Set beginning of graphics command memory

    uint16_t FT81x_GPIO_DAT; // Used for GPIO registers
    uint16_t FT81x_GPIO_DIR;
    uint8_t dly = 0;
    uint8_t PWM = 0;

    typedef struct {
        uint8_t cpha : 1;
        uint8_t inputsample : 1;
        uint8_t cpol : 1;
    } SPI_Setting;
    #define SPISelect(x) (LATBbits.LATB15 = x)
    #define SPIAssert() (LATBbits.LATB15=1)
    #define SPIDeassert() (LATBbits.LATB15 = 0)


    // Application Layer
    void APP_Init(void);
    void APP_FlashingDot(void);

    /*
                             Main application
     */
    int main(void) {
        uint8_t v;
        MCU_Init();
        // initialize the device
        APP_Init();

        //APP_SliderandButton();

        while (1) {
            // Add your application code
            // MCU_SPIReadWrite('H');
            // MCU_SPIReadWrite('E');
            // MCU_SPIReadWrite('L');
            // MCU_SPIReadWrite('L');
            // MCU_SPIReadWrite('O');
            // MCU_SPIReadWrite(' ');
            _LATD12 = 0;
            v = SPI1_Exchange8bit('H');
            v = SPI1_Exchange8bit('e');
            v = SPI1_Exchange8bit('l');
            v = SPI1_Exchange8bit('l');
            v = SPI1_Exchange8bit('o');
            v = SPI1_Exchange8bit(' ');
            _LATD12 = 1;

            __delay_ms(20);

        }

        return 1;
    }

    void APP_Init(void) {
        // ----------------------- Cycle PD pin to reset device --------------------

        MCU_PDlow(); // PD low to reset device
        MCU_Delay_20ms();
        MCU_PDhigh(); // PD high again
        MCU_Delay_20ms();

        // ---------------------- Delay to allow FT81x start-up --------------------

        EVE_CmdWrite(FT81x_ACTIVE, 0x00); // Sends 00 00 00 to wake FT8xx
        MCU_Delay_500ms(); // 500ms delay (EVE requires at least 300ms here))
        // --------------- Check that FT8xx ready and SPI comms OK -----------------

        while (EVE_MemRead8(REG_ID) != 0x7C) // Read REG_ID register until reads 0x7C
        {
        }

        while (EVE_MemRead8(REG_CPURESET) != 0x00) // Ensure CPUreset register reads 0 and so FT8xx is ready
        {
        }

        // ---------------- Configure the GPIO and PWM --------------------

        EVE_MemWrite8(REG_PWM_DUTY, 0); // Backlight off

        FT81x_GPIO_DAT = EVE_MemRead16(REG_GPIOX); // Read the FT81x GPIO register for a read/modify/write operation
        FT81x_GPIO_DAT = FT81x_GPIO_DAT | 0x8000; // set bit 15 of GPIO register (DISP). If using audio, also enable the amplifier shutdown GPIO line here
        EVE_MemWrite16(REG_GPIOX, FT81x_GPIO_DAT); // Enable the DISP signal to the LCD panel

        FT81x_GPIO_DIR = EVE_MemRead16(REG_GPIOX_DIR); // Read the FT81x GPIO DIR register for a read/modify/write operation
        FT81x_GPIO_DIR = FT81x_GPIO_DIR | 0x8000; // DISP is output, if using audio, also set the associated shutdown line as output (check your Eval module schematic))
        EVE_MemWrite16(REG_GPIOX_DIR, FT81x_GPIO_DIR); // Enable the DISP signal to the LCD panel

        // ------------------------- Display settings ------------------------------

        // display parameters
        lcdWidth = 320; // Active width of LCD display
        lcdHeight = 240; // Active height of LCD display
        lcdHcycle = 408; // Total number of clocks per line
        lcdHoffset = 70; // Start of active line
        lcdHsync0 = 0; // Start of horizontal sync pulse
        lcdHsync1 = 10; // End of horizontal sync pulse
        lcdVcycle = 263; // Total number of lines per screen
        lcdVoffset = 13; // Start of active screen
        lcdVsync0 = 0; // Start of vertical sync pulse
        lcdVsync1 = 2; // End of vertical sync pulse
        lcdPclk = 6; // Pixel Clock
        lcdSwizzle = 2; // Define RGB output pins
        lcdPclkpol = 1; // Define active edge of PCLK

        EVE_MemWrite16(REG_HSIZE, lcdWidth);
        EVE_MemWrite16(REG_HCYCLE, lcdHcycle);
        EVE_MemWrite16(REG_HOFFSET, lcdHoffset);
        EVE_MemWrite16(REG_HSYNC0, lcdHsync0);
        EVE_MemWrite16(REG_HSYNC1, lcdHsync1);
        EVE_MemWrite16(REG_VSIZE, lcdHeight);
        EVE_MemWrite16(REG_VCYCLE, lcdVcycle);
        EVE_MemWrite16(REG_VOFFSET, lcdVoffset);
        EVE_MemWrite16(REG_VSYNC0, lcdVsync0);
        EVE_MemWrite16(REG_VSYNC1, lcdVsync1);
        EVE_MemWrite8(REG_SWIZZLE, lcdSwizzle);
        EVE_MemWrite8(REG_PCLK_POL, lcdPclkpol);

        // ---------------------- Touch and Audio settings -------------------------

        //EVE_MemWrite16(REG_TOUCH_RZTHRESH, 1200); // Eliminate any false touches

        //EVE_MemWrite8(REG_VOL_PB, ZERO); // turn recorded audio volume down
        //EVE_MemWrite8(REG_VOL_SOUND, ZERO); // turn volume down
        //EVE_MemWrite16(REG_SOUND, 0x6000); // set volume mute

        // ---------------------- Create an initial screen before we enable the display -------------------------

        ramDisplayList = RAM_DL; // start of Display List
        EVE_MemWrite32(ramDisplayList, 0x02000000); // Clear Color RGB sets the colour to clear screen to

        ramDisplayList += 4; // point to next location
        EVE_MemWrite32(ramDisplayList, (0x26000000 | 0x00000007)); // Clear 00100110 -------- -------- -----CST (C/S/T define which parameters to clear)

        ramDisplayList += 4; // point to next location
        EVE_MemWrite32(ramDisplayList, 0x00000000); // DISPLAY command 00000000 00000000 00000000 00000000 (end of display list)

        EVE_MemWrite32(REG_DLSWAP, DLSWAP_FRAME); // Swap display list to make the edited one active

        // -------------------- Now turn on PCLK and ramp the PWM up -------------------------------------
        // ---------------- This provides a clean start-up for the application ----------------------------

        EVE_MemWrite8(REG_PCLK, lcdPclk); // Now start clocking data to the LCD panel

        MCU_Delay_20ms();

        for (PWM = 0; PWM <= 127; PWM++) {
            EVE_MemWrite8(REG_PWM_DUTY, PWM);
            MCU_Delay_20ms();
        }

    }


    //##############################################################################
    //##############################################################################

    void APP_FlashingDot(void) {
        uint8_t color = 0;

        while (1) {
            if (color == 0x00) // Toggle colour variable
                color = 0xFF;
            else
                color = 0x00;

            // ------------------- Create screen -------------------------------------

            API_LIB_BeginCoProList(); // Begin new screen
            API_CMD_DLSTART(); // Tell co-processor to create new Display List

            API_CLEAR_COLOR_RGB(0, 0, 0); // Specify color to clear screen to
            API_CLEAR(1, 1, 1); // Clear color, stencil, and tag buffer

            API_COLOR_RGB(color, 0, 0); // Set color for subsequent items
            API_BEGIN(FTPOINTS); // Begin drawing points
            API_POINT_SIZE(40 * 16); // Point size
            API_VERTEX2F(200 * 16, 200 * 16); // Place a point at the specified coordinates
            API_END(); // Finished drawing points

            API_DISPLAY(); // Tell EVE that this is end of list
            API_CMD_SWAP(); // Swap buffers in EVE to make this list active

            API_LIB_EndCoProList(); // Finish the co-processor list burst write
            API_LIB_AwaitCoProEmpty(); // Wait until co-processor has consumed all commands

            //APP_SnapShot2PPM(); // Un-comment to take snapshot (see BRT_AN_014)

            MCU_Delay_500ms();
        }
    }

    void APP_SliderandButton(void) {
        uint32_t TrackerVal = 0;
        uint8_t TagVal = 0;
        uint16_t SlideVal = 0;
        uint16_t Button3D = 0;
        uint8_t color = 0;

        while (1) {
            API_LIB_BeginCoProList(); // Begin new screen
            API_CMD_DLSTART(); // Tell co-processor to create new Display List

            API_CLEAR_COLOR_RGB(0, 0, 0); // Specify color to clear screen to
            API_CLEAR(1, 1, 1); // Clear color, stencil, and tag buffer

            API_TAG_MASK(1); // Enable tagging

            API_TAG(2); // Tag following items with tag 2
            API_CMD_FGCOLOR(0x0000FF); // Blue foreground color
            API_CMD_BUTTON(100, 200, 80, 30, 27, Button3D, "Button"); // Draw button

            API_TAG(5); // Tag following items with tag 5
            API_CMD_SLIDER(300, 100, 16, 200, 0, SlideVal, 255); // Draw a slider
            API_CMD_TRACK(300, 100, 16, 200, 5); // Place a tracker

            API_TAG_MASK(0); // Mask tagging so that following items won't be tagged

            API_BEGIN(FTPOINTS); // Draw a dot in red at 140, 100)
            API_POINT_SIZE(30 * 16);
            API_COLOR_RGB(color, 0, 0); // Set colour to blue and write some text
            API_VERTEX2F((140 * 16), (100 * 16));
            API_END();

            API_DISPLAY(); // Tell EVE that this is end of list
            API_CMD_SWAP(); // Swap buffers in EVE to make this list active

            API_LIB_EndCoProList(); // Finish the co-processor list burst write
            API_LIB_AwaitCoProEmpty(); // Wait until co-processor has consumed all commands

            // ------ read tag and tracker values --------
            TagVal = EVE_MemRead8(REG_TOUCH_TAG); // Get Tag value
            TrackerVal = EVE_MemRead32(REG_TRACKER); // Read the value of the tag and track register

            if (TagVal == 2) {// If button pushed tag register will read 2
                color = 0xFF; // change red amount to 255
                Button3D = 256; // Give the button a pushed-in appearance
            } else {// Otherwise...
                color = 0x00; // change red amount to 0 so dot is not visible
                Button3D = 0; // Button has 3D effect (not pushed in))
            }

            if (TagVal == 5) // if slider touched...
            {
                SlideVal = (TrackerVal >> 24); // ... then get the tracker value.
                // Note: Value of tracking is 16 bits but we only use upper 8 bits since the slider is set for 8 bit resolution
            }

            //APP_SnapShot2PPM(); // Un-comment to take snapshot (see BRT_AN_014)

            // Result of button press and slider value will be displayed next time round
        }
    }

    /**
     End of File
     */

    #3
    ezedhill
    Starting Member
    • Total Posts : 78
    • Reward points : 0
    • Joined: 2019/02/07 06:43:05
    • Location: 0
    • Status: offline
    Re: Question about MCC generated code for SPI using PIC24F 2019/07/09 13:55:13 (permalink)
    0
    Here is the MCC generated SPI file. 
     
    /**
      SPI1 Generated Driver API Source File

      Company:
        Microchip Technology Inc.

      File Name:
        spi1.c

      @Summary
        This is the generated source file for the SPI1 driver using PIC24 / dsPIC33 / PIC32MM MCUs

      @Description
        This source file provides APIs for driver for SPI1.
        Generation Information :
            Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.95-b-SNAPSHOT
            Device : PIC24FJ256GB410
        The generated drivers are tested against the following:
            Compiler : XC16 v1.36
            MPLAB : MPLAB X v5.10
    */

    /*
        (c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this
        software and any derivatives exclusively with Microchip products.

        THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
        EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
        WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
        PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
        WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.

        IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
        INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
        WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
        BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
        FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
        ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
        THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.

        MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
        TERMS.
    */

    /**
      Section: Included Files
    */

    #include "spi1.h"

    /**
     Section: File specific functions
    */

    /**
      SPI1 Transfer Mode Enumeration

      @Summary
        Defines the Transfer Mode enumeration for SPI1.

      @Description
        This defines the Transfer Mode enumeration for SPI1.
     */
    typedef enum {
        SPI1_TRANSFER_MODE_32BIT = 2,
        SPI1_TRANSFER_MODE_16BIT = 1,
        SPI1_TRANSFER_MODE_8BIT = 0
    }SPI1_TRANSFER_MODE;

    inline __attribute__((__always_inline__)) SPI1_TRANSFER_MODE SPI1_TransferModeGet(void);
    void SPI1_Exchange( uint8_t *pTransmitData, uint8_t *pReceiveData );
    uint16_t SPI1_ExchangeBuffer(uint8_t *pTransmitData, uint16_t byteCount, uint8_t *pReceiveData);

    /**
     Section: Driver Interface Function Definitions
    */


    void SPI1_Initialize (void)
    {
        //PMD1bits.SPI1MD = 0; // Power the SPI module.
        // AUDEN disabled; FRMEN disabled; AUDMOD I2S; FRMSYPW One clock wide; AUDMONO stereo; FRMCNT 0; MSSEN disabled; FRMPOL disabled; IGNROV disabled; SPISGNEXT not sign-extended; FRMSYNC disabled; URDTEN disabled; IGNTUR disabled;
        SPI1CON1H = 0x00;
        // WLENGTH 0;
        SPI1CON2L = 0x00;
        // SPIROV disabled; FRMERR disabled;
        SPI1STATL = 0x00;
        // SPI1BRGL 0;
        SPI1BRGL = 0x00;
        // SPITBFEN disabled; SPITUREN disabled; FRMERREN disabled; SRMTEN disabled; SPIRBEN disabled; BUSYEN disabled; SPITBEN disabled; SPIROVEN disabled; SPIRBFEN disabled;
        SPI1IMSKL = 0x00;
        // RXMSK 0; TXWIEN disabled; TXMSK 0; RXWIEN disabled;
        SPI1IMSKH = 0x00;
        // SPI1URDTL 0;
        SPI1URDTL = 0x00;
        // SPI1URDTH 0;
        SPI1URDTH = 0x00;
        // SPIEN enabled; DISSDO disabled; MCLKEN FOSC/2; CKP Idle:Low, Active:High; SSEN disabled; MSTEN Master; MODE16 disabled; SMP End; DISSCK disabled; SPIFE Frame Sync pulse precedes; CKE Idle to Active; MODE32 disabled; SPISIDL disabled; ENHBUF enabled; DISSDI disabled;
        SPI1CON1L = 0x8221;

    }

    void SPI1_Exchange( uint8_t *pTransmitData, uint8_t *pReceiveData )
    {

        while( SPI1STATLbits.SPITBF == true )
        {

        }
            
        SPI1BUFL = *((uint8_t*)pTransmitData);

        while ( SPI1STATLbits.SPIRBE == true)
        {
        
        }

        *((uint8_t*)pReceiveData) = SPI1BUFL;
    }

    uint16_t SPI1_ExchangeBuffer(uint8_t *pTransmitData, uint16_t byteCount, uint8_t *pReceiveData)
    {

        uint16_t dataSentCount = 0;
        uint16_t dataReceivedCount = 0;
        uint16_t dummyDataReceived = 0;
        uint16_t dummyDataTransmit = SPI1_DUMMY_DATA;

        uint8_t *pSend, *pReceived;
        uint16_t addressIncrement;
        uint16_t receiveAddressIncrement, sendAddressIncrement;

        addressIncrement = 1;

        // set the pointers and increment delta
        // for transmit and receive operations
        if (pTransmitData == NULL)
        {
            sendAddressIncrement = 0;
            pSend = (uint8_t*)&dummyDataTransmit;
        }
        else
        {
            sendAddressIncrement = addressIncrement;
            pSend = (uint8_t*)pTransmitData;
        }
            
        if (pReceiveData == NULL)
        {
           receiveAddressIncrement = 0;
           pReceived = (uint8_t*)&dummyDataReceived;
        }
        else
        {
           receiveAddressIncrement = addressIncrement;
           pReceived = (uint8_t*)pReceiveData;
        }


        while( SPI1STATLbits.SPITBF == true )
        {

        }

        while (dataSentCount < byteCount)
        {
            if ( SPI1STATLbits.SPITBF != true )
            {

                SPI1BUFL = *pSend;

                pSend += sendAddressIncrement;
                dataSentCount++;

            }

            if (SPI1STATLbits.SPIRBE == false)
            {

                *pReceived = SPI1BUFL;

                pReceived += receiveAddressIncrement;
                dataReceivedCount++;
            }

        }
        while (dataReceivedCount < byteCount)
        {
            if (SPI1STATLbits.SPIRBE == false)
            {

                *pReceived = SPI1BUFL;

                pReceived += receiveAddressIncrement;
                dataReceivedCount++;
            }
        }

        return dataSentCount;
    }

    uint8_t SPI1_Exchange8bit( uint8_t data )
    {
        uint8_t receiveData;
        
        SPI1_Exchange(&data, &receiveData);

        return (receiveData);
    }


    uint16_t SPI1_Exchange8bitBuffer(uint8_t *dataTransmitted, uint16_t byteCount, uint8_t *dataReceived)
    {
        return (SPI1_ExchangeBuffer(dataTransmitted, byteCount, dataReceived));
    }

    inline __attribute__((__always_inline__)) SPI1_TRANSFER_MODE SPI1_TransferModeGet(void)
    {
        if (SPI1CON1Lbits.MODE32 == 1)
            return SPI1_TRANSFER_MODE_32BIT;
        else if (SPI1CON1Lbits.MODE16 == 1)
            return SPI1_TRANSFER_MODE_16BIT;
        else
            return SPI1_TRANSFER_MODE_8BIT;
    }

    SPI1_STATUS SPI1_StatusGet()
    {
        return(SPI1STATL);
    }

    /**
     End of File
    */

     
     
    #4
    ezedhill
    Starting Member
    • Total Posts : 78
    • Reward points : 0
    • Joined: 2019/02/07 06:43:05
    • Location: 0
    • Status: offline
    Re: Question about MCC generated code for SPI using PIC24F 2019/07/09 13:59:05 (permalink)
    0
    Here is the MCC generated pin manager file. I'm using a pic24fj256gb410, MPLAB X v5.10, XC16 v1.36.
     
    /**
      PIN MANAGER Generated Driver File

      @Company:
        Microchip Technology Inc.

      @File Name:
        pin_manager.c

      @Summary:
        This is the generated manager file for the PIC24 / dsPIC33 / PIC32MM MCUs device. This manager
        configures the pins direction, initial state, analog setting.
        The peripheral pin select, PPS, configuration is also handled by this manager.

      @Description:
        This source file provides implementations for PIN MANAGER.
        Generation Information :
            Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.95-b-SNAPSHOT
            Device : PIC24FJ256GB410
        The generated drivers are tested against the following:
            Compiler : XC16 v1.36
            MPLAB : MPLAB X v5.10
    */

    /*
        (c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this
        software and any derivatives exclusively with Microchip products.

        THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
        EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
        WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
        PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
        WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.

        IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
        INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
        WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
        BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
        FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
        ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
        THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.

        MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
        TERMS.
    */


    /**
        Section: Includes
    */

    #include <xc.h>
    #include <stdio.h>
    #include "pin_manager.h"

    /**
     Section: File specific functions
    */

    /**
     Section: Driver Interface Function Definitions
    */
    void PIN_MANAGER_Initialize (void)
    {
        /****************************************************************************
         * Setting the Output Latch SFR(s)
         ***************************************************************************/
        LATA = 0x0000;
        LATB = 0x0000;
        LATC = 0x0000;
        LATD = 0x1000;
        LATE = 0x0000;
        LATF = 0x0000;
        LATG = 0x0000;

        /****************************************************************************
         * Setting the GPIO Direction SFR(s)
         ***************************************************************************/
        TRISA = 0xC6FF;
        TRISB = 0xFFFF;
        TRISC = 0x901E;
        TRISD = 0x8FFA;
        TRISE = 0x03FF;
        TRISF = 0x31BF;
        TRISG = 0xF3CF;

        /****************************************************************************
         * Setting the Weak Pull Up and Weak Pull Down SFR(s)
         ***************************************************************************/
        IOCPDA = 0x0000;
        IOCPDB = 0x0000;
        IOCPDC = 0x0000;
        IOCPDD = 0x0000;
        IOCPDE = 0x0000;
        IOCPDF = 0x0000;
        IOCPDG = 0x0000;
        IOCPDH = 0x0000;
        IOCPDJ = 0x0000;
        IOCPUA = 0x0000;
        IOCPUB = 0x0000;
        IOCPUC = 0x0000;
        IOCPUD = 0x0000;
        IOCPUE = 0x0000;
        IOCPUF = 0x0000;
        IOCPUG = 0x0000;
        IOCPUH = 0x0000;
        IOCPUJ = 0x0000;

        /****************************************************************************
         * Setting the Open Drain SFR(s)
         ***************************************************************************/
        ODCA = 0x0000;
        ODCB = 0x0000;
        ODCC = 0x0000;
        ODCD = 0x0000;
        ODCE = 0x0000;
        ODCF = 0x0000;
        ODCG = 0x0000;
        ODCH = 0x0000;
        ODCJ = 0x0000;

        /****************************************************************************
         * Setting the Analog/Digital Configuration SFR(s)
         ***************************************************************************/
        ANSA = 0xC6ED;
        ANSB = 0xFFFC;
        ANSC = 0x001E;
        ANSD = 0xCFE1;
        ANSE = 0x03FF;
        ANSF = 0x313F;
        ANSG = 0xF3C3;
        ANSH = 0x001F;


        /****************************************************************************
         * Set the PPS
         ***************************************************************************/
        __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS

        RPOR11bits.RP22R = 0x0007; //RD3->SPI1:SDO1
        RPINR20bits.SDI1R = 0x0017; //RD2->SPI1:SDI1
        RPOR12bits.RP24R = 0x0008; //RD1->SPI1:SCK1OUT

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

    }

    #5
    du00000001
    Just Some Member
    • Total Posts : 2887
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Question about MCC generated code for SPI using PIC24F 2019/07/09 15:47:53 (permalink)
    0
    If RD3 is to become SDO (and RD1 SCL), TRISD = 0x8FFA is wrong. I'd expect something like 0x???5.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    ezedhill
    Starting Member
    • Total Posts : 78
    • Reward points : 0
    • Joined: 2019/02/07 06:43:05
    • Location: 0
    • Status: offline
    Re: Question about MCC generated code for SPI using PIC24F 2019/07/09 16:46:59 (permalink)
    0
    I just created another project and I see data now. I don't think the MCC is accurate when you start changing things. This time I used the MCC just one time. Thanks everyone. 
    #7
    pr.mchp
    Starting Member
    • Total Posts : 29
    • Reward points : 0
    • Joined: 2015/03/23 06:20:48
    • Location: 0
    • Status: offline
    Re: Question about MCC generated code for SPI using PIC24F 2019/07/10 01:04:56 (permalink)
    0
    I tired to replicate your configurations multiple times, and everytime the code generated by MCC was consistent and accurate as expected. I could see the output on the pins as well.
     
    As we start changing things, out of the scope of MCC, its our responsibility to make sure all related dots are connected. For example, if we plan to change PPS pins, just changing the assignment will not do. We should also make sure, the corresponding tris, ansel are changed as well.
     
    #8
    ezedhill
    Starting Member
    • Total Posts : 78
    • Reward points : 0
    • Joined: 2019/02/07 06:43:05
    • Location: 0
    • Status: offline
    Re: Question about MCC generated code for SPI using PIC24F 2019/07/10 07:36:32 (permalink)
    0
    Thank you!
    #9
    RDS Cliff
    Junior Member
    • Total Posts : 59
    • Reward points : 0
    • Joined: 2016/09/23 11:50:05
    • Location: 0
    • Status: offline
    Re: Question about MCC generated code for SPI using PIC24F 2019/07/16 16:18:22 (permalink)
    0
    Dumb question: You pressed the "Generate" button after making your changes?  And took care of any merge conflicts manually?
     
    I sometimes forget.
    #10
    Jump to:
    © 2019 APG vNext Commercial Version 4.5