Array scan time: Sketch vs. Lib

Status
Not open for further replies.

btmcmahan

Well-known member
Okay, I'm on the last hurdle of my SPI Slave library.
Here's my problem:
I am creating an array for data the slave will receive from the master.
Assuming the array has a length of, lets say, 100.

When I put the array in my lib it doesn't it doesn't write fast enough.
When I put the array in my main sketch it works fine.

It's being used by my interrupt every time data is received.

if I use:
receivedData[pointer] = SPI0_POPR;
everything works fine.

if I use:
SPI_SLAVE.receivedData[pointer] = SPI0_POPR;
I get problems due to the array not writing fast enough.

Any ideas? Is there a way to use arrays faster? Here is my interrupt code:

Code:
void spi0_isr(void){               //SPI Interrupt
  receivedData[pointer] = SPI0_POPR;
  pointer++;
  
  if (pointer == dataLength){
    pointer=0;}

  SPI0_PUSHR_SLAVE = SPI_SLAVE.returnData[pointer];  
  SPI0_SR |= SPI_SR_RFDF;
}
 
Last edited:
Any ideas? Is there a way to use arrays faster?

You'll probably need to make the array a static variable. There's 2 steps.

First, just add "static" in front of its definition inside the .h file.

Second, you'll have to actually allocate its memory in the .cpp file. Static members aren't automatically allocated by the object's instance. Also, if you ever tried to create more than one instance of the object, they would all share the same array. So a static array probably only works if your design is intended to only have 1 instance of the object. Since this is for the one and only SPI port, that's probably not an issue?

Use something like this in your .cpp file:

Code:
spi_slave_class::receivedData[100];

I don't know what class name you library uses, since I can't see your .h file, but just substitute your actual name and it should work.
 
Status
Not open for further replies.
Back
Top