This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How can I read data stored with DTC in MSP430G2553 memory

Other Parts Discussed in Thread: MSP430G2553

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

  • >1) How can I read the data stored in memory?

    Same way as you read any other variable. Array which is filled with data by DTC does not differ from any other array.

    >3) why I can not declare a array with more than 200 values, for example unsigned int valuesADC10[500];

    Because unsigned int valuesADC10[500]; would need 1000 bytes of ram, but msp430g2553 have only 500 bytes of RAM for everything - stack, variables and heap.

  • thanks, now I can understand better

  • >but UART decrease the sampling frequency

    With just one int for the buffer, you can not replace that value until uart have sent the two bytes.
    So that will be the bottle-neck

    A 128 int  buffer using "& 127" for mask, for a rolling buffer so sampling rate can be 2x the uart rate.
    So you will be able to send 250 ints before head overlap the tail, is probably the best you can do.

    Additional option: don't send int's,  as upper 6bits are always zero's it's a waste.
    Putting the upper-two bits from four 10bit sample in to a 5th byte, is a way to make sure uart is not sending empty bits.
    And is not to hard as: you roll left 2bits, OR the upper 10adcmem-byte in and every 4th time you step ahead, using for example
    if (!(++number & 3)) twobitpointer +=5

  • Hello Tony thank for your answer.
    I decided to send the values ​​of conversion to a SD memory and then load the data from the PC, you think I'll have the same problem?. Also , if you have some code to save data to an SD I appreciate it . I was reading the petit´s library but not very clear to me.
  • SD card is flash the same type that your msp430 have, so if you need to sample 1K of data for later/slower transmission,
    you can use a few of msp430's 512byte-flash-blocks, but only if it's no more than once a day as it will wear out.

    other options:
    get a msp with more ram.
    get external spi ram.

**Attention** This is a public forum