Hardware SPI1 on Teensy-LC

Status
Not open for further replies.

vitormhenrique

Well-known member
Question is pretty simple,

I'm having issues sharing the SPI port on teensy-lc. So I want to use the second hardware SPI on it, how do I access it?

It is going to drive an ST7735S TFT Display, I could use software SPI but if I can make the hardware SPI work would be great.

I know that I need to tweak the library, so I'll need to create a new constructor, with the new SPI pins and say that it is indeed hardware SPI.

Current the constructors on the library are, changing this is simple :)

Code:
// Constructor when using software SPI.  All output pins are configurable.
Adafruit_ST7735::Adafruit_ST7735(int8_t cs, int8_t rs, int8_t sid, int8_t sclk, int8_t rst) 
  : Adafruit_GFX(ST7735_TFTWIDTH, ST7735_TFTHEIGHT_18)
{
  _cs   = cs;
  _rs   = rs;
  _sid  = sid;
  _sclk = sclk;
  _rst  = rst;
  hwSPI = false;
}


// Constructor when using hardware SPI.  Faster, but must use SPI pins
// specific to each board type (e.g. 11,13 for Uno, 51,52 for Mega, etc.)
Adafruit_ST7735::Adafruit_ST7735(int8_t cs, int8_t rs, int8_t rst) 
  : Adafruit_GFX(ST7735_TFTWIDTH, ST7735_TFTHEIGHT_18) {
  _cs   = cs;
  _rs   = rs;
  _rst  = rst;
  hwSPI = true;
  _sid  = _sclk = 0;
}

But when transferring data for the SPI I'm not sure about this part:

Code:
 if (hwSPI) {
#if defined (SPI_HAS_TRANSACTION)
      SPI.transfer(c);
#elif defined (__AVR__)
      SPCRbackup = SPCR;
      SPCR = mySPCR;
      SPI.transfer(c);
      SPCR = SPCRbackup;
//      SPDR = c;
//      while(!(SPSR & _BV(SPIF)));
#elif defined (__arm__)
      SPI.setClockDivider(21); //4MHz
      SPI.setDataMode(SPI_MODE0);
      SPI.transfer(c);
#endif
  }

How do I call SPI1?


Entire library code is here:

https://github.com/adafruit/Adafruit-ST7735-Library
 
Status
Not open for further replies.
Back
Top