我用的是TA的触发信号,然后想在AD转换的中断里把转换的数据写进SD卡的文件里,但是总是只能写一次的数据,不能接着上次写的数据写。文件系统用的FAT16格式的。贴一段代码,大家看看是哪里出问题了。
#include <msp430x14x.h> #include "mmc.h" #include "fAT16.h" #include <stdio.h> #include <string.h>
unsigned long cardSize = 0; unsigned char status = 1; unsigned int timeout = 0; int i = 0; int z=0; char buffer[512]=""; char str[16]; int k=0; unsigned int AC[200]={0}; //存放交流结果 uint8 Name[11]; #define Num_of_Results 64 int results[Num_of_Results] = {0};
void ADC_Init(void);
void main(void) { WDTCTL = WDTPW | WDTHOLD; // Disable the Watchdog. while (status != 0) // if return in not NULL an error did occur and the
// MMC/SD-card will be initialized again { status = initMMC(); timeout++; if (timeout == 50) // Try 50 times till error { printf ("No MMC/SD-card found!! %x\n", status); break; } } while ((mmc_ping() != MMC_SUCCESS)); // Wait till card is inserted // Read the Card Size from the CSD Register cardSize = MMC_ReadCardSize(); ReadBPB(); uint8 Name[11]="TEST0000TXT"; CreateFile(Name); P4DIR=0x03; ADC_Init(); // Initialize ADC12 ADC12CTL0 |= ENC; // Start conversion while(1); }
void ADC_Init(void) { P1DIR = 0xff; // set port to outputs P1OUT = 0; // reset port outputs P6SEL |= 0x01; // select A0 input ADC12CTL0 = ADC12ON+SHT0_1+REF2_5V+REFON; // Setup ADC12 ADC12CTL1 = SHP+CONSEQ_2+SHS_1; // Timer triggers sampling ADC12MCTL0 = INCH_0 + SREF_1; ADC12IE = 0x0001; // Enable ADC12IFG.0
TACCR0 = 32; // Delay to allow Ref to settle TACCTL0 |= CCIE; // Compare-mode interrupt. TACTL = TASSEL_1 | MC_1; // TACLK = ACLK, Up mode. _BIS_SR(LPM3_bits + GIE); // Wait for delay, Enable interrupts TACCTL0 &= ~CCIE; // Disable timer
P2SEL |= BIT3; // Set for Timer A1 P2DIR |= 0x08; TACCR0 = 32; // Init TACCR0 w/ sample prd=CCR0+1 TACCR1 = 16; // Trig for ADC12 sample & convert TACCTL1 = OUTMOD_3; // Set/reset TACTL = TACLR | MC_1 | TASSEL_1; // ACLK, clear TAR, up mode }
// Timer_A0 Interrupt Service Routine #pragma vector=TIMERA0_VECTOR __interrupt void ta0_isr(void) { TACTL = 0; LPM0_EXIT; // Exit LPM0 on return }
// ADC12 Interrupt Service Routine #pragma vector=ADC12_VECTOR __interrupt void ADC12ISR (void) { if(z%2==0) { P4OUT=0x01; results[z++]=ADC12MEM0; } else { P4OUT=0x02; results[z++]=ADC12MEM0;
if (z == 64) { z = 0; for(int j=0;j<64;j++) { sprintf(str,"%04x ",results[j]); strcat(buffer,str); } OperateFile(1,"TEST0000TXT",k*512,512,buffer); k++; } } }
|