chipKIT® Development Platform

Inspired by Arduino™


Created Sat, 12 Apr 2014 10:34:27 +0000 by adymages1


Sat, 12 Apr 2014 10:34:27 +0000


I am a beginner, but want to learn how to use spi on MX4ck.

I have try to connect PmodALS on MX4ck JB connector, i searched on google for some example of code but have not found anything.

Can can someone help me with parts of code?

Thank you!


Mon, 14 Apr 2014 19:17:40 +0000

Are you trying to implement it using MPLAB or MPIDE?


Mon, 14 Apr 2014 20:25:55 +0000



Wed, 16 Apr 2014 20:33:16 +0000

There should be two SPI libraries included when you download MPIDE: SPI and DSPI. DSPI lets you use any of the SPI ports on your board. There should be some examples included with MPIDE. Go to File->Examples->DSPI and check out one of those examples. For JB on the MX4cK, you will need to use the object instance DSPI0.


Tue, 06 May 2014 11:36:16 +0000

Can you give me an example of code for PmodALS?

I have try to make some code for ALS but didn't work.


Wed, 14 May 2014 16:15:10 +0000

You just need to read two bytes from the ADC via SPI. If you use the DSPI library, you'll use an array to store you received values. The 0th element will be the MSB and the 1st element will be the LSB. Shift the MSB to the left by four and the LSB to the right by 4, and bitwise or them together to get your final ADC value.

For code showing how to run the spi transfer, take a look at the DSPI sample code.