Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C

Raspberry<-->SPI<-->Microchip

5.00/5 (1 vote)
19 Feb 2016CPOL2 min read 11.6K   87  
Raspberry master, Pic24 slave over SPI

Introduction

Raspberry Pi2 master and Pic24FJ64GB002 slave communicate over SPI.

I consulted the following links:

I used:

  • VisualGDB to program Raspberry
  • MPLAB X IDE v3.21 to program Pic
  • pc: ASUS AMD X550ZE + Windows10
  • developement board Microchip: Microstick II

Scheme 1

SLAVE (Pic24)                      MASTER (Raspberry)
Pin                                        Pin (GPIO)
 5        SDO1  ------------->   SPI0MISO      21
 4        SDI1   <-------------  SPI0MOSI      19
 6        SCk1  <--------------  SPI0SCLK      23
 7        SS1    <-------------    CS0         24

27        GND  ---------------     GND          9

Load Ras in Raspberry, setting permissions. Load Sette HEX in Pic24FJ64GB002. Connect pins like scheme 1. Launch Ras.

Raspberry sends a number to Pic24 and Pick24 takes 17 from it and sends it back. Then Raspberry increments.

Image 1

Load SpiWiring in Raspberry, setting permissions. Load Sette1 HEX in Pic24FJ64GB002. Connect pins like scheme 1. Launch SpiWiring.

Image 2

This arrangement has 8 bit for Pic24 and for Raspberry: standard device with 8 bit default. I reach 200KHz.

Load PiGpioM in Raspberry, setting permissions. Load Sette2 HEX in Pic24FJ64GB002. Connect pins like scheme 1. Launch PiGpioM.

Raspberry sends a triplet to Pic24 and Pic sends back the triplet minus 15, then Raspberry increments the triplet by one. There is alignment to put better.

Image 3

This arrangement has 16 bit for Pic24 and for Raspberry. Unfortunately, PiGpio doesn't have write or read functions to transfer 16 bit, but only 8 bit at a time. So I don't see the advantage of using auxiliary device for Raspberry. It's better the standard device with 8 bit default. Anyway, below is word mode. I reach 360KHz.

Load PiGpioM1 in Raspberry, setting permissions. Load Sette3 HEX in Pic24FJ64GB002. Connect pins like scheme 2. Launch PiGpioM1.

Raspberry sends a couple to Pic24 and Pic sends back the couple multiplied by 4, then Raspberry increments the couple by one.

Scheme 2

SLAVE (Pic24)                      MASTER (Raspberry)
     Pin                                                 Pin (GPIO)
      5        SDO1  ------------->   SPI0auxMISO          35
      4        SDI1   <-------------    SPI0auxMOSI        38
      6        SCk1  <--------------   SPI0auxSCLK         40
      7        SS1    <-------------    CS0aux             12  

     27        GND  ---------------    GND                  9

Image 4

PiGpioxxx projects want some include directives under VisualGDB:

Image 5

Background

Enabling Raspberry's SPI with rasp-config; elementary knowledge of embedded microcontrollers.

Points of Interest

There are 3 approaches of Raspberry to Pic24: first is raw GNU code (1 byte); second and third custom libraries.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)