Hi,
I'm building something with two SPI devices on a Teensy 3.1 - an ILI9341 SPI display, which works fine on its own with either Paul S' T3 library or the standard Adafruit one.
As soon as I add a second SPI device, the display freezes. The Teensy is still up and running as Serial.print() is working after the SPI stops.
BTW the second SPI device (PGA2311 audio gain cell) isn't fitted at this stage, so its code effectively does nothing other than wiggle the outputs.
Here's a simple version of the Teensyduino code.
I'd be grateful for insights into where I have strayed from the approved SPI path.
Richard
#include <SPI.h>
#include "ILI9341_t3.h"
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
// Shared SPI pins - with PGA2311 Gain Cell
#define TFT_MOSI 11
#define TFT_SCLK 13
#define TFT_MISO 12
// TFT hardware SPI
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
// gain cell shares SPI - so everything but CS is the same.
#define GC_CS 7
#define GC_MUTE 3
setup(){
gcBegin();
}
SPISettings SPIsettingsGC(30000000, MSBFIRST, SPI_MODE1);
void gcBegin(void){
void gcSetVal(uint8_t gain_r, uint8_t gain_l){
loop(){
I'm building something with two SPI devices on a Teensy 3.1 - an ILI9341 SPI display, which works fine on its own with either Paul S' T3 library or the standard Adafruit one.
As soon as I add a second SPI device, the display freezes. The Teensy is still up and running as Serial.print() is working after the SPI stops.
BTW the second SPI device (PGA2311 audio gain cell) isn't fitted at this stage, so its code effectively does nothing other than wiggle the outputs.
Here's a simple version of the Teensyduino code.
I'd be grateful for insights into where I have strayed from the approved SPI path.
Richard
#include <SPI.h>
#include "ILI9341_t3.h"
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
// Shared SPI pins - with PGA2311 Gain Cell
#define TFT_MOSI 11
#define TFT_SCLK 13
#define TFT_MISO 12
// TFT hardware SPI
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
// gain cell shares SPI - so everything but CS is the same.
#define GC_CS 7
#define GC_MUTE 3
setup(){
pinMode(SPI_SS, OUTPUT); digitalWrite(SPI_SS, HIGH);
tft.begin();
tft.fillScreen(ILI9341_BLACK);
...
tft.fillScreen(ILI9341_BLACK);
...
gcBegin();
}
SPISettings SPIsettingsGC(30000000, MSBFIRST, SPI_MODE1);
void gcBegin(void){
// assume SPI core pins are already set (MISO, MOSI, SCK)
// add CS pin
pinMode(GC_CS, OUTPUT);
digitalWrite(GC_CS, HIGH);
// toggle MUTE low for > 2ms to reset gain cell
if (GC_MUTE < 255) {
// add CS pin
pinMode(GC_CS, OUTPUT);
digitalWrite(GC_CS, HIGH);
// toggle MUTE low for > 2ms to reset gain cell
if (GC_MUTE < 255) {
pinMode(GC_MUTE, OUTPUT);
digitalWrite(GC_MUTE, HIGH); // Make sure a reset isn't already underway
delay(100);
digitalWrite(GC_MUTE, LOW);
delay(20);
digitalWrite(GC_MUTE, HIGH);
delay(150); // stabilise after MUTE
digitalWrite(GC_MUTE, HIGH); // Make sure a reset isn't already underway
delay(100);
digitalWrite(GC_MUTE, LOW);
delay(20);
digitalWrite(GC_MUTE, HIGH);
delay(150); // stabilise after MUTE
}
}void gcSetVal(uint8_t gain_r, uint8_t gain_l){
SPI.beginTransaction(SPISettings(SPIsettingsGC));
digitalWrite(GC_CS, LOW);
SPI.transfer(gain_r);
SPI.transfer(gain_l);
SPI.transfer(gain_l);
digitalWrite(GC_CS, HIGH);
SPI.endTransaction();
}loop(){
tft.setCursor(10,90);
tft.print("Display");
gcSetVal(30, 40);
}tft.print("Display");
gcSetVal(30, 40);