This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/CC2640R2F: Advice for ADC data logging application

Part Number: CC2640R2F

Tool/software: TI-RTOS

I am trying to create a Bluetooth Low Energy application based on the Simple Peripheral example from the Simple link Academy. The end goal of the application is to take readings from an array of temperature sensors every minute using ADC, store those values non volatile storage, then periodically come by and collect all of data that has been logged.

I have successfully taken readings from each of the sensors periodically, and stored the results in non volatile storage using the Empty project, but I am having trouble moving the code into the Simple Peripheral example. Below is the code from my Empty project. How would I implement this code in the Simple Peripheral project to achieve the functionality I am looking for?

  /* Global Variables */
  uint16_t tempOne = 0;
  uint16_t tempTwo = 0;
  uint16_t tempThree = 0;
  uint16_t salinity = 0;

  /* Struct */
  struct Datapoint {
      uint16_t t1;
      uint16_t t2;
      uint16_t t3;
      uint16_t sal;
  } dp;

  struct Datapoint buffer[1];

  /*
   *  ======== mainThread ========
   */

  void *mainThread(void *arg0)
  {
    /* 1 second delay */
    uint32_t time = 1;

    /* Call driver init functions */
    GPIO_init();
    ADC_init();
    // I2C_init();
    // SDSPI_init();
    // SPI_init();
    // UART_init();
    // Watchdog_init();

    /* Open Display Driver */
    Display_Handle    displayHandle;
    Display_Params    displayParams;
    Display_Params_init(&displayParams);
    displayHandle = Display_open(Display_Type_UART, NULL);
    Display_printf(displayHandle, 0, 0, "\nDisplay driver initialized");

    /* Open NVS Driver */
    NVS_Handle nvsHandle;
    NVS_Attrs regionAttrs;
    NVS_Params nvsParams;
    NVS_init();
    NVS_Params_init(&nvsParams);
    nvsHandle = NVS_open(Board_NVS0, &nvsParams);
    if (nvsHandle == NULL) {
        Display_printf(displayHandle, 0, 0, "NVS_open() failed.");
        return (NULL);
    }
    Display_printf(displayHandle, 0, 0, "NVS driver initialized");
    NVS_getAttrs(nvsHandle, &regionAttrs);
    /* Erase the entire flash region */
    NVS_erase(nvsHandle, 0, regionAttrs.regionSize);
    /* Print NVS region details */
    Display_printf(displayHandle, 0, 0, "\tRegion base address: 0x%x",
            regionAttrs.regionBase);
    Display_printf(displayHandle, 0, 0, "\tSector size: 0x%x",
            regionAttrs.sectorSize);
    Display_printf(displayHandle, 0, 0, "\tRegion size: 0x%x",
            regionAttrs.regionSize);

    /* Open ADC Driver*/
    int_fast16_t res;
    ADC_Params params;
    ADC_Params_init(&params);

    /* ADC Pin for tempOne - DIO23 */
    ADC_Handle adcOne;
    adcOne = ADC_open(Board_ADC0, &params);
    if (adcOne == NULL) {
        // Error initializing ADC channel 0
        Display_print0(displayHandle, 0, 0, "Error initializing ADC channel 0");
        while (1);
    }

    /* ADC Pin for tempTwo - DIO24 */
    ADC_Handle adcTwo;
    adcTwo = ADC_open(Board_ADC1, &params);
    if (adcTwo == NULL) {
        // Error initializing ADC channel 1
        Display_print0(displayHandle, 0, 0, "Error initializing ADC channel 1");
        while (1);
    }

    /* ADC Pin for tempThree - DIO25 */
    ADC_Handle adcThree;
    adcThree = ADC_open(Board_ADC2, &params);
    if (adcThree == NULL) {
        // Error initializing ADC channel 2
        Display_print0(displayHandle, 0, 0, "Error initializing ADC channel 2");
        while (1);
    }

    /* ADC Pin for salinity - DIO26 */
    ADC_Handle adcFour;
    adcFour = ADC_open(Board_ADC3, &params);
    if (adcFour == NULL) {
        // Error initializing ADC channel 3
        Display_print0(displayHandle, 0, 0, "Error initializing ADC channel 3");
        while (1);
    }
    Display_print0(displayHandle, 0, 0, "ADC driver initialized");

    /* Start red LED in the off state */
    GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_OFF);
    Display_printf(displayHandle, 0, 0, "Starting sample collection\n");

    /* Collect 10 data samples from each sensor */
    uint8_t ix = 0;
    while (ix < 10) {
        /* Toggle red LED ON to indicate start of loop */
        GPIO_toggle(Board_GPIO_LED0);

        /* Read temperature sensors using ADC Driver
         * tempOne - Pin DI023
         * tempTwo - Pin DIO24
         * tempThree - Pin DIO25
         * salinity - Pin DIO26
         */
        res = ADC_convert(adcOne, &tempOne);
        if(res != ADC_STATUS_SUCCESS){
          Display_printf(displayHandle, 0, 0, "Sensor tempOne reading failed!");
        }
        res = ADC_convert(adcTwo, &tempTwo);
        if(res != ADC_STATUS_SUCCESS){
          Display_printf(displayHandle, 0, 0, "Sensor tempTwo reading failed!");
        }
        res = ADC_convert(adcThree, &tempThree);
        if(res != ADC_STATUS_SUCCESS){
          Display_printf(displayHandle, 0, 0, "Sensor tempThree reading failed!");
        }
        res = ADC_convert(adcFour, &salinity);
        if(res != ADC_STATUS_SUCCESS){
          Display_printf(displayHandle, 0, 0, "Sensor salinity reading failed!");
        }

        dp.t1 = tempOne;
        dp.t2 = tempTwo;
        dp.t3 = tempThree;
        dp.sal = salinity;
        buffer[0] = dp;

        /* Print readings to display */
        Display_printf(displayHandle, 0, 0, "tempOne: %d\t tempTwo: %d\t tempThree: %d\t salinity: %d", tempOne, tempTwo, tempThree, salinity);

        /* Write data sample to memory */
        NVS_write(nvsHandle, (ix * sizeof(dp)), (void *) buffer, sizeof(buffer), NULL);

        /* Toggle red LED OFF to indicate end of loop */
        GPIO_toggle(Board_GPIO_LED0);

        /* Sleep for one second */
        sleep(time);
        ix++;
    }
    Display_printf(displayHandle, 0, 0, "\nSample collection completed");
    Display_printf(displayHandle, 0, 0, "Reading collected samples from NVS\n");

    // Reset ix
    ix = 0;

    /* Read data samples stored in memory and print to display */
    while (ix < 10) {
        NVS_read(nvsHandle, (ix * sizeof(dp)), (void *) buffer, sizeof(buffer));
        /* Print readings to display */
        dp = buffer[0];
        Display_printf(displayHandle, 0, 0, "tempOne: %d\t tempTwo: %d\t tempThree: %d\t salinity: %d", dp.t1, dp.t2, dp.t3, dp.sal);
        ix++;
    }