9.2 Transmit the Results
The ADC result will be transmitted through USART. To avoid corrupting the adcVal value
because of the interrupt, the result will be stored using another variable, as presented
below.
while (1)
{
if (adcResultReady == 1)
{
/* Store the result to avoid altering adcVal because of the interrupt. This operation must be atomic */
cli();
result = adcVal;
sei();
/* Update the flag value */
adcResultReady = 0;
/* Toggle the LED */
LED0_toggle();
/* Transmit the ADC result to be plotted using Data Visualizer */
USART1_Write(START_TOKEN);
USART1_Write(result & 0x00FF);
USART1_Write(result >> 8);
USART1_Write(END_TOKEN);
}
}