8 years, 9 months ago.

UARTService issues: waitForEvent() not continuing

Trying to get a string from a cfg file to be read and displayed on my OLED display. I have got the sd card working and trying to debug getting it going with the OLED (Both SPI). The SDCard reader doesn't like using many pins (BLENano). The OLED object works fine by itself (without SD).

What I expect this program to do is wait until DataWritten(callback) then break out of the waitForEvent loop. Then execute the SDCard access and OLED init and drawString blah blah...

Currently this program stays on the bleWaitForEvent() with the P0_19 (LED1 on the board) being switched each time you write to RX via the android UART app made by Nordic.

=

#include "mbed.h"
#include "SDFileSystem.h"
#include "ConfigFile.h"
#include "FTOLED.h"
#include "Arial14.h"
#include "FTOLED_Colours.h"
#include "BLE.h"

#include "UARTService.h"

BLEDevice  ble;
DigitalOut led1(P0_19);
UARTService *uart;
bool        condition=false;
ConfigFile cfg;
SDFileSystem sd(P0_7,  P0_6,  P0_15, P0_29, "sd"); //(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
OLED lcd(P0_9,P0_11,P0_8,P0_10,P0_4,P0_5);  //OLED(PinName mosi, PinName miso, PinName sclk, PinName ncs, PinName dc, PinName reset)


void periodicCallback(const GattWriteCallbackParams *params)
{
    led1 = !led1;
    condition=true;
}


int main()
{
    ble.init();

    uart = new UARTService(ble);
    ble.onDataWritten(periodicCallback);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
                                     (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                     (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));

    ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
   
    ble.startAdvertising();


    while (true) {
        
        while(!condition);
            ble.waitForEvent();



        lcd.begin();
        lcd.setDisplayOn(true);
        lcd.selectFont(Arial14);
        char value[BUFSIZ];


        uart->writeString("Hello World!\n");

        mkdir("/sd/mydir", 0777);

        FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");

        if(fp == NULL) {
            uart->writeString("Could not open file for write\n");
        }
        fprintf(fp, "Hello fun SD Card World!");
        fclose(fp);

        cfg.write("/sd/mycfg.cfg");
        cfg.removeAll();
        cfg.setValue("ABC", "123");
        cfg.setValue("DEF", "456");
        cfg.write("/sd/mycfg.cfg");

        cfg.read("/sd/mycfg.cfg");

        cfg.getValue("ABC", &value[0], sizeof(value));

        lcd.drawString(10,10, value, RED,BLACK);

        uart->writeString("Goodbye World!\n");
        condition=false;
    }
}
Be the first to answer this question.