Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In the PICpilot, SPI is used for communication with the GPS, VectorNav (IMU), and the two individual cores (CPU/Microcontrollers). The GPS uses SPI2, the VectorNav uses SPI2, and the crosstalk between chips uses SPI1.

In the code

Each dspic33fj256gp710a has two SPI interfaces. They are labeled SPI1 and SPI2. In the code, you won't find any SPI files present. The initialization functions are embedded in the corresponding peripheral files. The SPI1 configuration can be found on both chips, in the file, InterchipDMA.c, as well as the corresponding .h file. The function in those files is init_SPI1. In addition, on the secondary chip (in other words, the path management chip), the SPI2 (GPS) interface is also enabled in the InterchipDMA.c file, as well as the header file. The function is called init_SPI2.

...

The most important settings are listed below.

SPI1 – DMA and SPI2 - GPS

Code Block
//Set interrupts

IFS0bits.SPI1IF = 0;

IEC0bits.SPI1IE = 1;

IPC2bits.SPI1IP = 4;

SPI1BUF = 0;

//SPI clock controlled by this module

SPI1CON1bits.DISSCK = 0;

//Output pins are controlled by this module

SPI1CON1bits.DISSDO = 0;

//16/8 bit communication mode (1/0)

SPI1CON1bits.MODE16 = 1; //16

//Master mode(1)/Slave mode(0)

SPI1CON1bits.MSTEN = 0; //Slave

//Enable Slave Select

SPI1CON1bits.SSEN = 0;

//Sample Phase (end/middle)

SPI1CON1bits.SMP = 0; //Sample the input at the middle of the square wave

//Clock Edge Select

SPI1CON1bits.CKE = 0; //Output data changes from idle state to active clock state (1 is the opposite)

//Clock Polarity

SPI1CON1bits.CKP = 0; //Idle clock state is low, active clock state is high

//Enable SPI

SPI1STATbits.SPIEN = 1;

Register

Value

Function

IFS0bits.SPI1IF

0

This is the interrupt flag for the SPI1 interface.

IEC0bits.SPI1IE

1 (0 for GPS)

This is the interrupt enable bit for the SPI1 interface. This allows interrupts to occur.

IPC2bits.SPI1IP

4 (0 for GPS)

This determines the priority of every interrupt that occurs from the SPI1 interface.

SPI1BUF

0

This is the buffer that is used for sending and receiving data. This is buffer is for both reading and writing.

SPI1CON1bits.DISSCK

0

This bit allows the SPI1 module to control the clock.

SPI1CON1bits.DISSDO

0

This bit allows the SPI1 module to convert the usual GPIO pins into SPI1 pins.

SPI1CON1bits.MODE16

1

This allows 16 bits to be transmitted per message.

SPI1CON1bits.MSTEN

0 or 1

This determines if the chip is the master (attitude manager) or the slave (path manager).

SPI1CON1bits.SSEN

0

This value enables the slave select pin.

SPI1CON1bits.SMP

0

This determines the sampling time of the SPI interface. 0 forces sampling in the middle of the square wave, 1 forces sampling at the end of the square wave.

SPI1CON1bits.CKE

0

This bit determines when the transmitted square wave changes states. 0 means it changes from clock low to high. 1 is the opposite.

SPI1CON1bits.CKP

0

Determines the clock polarity. 0 means that active clock state is high, idle state is low. 1 is the opposite.

SPI1STATbits.SPIEN

1

Enables the entire SPI module.

SPI2 - VectorNav

The VectorNav SPI configuration is very similar. The differences are listed below:

...