# Slow SPI in Particle Argon

**URL:** <https://community.particle.io/t/slow-spi-in-particle-argon/63568>\
**Category:** Firmware\
**Created:** [November 22, 2022, 8:27pm UTC](https://community.particle.io/t/slow-spi-in-particle-argon/63568 "2022-11-22T20:27:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mglazzari](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@mglazzari](https://community.particle.io/u/mglazzari)\
**Post date:** [November 22, 2022, 8:27pm UTC](https://community.particle.io/t/slow-spi-in-particle-argon/63568/1 "2022-11-22T20:27:58Z")

</div>

Hi there  
Trying to drive an SPI display with a Particle Argon. The display refresh is painfully slow (taking about 2 seconds to refresh 240 lines). To investigate, I wrote a simple program sending data over the SPI port:

```auto
#define BLUE_LED D7

// setup() runs once, when the device is first turned on.
void setup() {
  // Put initialization like pinMode and begin functions here.
  pinMode (BLUE_LED, OUTPUT);

  SPI.begin();
}

void loop() {

    SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));
    for (int i=32; i<96; i++){
      SPI.transfer(i);
    }
    SPI.endTransaction();

}

```

I can see the bursts of SPI transfer (8-bit) in the scope measuring less than 1 microsecond, but then pausing for about 12 microseconds before the next byte is transferred.

Can this be improved? I know there’s the possibility of using DMA to transfer but it comes with its complications and I would have to start modifying the display library, which I’d prefer not to do.

I also tried using SINGLE\_THREADED\_BLOCK(){} but no difference.

Any suggestions out there?

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [November 22, 2022, 8:46pm UTC](https://community.particle.io/t/slow-spi-in-particle-argon/63568/2 "2022-11-22T20:46:58Z")

</div>

Definitely switch to using the [DMA-based SPI.transfer API](https://docs.particle.io/reference/device-os/api/spi/transfer-void-void-size_t-std-function/) instead of the single byte API you are using.

---

<div class="post-metadata">

**Author:** ![mglazzari](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@mglazzari](https://community.particle.io/u/mglazzari)\
**Post date:** [November 23, 2022, 12:20am UTC](https://community.particle.io/t/slow-spi-in-particle-argon/63568/3 "2022-11-23T00:20:12Z")

</div>

That worked. Fortunately the display driver was written to send large buffers at a time, so it was easy to adapt. But I still feel that writing individual bytes should not take that long to transfer.

This is the code that I used:

```auto
//callback and flag for DMA SPI transfer ready
volatile bool tranferReadyFlag = false;
void transferReady(){
  tranferReadyFlag = true;
}

//modified WRITEBUF function
INLINE void Arduino_HWSPI::WRITEBUF(uint8_t *buf, size_t count)
{
  //Modified to use Particle DMA SPI transfer
  tranferReadyFlag = false;
  SPI.transfer(buf, buf, count, transferReady);
  //wait until DMA transaction is complete
  while (!tranferReadyFlag);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/2/3291e3c9351789fe8620ae5bcec8d3fec67ff221.png) [@system](https://community.particle.io/u/system)\
**Post date:** [May 24, 2023, 12:20pm UTC](https://community.particle.io/t/slow-spi-in-particle-argon/63568/4 "2023-05-24T12:20:33Z")

</div>

Closed on May 24, 2023, 12:20pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
