Where is the definition of SPCR in teensy3 core?

Status
Not open for further replies.

christoph

Well-known member
I have removed this question from another thread where it might not be discovered.

The SPI library shipped with teensyduino uses the SPCR emulation object when compiled for the Teensy 3.x. Where is SPCR defined? I only see an external declaration, but no definition. I've search for SPCR in my local copy of the teensyduino core as well as in Pauls online repo, without sucess.

Currently the SPI library doesn't compile in my environment, because the linker can't find SPCR. Can anyone tell me where SPCR is defined or what I might be missing here?

Regards

Christoph
 
I only see an external declaration there. Line 1034:
Code:
extern SPCRemulation SPCR;
So there must be some c or cpp file defining it?
 
Oh, there's also avr_emulation.cpp that allocates storage for the static "pinout" member.

There is no instance for this class. All of the functions are static inline, so no instance of the object actually exists.
 
Oooh ok, that makes sense, but then my linker complaining about a missing reference to SPCR doesn't make sense. Maybe some compiler flag missing in my setup...
 
OK I compiled and ran the following code successfully, using my own setup in Code::Blocks.
Hardware: Connect the SPI's DOUT (11) to DIN (12)
Code:
#include <SPI.h>

SPISettings settings(12000000, MSBFIRST, SPI_MODE0);

void setup()
{
  while(!Serial.available());
  while(Serial.available())
  {
    Serial.read();
  }
  Serial.print("Hi! Testing an SPI transfer: ");
  pinMode(LED_BUILTIN, OUTPUT);

  SPI.begin();
  SPI.beginTransaction(settings);
  char d = 0xAA;
  char r = 0;
  r = SPI.transfer(d);
  if (r == d)
  {
    Serial.println("success!");
  }
  else
  {
    Serial.println("bad!");
  }
  Serial.println("Ending transaction"); Serial.flush();
  SPI.endTransaction();

  Serial.println("Setup done."); Serial.flush();
  SPI.end();
}

void loop()
{
  digitalWriteFast(LED_BUILTIN, true);
  delay(500);
  digitalWriteFast(LED_BUILTIN, false);
  delay(500);
}
So the definition of SPCR is indeed not necessary and the root cause for the linker error I got must be somewhere else.
 
Last edited:
christoph,
I have found that if I need a library in a source or header file other than the main pde that I have to include the library header files in the pde for the other files to find them. I suspect that is what you had issues with. I don't know why it is like that as most other compilers I have used have not worked that way. I am also on the Windows platform so it might be a platform specific issue.

Edit:
To help explain better.

In file test.h:
Code:
#include <SPI.h>

blah blah blah

If I do not include SPI.h in the pde file as well, then the test.h file cannot find SPI.h.
 
Last edited:
Status
Not open for further replies.
Back
Top