chipKIT® Development Platform

Inspired by Arduino™

SPI & Understanding library development

Created Tue, 13 Sep 2011 21:55:25 +0000 by laelfrog


laelfrog

Tue, 13 Sep 2011 21:55:25 +0000

I'm putting together a TLC5940 Library and am adding SPI for clocking out data to the chip.

We've found helper macros for Output Compares and Timers in outcompare.h and timer.h and thought we might find something like this for SPI, we found spi_legacy.h and spi.h(& spi_3xx_4xx.h). I like some of the functions found in spi_3xx_4xx..h

I found some useful definitions of functions in spi_3xx_4xx.h but can't find the actual functions. Where are they? I want to understand these mechanisms

How is this function implemented and where is it?

void SpiChnPutS(SpiChannel chn, unsigned int* pBuff, unsigned int nChars);

There are other functions that I've seen in timer.h that don't have an implementation anywhere that I can find and I'd like to understand why.


GeneApperson

Tue, 13 Sep 2011 23:22:37 +0000

These functions are part of the Microchip C32 Peripheral Library. The MPIDE distribution doesn't include the source for the plib. However, if you download the MPLAB IDE from the Microchip web site and install it (an evaluation version of the C32 compiler is installed as part of the MPLAB installation), you will get the source code.

The source will be under the following folder tree: [install dir]/MPLAB C32 Suite/pic32-libs/peripheral/...

Because the C32 Peripheral Library isn't open source, we're going to be trying to remove the dependency on it going forward, by incorporating some of that functionality into the core.

Gene Apperson Digilent


laelfrog

Wed, 14 Sep 2011 03:27:46 +0000

Thank you, that was exactly what I was looking for.

I found it in:

MPLAB C32 Suite/pic32-libs/peripheral/spi/source/spi_chn_puts_lib.c

That function is blocking and doesn't use interrupts - so I found what I was looking for.


laelfrog

Sat, 08 Oct 2011 17:54:42 +0000

That function is blocking and doesn't use interrupts - so I found what I was looking for.

It turns out that the function only blocks until its done writing to the TXBuffer... We were seeing an extra 64 SPI CLK pulses after the function returned and this threw us for a loop until we read something about how PIC32 does double buffering of SPI data, so we got 2x 32bit words in the buffers when the function returned causing us some headache and was a little difficult to debug.

So this is what worked for us:

putsSPI2(NUM_OF_WORDS, data);
while(SpiChnIsBusy(SPI_CHANNEL2)); //Blocks until transmission is done.

I'm sure an more asynchronous method of transferring the data using interrupts would be faster, but blocking works at this point.