Hello,
I am progressing on a project that contains a timer interrupt...which samples temperature from the ADC. I would like to store that temperature into memory(FLASH or EEPROM...it doesn't matter) so that I can retrieve it when desired.
There is a while(1) loop after the EEPROM code. I want to replace the while loop with some type of user input...press a button, etc to move on and transmit the data.
Before the loop/logic I'd like to store temperature F to memory. After the loop/logic I would like to READ from memory and store to msg.tempF for the rest of the program to use.
I tried to set pui32Read to msg.tempF and I simply got the address of pui32Read. How do I get the contents? That was with EEPROM of course...i wasn't sure how to even get started reading flash.
Thanks!
void Timer0IntHandler(void)
{
int32_t intStatus;
message_t msg;
uint8_t * ptr,
byte;
uint32_t ui32ADC0Value[4];
volatile uint32_t ui32TempAvg;
volatile uint32_t ui32TempValueC;
volatile uint32_t ui32TempValueF;
uint32_t pui32Data[1];
uint32_t pui32Read[1];
//////////////////////////////////////////////////////////////////////////
//Enable the gpio led pins
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //For Flash testing
GPIOPinTypeGPIOOutput
(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x00);
SysCtlDelay(20000000); //End of flash testing
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//Enable the analog to digital converter. ADC0
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
///////////////////////////////////////////////////////////////////////////
// Retrieve timer interrupt status.
intStatus = TimerIntStatus(TIMER0_BASE, true);
// Clear interrupt.
TimerIntClear(TIMER0_BASE, intStatus);
// Check if the interrupt was the correct one (timeout).
if((intStatus & TIMER_TIMA_TIMEOUT) == TIMER_TIMA_TIMEOUT)
{
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1);
ADCIntClear(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);
while(!ADCIntStatus(ADC0_BASE, 1, false)) //Unknown time in this loop.
{
}
ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
//Allows for whole number temperature. Does not allow for floating point values. Look at data sheet
ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
//ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;
ui32TempValueF = (ui32TempValueC * 9/5) + 32;
//////////////////////////////////////////////////////////////////////////
//Programs the data array we created, to the start of the block(10k), of the length of the array
pui32Data[0] = ui32TempValueF;
FlashErase(0x10000);
FlashProgram(pui32Data, 0x10000,sizeof(pui32Data));
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x02);
SysCtlDelay(20000000);
SysCtlPeripheralEnable (SYSCTL_PERIPH_EEPROM0);
EEPROMInit();
EEPROMMassErase();
EEPROMRead(pui32Read, 0x0, sizeof(pui32Read));
EEPROMProgram(pui32Data, 0x0, sizeof(pui32Data));
EEPROMRead(pui32Read, 0x0, sizeof(pui32Read));
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x04);
while(1){
}
//////////////////////////////////////////////////////////////////////////
msg.tempF = ui32TempValueF;
UARTprintf("\nTemperature sent is %d\n",msg.tempF);
// Cast the structure into a byte array.
ptr = (uint8_t *)&msg;
// Loop through the entire message.
for(byte = 0; byte < sizeof(message_t); byte++)
{
// Is there space in the Tx FIFO?
if(UARTSpaceAvail(UART1_BASE) == true)
{
// Put the byte into the Tx FIFO.
UARTCharPut(UART1_BASE, ptr[byte]);
}
else
{
// Otherwise, stash the byte in our FIFO for when there's space.
RingBufWriteOne(&txRingBuf, ptr[byte]);
}
}
}
}