• 0

How to use the digilent spi in an arduino program to convert it to a chipkit Uc32 program



I have a program that work on Arduino Uno. It is the graphictest given by adafruit with all their librarys for the tft 2.2" screen ili9340c https://www.adafruit.com/products/1480.


I would like to make it work on the chipkit uc32 or chipkit Max32 or chipkit wf32 but don't know what line to put  so the spi can work correctly on it. I tried to  put this code before the arduino code but still have a lot of errors with the spi part. I just don't know how to transfer the dspi to an arduino program to make it work on the chipkit uc32. Is there somebody who can help me with this.


Thank You,

Best Regards,


  This is an example sketch for the Adafruit 2.2" SPI display.
  This library works with the Adafruit 2.2" TFT Breakout w/SD card
  ----> http://www.adafruit.com/products/1480
  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
// #include "SPI"
#include "DSPI.h"  // I PUT THAT
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"

// pour Arduino Due car c'est ce type de microcontrolleur sam3x8e
#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal

//// pour pic32
    #if defined(__PIC32MX__)
      #ifndef _P32XXXX_H
      #define _P32xxxx_H
      #include <p32xxxx.h>
      #define __C32_UART __XC_UART
      #ifndef _P32MX340F512F_1
      #define _P32MX340F512H_1 //_P32xxxx_H
      #include <plib.h>
      #ifndef _XC_H
      #include <xc.h>
   #endif /* _P32XXXX_H */
     /* For backwards compatibility */
  #undef __FlashStringHelper::F(string_literal)
  #define F(string_literal) string_literal

// These are the pins used for the UNO
// for Due/Mega/Leonardo use the hardware SPI pins (which are different)
#define _sclk 13  //connecteur spi sur Arduino Due
#define _miso 12  //connecteur spi sur Arduino Due
#define _mosi 11  //connecteur spi sur Arduino Due
#define _cs 10
#define _dc 9
#define _rst 8  //connecteur spi sur Arduino Due

// Using software SPI is really not suggested, its incredibly slow
//Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);
// Use hardware SPI
Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);

void setup() {
  while (!Serial);
  Serial.println("Adafruit 2.2\" SPI TFT Test!");

  Serial.println(F("Benchmark                Time (microseconds)"));
  Serial.print(F("Screen fill              "));

  Serial.print(F("Text                     "));

  Serial.print(F("Lines                    "));




Share this post

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

I shouldn't bother if I were you - you'd only be reinventing the wheel.  Instead use the proper chipKIT display libraries - DisplayCore.

You need at least two libraries - the core library and the display driver:

There's no example with the driver for that screen at the moment, but you can try:

#include <DSPI.h>
#include <DisplayCore.h>
#include <ILI9340.h>

DSPI0 spi;
// Pin 10 is CS, pin 9 is DC, 8 is RST.
ILI9340 tft(spi, 10, 9, 8);

void setup() {
    tft.setTextColor(Color::Red, Color::Black);

void loop() {
    tft.setCursor(20, 20);


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now