PublishQueueAsyncSdFat and other SPI devices

I am attempting to use the implementation of PublishQueueAsyncRK that uses an sdCard for persistent storage of publish events, however at the same time a requirement of this application is to publish asynchronously the values of another SPI chip that is read every 50ms, the code looks something like this:

bool readFlag = false;
bool publishFlag = false;

void readTimerHandler() { readFlag = true; }
void publishTimerHandler() { publishFlag = true; }

Timer readTimer(50, powerTimerHandler);
Timer publishTimer(2000, publishTimerHandler);


void loop() {
    if(readFlag) {
        // use SPI to read values from sensor here
    if(publishFlag) {
        // use PublishQueueAsyncSdFat to publish the data, asynchronously using the queue

I am encountering problems with this code (seizes execution and returns a loop error 1) and I believe this issue to be related to the queue library using the SPI for the sd card while at the same time my sensors using the SPI for reading.

It is paramount that the reading of the sensors take place every 50ms, I have experimented with pausing the publishing of the queue, adding all of the events, and then resuming once the readings are finished, however this results in the same loop error 1.

Thanks in advance, Ozzie

Do you really need 2 Timers for this ?
IMHO if you will implement simple int counter incremented every 50ms and then publish after counter reach 40 then start over ? Maybe there’s an issue with Timers not with PublishQueueAsyncRK

I haven’t checked recently, but in the past ENABLE_SPI_TRANSACTIONS was not defined in SdFatConfig.h. Without that, horrible things will happen as the two libraries will interfere with each other.

If that’s still the case, the easiest option is to build in Workbench and just change the value in the local copy of the library. If you edit the local source, be sure to remove it from otherwise when you cloud compile the official library will be used instead of the locally modified version.

1 Like

Thank you so much, saved me a ton of head scratching. Enabling transactions with sdFat was the key, as well as implementing the use of SPI.enableTransaction(); with my other sensors.

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