Hi everyone,
I am trying to use the two block continues transfer (DTC) using the MPS430 microcontroller. I have created a very simple program that it seems to work fine, but I am trying to figure out what it is the best way to synchronize the writing to the each block and the reading from the main program. I am using a variable called readingBlockNum to synchronize between the called to the interrupt (when a block has been written)and the main loop, but I doubt that it is the best way to do it.
I would appreciate if anyone can suggest a better solution
volatile char readingBlockNum = 0;
void main()
{
int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
// Some clk configuration...
adc_Setup();
while(1)
{
// Adding some dummy processing
for(i = 0;i<100;i++)
{
readingBlockNum = 1;
__delay_cycles(100);
}
for(i = 0;i<100;i++)
{
readingBlockNum = 2;
__delay_cycles(100);
}
// Enable the ADC
ADC10CTL0 |= ENC + ADC10SC; // Enable Conversion and conversion start
}
}
void adc_Setup()
{
ADC10CTL1 = ADC10SSEL_0 + CONSEQ_2; // Repeat single channel and ADC10OSC (5MHz)CLK
ADC10CTL0 = ADC10SHT_1 + MSC + ADC10ON + ADC10IE;
ADC10AE0 |= 0x01; // P1.0 ADC option select
ADC10DTC0 |= ADC10TB + ADC10CT; // Continous two block transfers
ADC10DTC1 = 0x64; // 100*2 conversions
ADC10SA = (int)adc;
ADC10CTL0 |= ENC + ADC10SC; // Start sampling continously
__enable_interrupt(); // Enable interrupts
}
#pragma vector = ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
if (ADC10DTC0 & ADC10B1)
{
if(readingBlockNum == 2) // if the main is currently reading the 2 block, we stop to overwrite to the 2 block
ADC10CTL0 &= ~ENC;
}
else
{
if(readingBlockNum == 1) // if the main is currently reading the 1 block, we stop to overwrite to the 1 block
ADC10CTL0 &= ~ENC;
}
}