GithubHelp home page GithubHelp logo

microchip-pic-avr-examples / pic18f47q10-cnano-spi-driver-mplab-mcc Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 664 KB

This code example demonstrates how to communicate as host and client using SPI protocol in interrupt and polling mode on PIC18F47Q10 with MPLAB MCC Melody.

License: Other

Makefile 4.14% C 95.86%
curiosity curiosity-nano mcc mcc-melody melody mssp spi spi-protocol

pic18f47q10-cnano-spi-driver-mplab-mcc's Introduction

Microchip Technologies Inc.

SPI Driver Using the PIC18F47Q10 Microcontroller and MCC Melody

This code example demonstrates how to communicate as host and client using the Serial Peripheral Interface (SPI) protocol in Interrupt and Polling modes on a PIC18F47Q10 microcontroller with MPLAB® Code Configurator (MCC) Melody. The SPI Host demo writes data to a seven-segment display upon the press of a hardware button. The SPI Client demo exchanges data between two PIC18F47Q10 microcontrollers and displays the exchanged data on a serial terminal.

Related Documentation

Software Used

Hardware Used

  1. Download the ZIP file containing the source code and extract it.
  2. Connect the 7seg Click board to Curiosity Nano Base on mikroBUS™ port 1.
  3. Connect the Curiosity Nano board to the Curiosity Nano Base.
  4. Connect the Curiosity Nano board to the system.
  5. Open MPLAB X IDE.
  6. Click File>Open Project.
  7. Navigate to the extracted source code folder and select both projects with spi-host in the project names.
  8. Click the Open Project button in the window.
    Open SPI Host Projects
  9. The following configuration was made in MCC Melody UI for SPI Host Driver polling project with Interrupt Driven toggled on for the interrupt project:
    Host Configuration
  10. The following pin configurations were made in MCC Melody UI for both SPI Host Driver projects:
    Host Pin Configuration

Operation: Host Polling

  1. From the Projects window on MPLAB, right click the pic18f47q10-spi-host-polling project and select Make and Program Device to program the code to the device.
    Make and Program Host Polling
  2. A dialog box will pop up to select the tool to be programmed. Select the connected tool from the drop-down box. Click OK.
    Select Device
  3. The seven-segment display will now show -- once the programming is complete.
  4. Press SW0 on the Curiosity Nano. The display will now show 00.
  5. Press SW0 again to increment the number showed on the seven-segment display.

Operation: Host Interrupt

  1. From the Projects window on MPLAB, right click the pic18f47q10-spi-host-interrupt project and select Make and Program Device to program the code to the device.
    Make and Program Host interrupt
  2. A dialog box will pop up to select the tool to be programmed. Select the connected tool from the drop-down box. Click OK.
    Select Device
  3. The seven-segment display will now show -- once the programming is complete.
  4. Press SW0 on the Curiosity Nano. The display will now show 00.
  5. Press SW0 again to increment the number showed on the seven-segment display.
  1. Download the ZIP file containing the source code and extract it.

  2. Connect the Serial Data Out (SDO), Serial Data In (SDI), Serial Clock (SCK), Chip Select 1 (CS1) and Ground (GND) pins of two Curiosity Nano boards to each other. The following pinouts are required for the PIC18F47Q10 demonstration:

    Pin Function Hardware Pin
    SDO RC4
    SDI RC5
    SCK RC6
    CS1 RD4
    GND GND
  3. Open MPLAB X IDE.

  4. Click File>Open Project.

  5. Navigate to the extracted source code folder and select all three projects with spi-client in the project names.

  6. Click the Open Project button in the window.
    Open SPI Client Projects

  7. Connect one development board to the system. Make note of the serial number on the back of the development board.

  8. From the Projects window on MPLAB, right click the pic18f47q10-spi-client-tester project and select Make and Program Device to program the code to the device.
    Make and Program Client Tester

  9. A dialog box will pop up to select the tool to be programmed. Select the connected tool from the drop-down box. Click OK.
    Select Device

  10. After programming the device, the on-board LED0 will flash once every second indicating that it is working as expected. The setup for testing client projects is now complete. Disconnect the tester for now. The spi-client-polling and spi-client-interrupt projects are preconfigured as mentioned in the next two points.

  11. The following configuration was made in MCC Melody UI for SPI Client Driver polling project with Interrupt Driven toggled on for the interrupt project:
    client Configuration

  12. The following pin configurations were made in MCC Melody UI for both SPI Client Driver projects:
    client Pin Configuration

Operation: Client Polling

  1. Open MPLAB Data Visualizer from the toolbar above. Alternatively, go to Window>Debugging>Data Visualizer.
  2. With the Data Visualizer open, connect the other development board to the system. Make note of the COM port assigned to the connected device. See example below:
    MPLAB Data Visualizer COM Port
  3. Hover the cursor over the COM port of the device just connected and select the option Display as Text in the Terminal.
    MPLAB Data Visualizer COM Port
  4. Now connect the tester development board used in Setup for Client Demo to the system. The client tester will start working automatically.
  5. From the Projects window on MPLAB, right click the pic18f47q10-spi-client-polling project and select Make and Program Device to program the code to the device.
    Make and Program Client Polling
  6. A dialog box will pop up to select the tool to be programmed. From the drop-down box select a different tool from the one selected before in Setup for Client Demo. The serial number can be found on the back of the development board. Click OK.
    Select Device
  7. Once the programming is complete, the terminal window in Data Visualizer will display the results. If the data exchange happens as expected, SUCCESS will be displayed in the terminal. See the example below:
    Client Communication Success

Operation: Client Interrupt

  1. Open MPLAB Data Visualizer from the toolbar above. Alternatively, go to Window>Debugging>Data Visualizer.
  2. With the Data Visualizer open, connect the other development board to the system. Make note of the COM port assigned to the connected device. See example below:
    MPLAB Data Visualizer COM Port
  3. Hover the cursor over the COM port of the device just connected and select the option Display as Text in the Terminal.
    MPLAB Data Visualizer COM Port
  4. Now connect the tester development board used in Setup for Client Demo to the system. The client tester will start working automatically.
  5. From the Projects window on MPLAB, right click the pic18f47q10-spi-client-interrupt project and select Make and Program Device to program the code to the device.
    Make and Program Client Interrupt
  6. A dialog box will pop up to select the tool to be programmed. From the drop-down box select a different tool from the one selected before in Setup for Client Demo. The serial number can be found on the back of the development board. Click OK.
    Select Device
  7. Once the programming is complete, the terminal window in Data Visualizer will display the results. If the data exchange happens as expected, SUCCESS will be displayed in the terminal. See the example below:
    Client Communication Success

Summary

The demo provides examples of both host and client communication using the SPI protocol in Interrupt and Polling modes of operation. The demo utilizes firmware code generated using MCC Melody.

pic18f47q10-cnano-spi-driver-mplab-mcc's People

Contributors

aku-work avatar pratyushmangalakattu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.