I used the fflush function before and after the fprintf statement to no avail. Here is the code that I am using now:
FILE *analog_values = fopen("analog_values.txt", "w");
int x = 0;
while (x < 500)
{
LPADC_DoSoftwareTrigger(DEMO_LPADC_BASE, 1U); /* 1U is trigger0 mask. */
while (!g_LpadcConversionCompletedFlag)
{
}
PRINTF("ADC value: %d\r\n",
((g_LpadcResultConfigStruct.convValue) >> g_LpadcResultShift));
g_LpadcConversionCompletedFlag = false;
if (analog_values == NULL)
{
PRINTF("File could not be opened\n");
}
fprintf(analog_values, "%d\n", (g_LpadcResultConfigStruct.convValue) >> g_LpadcResultShift);
fflush(analog_values);
if ( (int)g_LpadcResultConfigStruct.convValue > 0 && (int)g_LpadcResultConfigStruct.convValue < 16384)
{
GPIO_PinWrite(GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, 1);
GPIO_PinWrite(GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, 0);
GPIO_PinWrite(GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, 0);
}
else if ( (int)g_LpadcResultConfigStruct.convValue > 16384 && (int)g_LpadcResultConfigStruct.convValue < 32768)
{
GPIO_PinWrite(GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, 0);
GPIO_PinWrite(GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, 1);
GPIO_PinWrite(GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, 0);
}
else if ( (int)g_LpadcResultConfigStruct.convValue > 32768 && (int)g_LpadcResultConfigStruct.convValue < 49152)
{
GPIO_PinWrite(GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, 0);
GPIO_PinWrite(GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, 0);
GPIO_PinWrite(GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, 1);
}
else if ((int)g_LpadcResultConfigStruct.convValue > 49152 && (int)g_LpadcResultConfigStruct.convValue < 65536)
{
GPIO_PinWrite(GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, 1);
GPIO_PinWrite(GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, 1);
GPIO_PinWrite(GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, 1);
}
else
{
GPIO_PinWrite(GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, 1);
}
x++;
}
fclose(analog_values);
return 0;
}