Hello!

I don't quite understand the state of SPI on the bela. Can you or can you not use it at the same time as you're using audio?
http://bela.io/archive/faq.html#18
^ This makes me think I can't
https://forum.bela.io/d/107-features-on-bela-system
https://blog.bela.io/2018/02/22/bela-mini-launch/
^ These don't suggest any such limitations

Thing is I have a LED driver breakout board (TLC5947) that uses SPI. But if that doesn't work I'll have to get one that uses I2C instead.

Cheers!

I see! I'll take a look at soft-spi then, speed shouldn't be an issue for my application. Thanks!

    6 days later

    ErikNatanael curious as to how you progress on this. need SPI for implementing an OLED screen myself, but I'm afraid that the soft SPI will be too slow for drawing graphics. Not sure though. soft SPI is too slow on an Arduino Mega (hardware SPI is fine). Looking at the PRU thing (never heard of this term before) seems like way too much hazzle for just attaching a screen. I might be wrong? .. Maybe I should go teensy on this instead...

    EDIT: or maybe I should just wait for the new small bela, seeing it has hardware SPI.. it's just so few I/O's on that thing... what a whiny man I am

      soeren I'm afraid that the soft SPI will be too slow for drawing graphics

      Are you using the analog out at all? The SPI bandwidth currently used by those could be used to transmit 88200 32-bit words per second, if that suits your application. The limitation is that each transaction would have to be 32bit long, which may - or may not - be what your screen requires?

      In all fairness, the spi-pru implementation would probably work fairly easily if the already-implemented polarity and phase match those on the SPI screen.

      6 days later

      Haven't gotten around to it yet since my LEDs haven't arrived yet, unfortunately. I'll keep you posted!

      4 days later

      Also, I was thinking that you can bitbang the SPI protocol using the Bela digital or analog outputs! This should give you about 22.05kHz bitrate if using the digital outputs, or 44.1kHz using the analog outputs at 88.2kHz (which could also mean running them at 22.05kHz and OR-wire together the odd and even channels) ... lots of possibilities there. I have some untested code for that:

      
      int clockChannel = //Bela digital channel where to send the clock
      int misoChannel = // Bela digital channel where to send the data
      int chipSelectChannel= // Bela digital channel to use as chip select(if needed)
      // device-dependent configuration:
      bool chipSelectIdle = 1; //  chip select idle value
      bool chipSelectActive = 0; // chip select active value
      bool samplingEdge = 1; // 1 means that the receiving device samples on a rising clock edge, 0 means it samples on a falling edge
      bool nonSamplingEdge = !samplingEdge;
      bool setup()
      {
        pinMode(context, 0, clockChannel, OUTPUT);
        pinMode(context, 0, misoChannel, OUTPUT);
        pinMode(context, 0, chipSelectChannel, OUTPUT);
      }
      
      void render()
      {
      ...
      static bool outputBitValue = 0;
      static bool chipSelectOutputValue = chipSelectIdle;
      static bool clockValue = 0;
      static uint32_t outputWord;
      static int clockCount;
      
      static int currentIndexInOutputWord = -1;
      static unsigned int wordLength = sizeof(outputWord);
      
      for(int n = 0; n < context->digitalFrames; ++n)
      {
        if(newWordAvailableToWrite) // up to you
        {
            outputWord = // set value here;
            currentIndexInOutputWord = 0;
            chipSelectOutputValue = chipSelectActive;
            clockCount = 0;
        }
        if(currentIndexInOutputWord >= 0)
        {
          // generate a clock at half sampling rate
          if((clockCount++ & 2) == 0)
          {
            clockValue = samplingEdge;
          }
          else
          {
            clockValue = nonSamplingEdge;
            outputBitValue = (bool)(outputWord & (1 << currentIndexInOutputWord));
            ++currentIndexInOutputWord;
          }
      
          if(currentIndexInOutputWord == wordLength && clockValue == samplingEdge)
          {
            currentIndexInOutputWord = -1; // done transmitting one word
            chipSelectOutputValue = chipSelectIdleValue;
          }
        }
        // write clock
        digitalWriteOnce(context, n, clockChannel, clockValue);
        // write output bit
        digitalWriteOnce(context, n, misoChannel, outputBitValue);
        // write chip select value
        digitalWriteOnce(context, n, chipSelectChannel, chipSelectValue);
      }
      ...
      }