Skip to content

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

Notifications You must be signed in to change notification settings

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

Repository files navigation

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.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published