Hello,
I need to convert an amount of samples and then send via uart, I first tried to convert and send each sample , but UART decrease the sampling frequency, for this reason I use DTC to hold the samples and then send, but :
1) How can I read the data stored in memory?
2) If I want to store 500 or more samples, I have to use continuously DTC or used several blocks
3) why I can not declare a array with more than 200 values, for example unsigned int valuesADC10[500];
code here....
#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
volatile long tempRaw;
volatile unsigned int i = 0, nMuestras = 0, j =0;
//volatile int dato;
//volatile int vec [200];
int *pointer = 512;
void FaultRoutine(void);
void ConfigWDT(void);
void ConfigClocks(void);
void ConfigLEDs(void);
void ConfigADC10(void);
void ConfigTimerA2(void);
void EnviarUart(void);
//void EnviarSpi(void);
void ConfigUart(void);
//void ConfigSpi(void);
void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigLEDs();
ConfigADC10();
ConfigUart();
ConfigTimerA2();
//ConfigSpi();
__enable_interrupt();
while(1)
{
__bis_SR_register(LPM1_bits + GIE);
ADC10CTL0 &= ~ENC; // Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON); // Ref and ADC10 off
//vec[i] = ADC10MEM;
i++;
if(i==nMuestras){
CCTL0 &= ~CCIE;
ADC10SA = 0;
EnviarUart();
}
}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
}
void ConfigClocks(void)
{
if (CALBC1_16MHZ ==0xFF || CALDCO_16MHZ == 0xFF)
FaultRoutine(); // If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_16MHZ; // Set range
DCOCTL = CALDCO_16MHZ; // Set DCO step + modulation
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_0 + DIVS_3; // MCLK = DCO/1, SMCLK = DCO/8
}
void FaultRoutine(void)
{
P1OUT = BIT0; // P1.0 on (red LED)
while(1); // TRAP
}
void ConfigLEDs(void)
{
P1DIR = BIT0; // P1.6 and P1.0 outputs
P1OUT = 0; // LEDs off
P1SEL |= BIT1 + BIT2;
P1SEL2 |= BIT1 + BIT2;
}
void ConfigADC10(void)
{
//ADC10CTL1 = INCH_3 + INCH0 + ADC10DIV_0 ;
ADC10CTL1 = INCH_3 + ADC10DIV_0 ; // ADC10CLK
ADC10CTL0 = SREF_0 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + MSC;
ADC10AE0 = 0x8;
//ADC10AE0 = 0x9;
//ADC10DTC0 |= ADC10TB;
ADC10DT0 |= ADC10CT;
ADC10DTC1 = 255;
//ADC10SA = (unsigned int)512;
}
void ConfigUart(void){
UCA0CTL1 = UCSSEL_2 | UCSWRST;
UCA0MCTL = UCBRF_0 | UCBRS_3;
UCA0BR0 = 208;
UCA0BR1 = 0;
UCA0CTL1 &= ~UCSWRST;
IE2 |= UCA0RXIE;
}
void ConfigTimerA2(void)
{
TACTL = TASSEL_2;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
ADC10CTL0 |= ENC + ADC10SC;
While (ADC10TL1 & ADC10BUSY);
_bic_SR_register_on_exit(LPM1_bits);
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR_HOOK(void)
{
//_bic_SR_register_on_exit(LPM1_bits);
}
void EnviarUart(void){
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = '{';
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = 0;
while(j<nMuestras){
tempRaw = pointer++;
j++;
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = tempRaw;
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = tempRaw>>8;
}
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = '}';
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = 0;
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR_HOOK(void)
{
if (IFG2 & UCA0RXIFG) {
if(UCA0RXBUF == 'C'){
ADC10SA = (unsigned int)512;
P1OUT ^= BIT0;
CCR0 = 4000-1;
CCTL0 = CCIE;
nMuestras = 500;
i=0;
TACTL |= MC_1;
}
if(UCA0RXBUF == 'V'){
ADC10SA = (unsigned int)512;
P1OUT ^= BIT0;
CCR0 = 80-1;;
CCTL0 = CCIE;
nMuestras = 1000;
i=0;
TACTL |= MC_1;
}
}
}
thanks