Hey guys,
I am trying to use a DMA and Pointers to help me send A/D values through serial. Right now, I can only get the code to display the values coming in from ADC12MEM0
on my terminal program. The other values being dumped into my RAM are not being transmitted to the terminal. Therefore, I am trying to set up a pointer that will keep track of
where I am in RAM and send every conversion to the terminal. Here is my code, I tried using the comments to explain what I was thinking
# include <msp430xG46x.h>
int ADCSample;
int *Pointer1;
int ADCSample2;
void main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog
P5DIR |= 0x02;
P5OUT |= 0x02;
// Initialization of ADC12//
P6SEL |= 0x01; // Enable A/D channel A0
ADC12CTL0 &= ~ENC; // Disable Conversions
ADC12CTL0 = ADC12ON + SHS_1 + REFON + REF2_5V + MSC; // turn on ADC12, set samp time
ADC12CTL1 = SHP+CONSEQ_2; // Use sampling timer
ADC12MCTL0 = SREF_1+INCH_0; // Vr+=VeREF+ (external)
//ADC12IFG = 0;
//Timer A
TACCR0 = 1500; // Delay to allow Ref to settle
TACCR1 = 1470;
//TACCTL0 |= CCIE; // Compare-mode interrupt.
TACCTL1 = OUTMOD_7;
TACTL = TASSEL_1 + MC_1 + TACLR; // TACLK = ACLK, Up mode.
//__bis_SR_register(LPM3_bits + GIE); // Wait for delay, Enable interrupts
ADC12CTL0 |= ENC; // Enable conversions
// Initialization of Rs-232//
FLL_CTL0 |= XCAP14PF; // Configure load caps
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
_delay_cycles(50000); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
P2SEL |= 0x30; // P2.4,5 = USCI_A0 RXD/TXD
UCA0CTL1 |= UCSSEL_1; // CLK = ACLK
UCA0BR0 = 0x03; // 32k/9600 - 13.65
UCA0BR1 = 0x00; //
UCA0MCTL = 0x06; // Modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0TXIE + UCA0RXIE; // enable RXD and TXD interrupt;
// Initialize DMA
DMACTL0 = DMA0TSEL_6; // ADC12IF set
DMACTL1 = DMAONFETCH;
__data16_write_addr((unsigned short) &DMA0SA, (unsigned long) &ADC12MEM0); // Source address
__data16_write_addr((unsigned short) &DMA0DA, (unsigned long) 0x001108); // Destination single address
DMA0SZ = 0x0FFF; // Set DMA Block size ADCSample size
DMA0CTL = DMADT_4 + DMADSTINCR_3 + DMAIE + DMADSTBYTE + DMASRCBYTE; // Repeat single, inc dst, interrupts
ADCSample = ADC12MEM0; //Set integer to value of ADC12MEM0
Pointer1 = &ADCSample; //Set Pointer1 to the address of ADCSample(Not sure where this address, I want it to be at 0x001108)
DMA0CTL |= DMAEN; //Enable DMA
ADC12CTL0 |= ADC12SC; //Start Conversions
//Serial Loop
while(*Pointer1 <= 0x030FF) // Execute loop until loop reaches 0x030FF address
{
ADCSample2 = *Pointer1; //Set integer to value stored in Pointer1
UCA0TXBUF = ADCSample2 >> 8; //Send upper byte from Pointer1 to Serial
while(!(IFG2 & UCA0TXIFG))
{
__delay_cycles(1000);// wait for first transmit
}
UCA0TXBUF = ADCSample2;
*Pointer1 = (*Pointer1 + 1) &0x030FF; //Increment Pointer1 from address 0x001108 to 0x030FF
__bis_SR_register(LPM0_bits + GIE);
}
}