Try this, hopefully it makes it work again. If you still see those 4294967295, open the scope and take a few snapshots
#include <Bela.h>
#define USE_SCOPE
#ifdef USE_SCOPE
#include <libraries/Scope/Scope.h>
Scope gScope;
const unsigned int kClockLoopbackPin = 2;
#endif // USE_SCOPE
const unsigned int kClockPin = 0;
const unsigned int kDataPin = 1;
const unsigned int kNumBits = 24;
// number of clock pulses being written:
// - 25: differential input
// - 26: temperature or DVDD-AVDD
// - 27: differential input, gain 128
const unsigned int kDataType = 25;
uint32_t inputWord;
bool setup(BelaContext* context, void*)
{
#ifdef USE_SCOPE
gScope.setup(5, context->digitalSampleRate);
pinMode(context, 0, kClockLoopbackPin, INPUT);
#endif // USE_SCOPE
pinMode(context, 0, kClockPin, OUTPUT);
pinMode(context, 0, kDataPin, INPUT);
return true;
}
static unsigned int gCount = 100000;
void render(BelaContext* context, void*)
{
for(unsigned int n = 0; n < context->digitalFrames; ++n)
{
unsigned int kFramesPerClock = 4;
unsigned int kSamplingBit = kFramesPerClock - 1;
unsigned int loopbackDelay = context->digitalFrames * 2 + 1;
if(gCount > loopbackDelay + kNumBits * 2 + 200) {
// data pin goes low means data is ready and a new acquisition cycle can start
if(digitalRead(context, n, kDataPin) == 0)
{
gCount = 0;
inputWord = 0;
}
}
bool dataReady = false;
bool clk = 0;
if(gCount < kDataType * kFramesPerClock) // write the clock output
clk = !(gCount % kFramesPerClock);
digitalWriteOnce(context, n, kClockPin, clk);
bool sampling = false;
unsigned int samplingCount = gCount - loopbackDelay;
if(samplingCount < kNumBits * kFramesPerClock)
{
// after the loopback delay, read the data in on the falling edge
if((samplingCount % kFramesPerClock) == kSamplingBit)
{
sampling = true;
// shift data in on odd frames
bool bit = digitalRead(context, n, kDataPin);
inputWord <<= 1;
inputWord |= bit;
}
}
if(loopbackDelay + kNumBits * kFramesPerClock - 1 == gCount)
{
dataReady = true;
// input is ready
// extend sign
if (inputWord & 0x800000)
inputWord |= 0xFF000000;
rt_printf("%llu inputWord: %u\n", context->audioFramesElapsed + n, inputWord);
}
gCount++;
#ifdef USE_SCOPE
float logs[] = {
logs[0] = dataReady * 0.09f - 0.05f,
logs[1] = clk * 0.09f + 0.01f,
logs[2] = digitalRead(context, n, kDataPin) * 0.09f + 0.2f,
logs[3] = digitalRead(context, n, kClockLoopbackPin) * 0.09f + 0.3f,
logs[4] = sampling * 0.09f + 0.4f,
};
gScope.log(logs);
#endif // USE_SCOPE
}
}
void cleanup(BelaContext* context, void*)
{
}