本帖最后由 13916625369 于 2015-9-18 17:56 编辑
ADC转换 和 fate文件已经实现了 ,现在主要想把数据存下来 放到TF卡里。
基本想法 在内存建立2个512个半字数组,数组1先写入,(这里有个想法是否可以用DMA1 的通道2 来操作,DMA1 通道1我现在是转ADC12双模式的值),等数组1满了,用fate文件的函数创建一个TXT文本到SD卡,同时数组2写入,实现交替写数据。
贴下 ADC转换显示部分程序:
void adc_convert(void)
{
ADC1_ConvertedValue=(uint16_t) (ADC_ConvertedValue );
ADC2_ConvertedValue=(uint16_t) (ADC_ConvertedValue >> 16 );
ADC1_ConvertedValueLocal =(float) ADC1_ConvertedValue/4096*3.3; // ¶Áȡת»»µÄADÖµ
ADC2_ConvertedValueLocal =(float) ADC2_ConvertedValue/4096*3.3; // ¶Áȡת»»µÄADÖµ
}
void app_display_adcprint(void)
{
char str123[30]; //adc value for TFT display
LCD_DispEnCh(50, 50, "------AD²ÉÑùÄ£¿é------", BLUE2);
adc_convert();
printf("\r\n The test AD value = 0x%lX \r\n", ADC_ConvertedValue);
printf("\r\n The AD1 value = 0x%04X \r\n", ADC1_ConvertedValue);
printf("\r\n The AD2 value = 0x%04X \r\n", ADC2_ConvertedValue);
printf("\r\n The current AD1 value = %f V \r\n",ADC1_ConvertedValueLocal);
printf("\r\n The current AD2 value = %f V \r\n",ADC2_ConvertedValueLocal);
LCD_DispStr(50, 70, (uint8_t *) "The AD1 value =", BLUE2);
sprintf(str123,"%f",ADC1_ConvertedValueLocal);
LCD_DispStr(50, 80, (uint8_t *) str123, BLUE2);
LCD_DispChar(112, 80, 'V', BLUE2);
LCD_DispStr(50, 90, (uint8_t *) "The AD2 value =", BLUE2);
sprintf(str123,"%f",ADC2_ConvertedValueLocal);
LCD_DispStr(50, 100, (uint8_t *) str123, BLUE2);
LCD_DispChar(112, 100, 'V', BLUE2);
Delay(0xffffee);
}
ADC DMA设置如下:
static void ADC1_Mode_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
/* DMA channel1 configuration */
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //ADCµØÖ·
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue; //ÄÚ´æµØÖ·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //ÍâÉèµØÖ·¹Ì¶¨
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; //ÄÚ´æµØÖ·¹Ì¶¨
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //È«×Ö
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
// DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //°ë×Ö
// DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //Ñ»·´«Êä
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
/* ADC1 configuration */
ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult ; //¶ÀÁ¢ADCģʽ ADC_Mode_Independent ˫ģʽ ͬ²½ ADC_Mode_RegSimult½
ADC_InitStructure.ADC_ScanConvMode = DISABLE ; //½ûֹɨÃèģʽ£¬É¨ÃèģʽÓÃÓÚ¶àͨµÀ²É¼¯
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //¿ªÆôÁ¬Ðøת»»Ä£Ê½£¬¼´²»Í£µØ½øÐÐADCת»»
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //²»Ê¹ÓÃÍⲿ´¥·¢×ª»»
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //²É¼¯Êý¾ÝÓÒ¶ÔÆë
ADC_InitStructure.ADC_NbrOfChannel = 1; //Ҫת»»µÄͨµÀÊýÄ¿1
ADC_Init(ADC1, &ADC_InitStructure);
ADC_Init(ADC2, &ADC_InitStructure);
/*ÅäÖÃADCʱÖÓ£¬ÎªPCLK2µÄ8·ÖƵ£¬¼´9MHz*/
RCC_ADCCLKConfig(RCC_PCLK2_Div8);
/*ÅäÖÃADC1µÄͨµÀ11Ϊ55. 5¸ö²ÉÑùÖÜÆÚ£¬ÐòÁÐΪ1 */
ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 1, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 1, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_55Cycles5);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
ADC_DMACmd(ADC2, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
ADC_Cmd(ADC2, ENABLE);
/*¸´Î»Ð£×¼¼Ä´æÆ÷ */
ADC_ResetCalibration(ADC1);
ADC_ResetCalibration(ADC2);
/*µÈ´ýУ׼¼Ä´æÆ÷¸´Î»Íê³É */
while(ADC_GetResetCalibrationStatus(ADC1));
while(ADC_GetResetCalibrationStatus(ADC2));
/* ADCУ׼ */
ADC_StartCalibration(ADC1);
ADC_StartCalibration(ADC2);
/* µÈ´ýУ׼Íê³É*/
while(ADC_GetCalibrationStatus(ADC1));
while(ADC_GetCalibrationStatus(ADC2));
/* ÓÉÓÚûÓвÉÓÃÍⲿ´¥·¢£¬ËùÒÔʹÓÃÈí¼þ´¥·¢ADCת»» */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
ADC_SoftwareStartConvCmd(ADC2, ENABLE);
}
|
|