Hi all,
Thought I had this figured out once, but ust can't get it to work again.
What I am trying to do is use SERCOM from within a library to set up a second SPI port on a Zero clone. I am trying to set up this second SPI to handle a touchscreen on a display. I am using the XPT2046_Touchscreen library found here: GitHub - PaulStoffregen/XPT2046_Touchscreen: Touchscreen Arduino Library for XPT2046 Touch Controller Chip
Here's the Zero sketch that I am using:
#include <XPT2046_Touchscreen.h>
#define CS_PIN 7
// MOSI=11, MISO=12, SCK=13
XPT2046_Touchscreen ts(CS_PIN);
//#define TIRQ_PIN 2
//XPT2046_Touchscreen ts(CS_PIN); // Param 2 - NULL - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, 255); // Param 2 - 255 - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN); // Param 2 - Touch IRQ Pin - interrupt enabled polling
void setup() {
SerialUSB.begin(9600);
ts.begin();
ts.setRotation(1);
while (!SerialUSB || (millis() <= 5000));
SerialUSB.println("TouchTest - started.\n");
}
void loop() {
if (ts.touched()) {
TS_Point p = ts.getPoint();
SerialUSB.print("Pressure = ");
SerialUSB.print(p.z);
SerialUSB.print(", x = ");
SerialUSB.print(p.x);
SerialUSB.print(", y = ");
SerialUSB.print(p.y);
delay(20);
SerialUSB.println();
}
delay(100);
}
Here's where I am trying to define the SPI port at in the 2046XPT_touchscreen.cpp file at:
#include "XPT2046_Touchscreen.h"
#include "wiring_private.h" // pinPeripheral() function
#include <SPI.h>
SPIClass tsSPI (&sercom1, 12, 13, 11, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_3);
#define Z_THRESHOLD 400
#define Z_THRESHOLD_INT 75
#define MSEC_THRESHOLD 3
#define SPI_SETTING SPISettings(2000000, MSBFIRST, SPI_MODE0)
static XPT2046_Touchscreen *isrPinptr;
void isrPin(void);
bool XPT2046_Touchscreen::begin()
{
tsSPI.begin();
// Assign pins 11, 12, 13 to SERCOM functionality
pinPeripheral(11, PIO_SERCOM);
pinPeripheral(12, PIO_SERCOM);
pinPeripheral(13, PIO_SERCOM);
pinMode(csPin, OUTPUT);
digitalWrite(csPin, HIGH);
if (255 != tirqPin) {
pinMode( tirqPin, INPUT );
attachInterrupt(digitalPinToInterrupt(tirqPin), isrPin, FALLING);
isrPinptr = this;
}
return true;
}
I am attaching my sketch and the library files as I am using them currently.
Could someone enlighten me as to where I am going wrong?
Thanks,
Randy
2.8_zero_TouchTest.ino (860 Bytes)
XPT2046_Touchscreen.h (2.44 KB)
XPT2046_Touchscreen.cpp (5.05 KB)