新手入门
- 积分
- 18
- 金钱
- 18
- 注册时间
- 2019-3-5
- 在线时间
- 2 小时
|
1金钱
#include "stm32f10x.h"
#include "SysTick.h"
#include "sdio_sdcard.h"
#include "usart1.h"
#include "adc_dma.h"
#include "key_led.h"
#include "ff.h"
#define usart_EN 1
int res;
FIL fdst;
FATFS fs;
UINT br, bw; // File R/W count
BYTE textFileBuffer[] = "ch0,ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9,ch10,ch11,ch12,ch13,ch14,ch15\r\n";
uint8_t start_flag;
uint8_t end_flag;
uint8_t usart_finished;
int main(void)
{
uint8_t i,j;
start_flag=0;
end_flag=0;
Free_Buf_Now=BUF2;
Buf_Ok=0;
SysTick_Init();
LED_GPIO_Config();
EXTI_PE5_Config();
USART1_Config(115200);/* USART1 config */
// USART1_Config();
SD_NVIC_Configuration();/* Interrupt Config */
adc_dma_config();
printf ( "\r\n test starting......\r\n" );
while(1)
{
//while(!(start_flag==1));
start_flag=0;
f_mount(0,&fs);
// res = f_open(&fdst,"0:/êy¾Y.TXT",FA_CREATE_ALWAYS | FA_WRITE); //ÿ′Î′æ′¢oó¸2¸ÇÔ′Îļt
res = f_open(&fdst,"0:/êy¾Y.TXT",FA_CREATE_ALWAYS | FA_WRITE); //ÿ′Î′æ′¢oó¸2¸ÇÔ′Îļt
printf ( "Îļt′ò¿a£¨′′½¨£©3é1|.\r\n" );
if (res==FR_OK)
{
printf("Open File Succes!\r\n");
GPIO_WriteBit(GPIOE,GPIO_Pin_3,Bit_SET);
f_lseek(&fdst, f_size(&fdst)); // point to the end of a file
res = f_write(&fdst, textFileBuffer, sizeof(textFileBuffer), &bw);
adc_dma_start();
for(;;)
{
res=f_sync(&fdst); //±ß2é¼ˉ±ß±£′æÎÄμμ,oüÖØòa£¡£¡£¡
if(Buf_Ok==1)
{
Buf_Ok=0;
if(Free_Buf_Now==BUF1)
{
dma_2_set();
adc_start();
for(i=0;i<TT_NUM;i++)
{
for(j=0;j<CH_NUM-1;j++)
f_printf(&fdst, "%d,",ad1[i][j]);
f_printf(&fdst, "%d\r\n",ad1[i][CH_NUM-1]);
}
//printf("1\r\n");
}
else if(Free_Buf_Now==BUF2)
{
dma_1_set();
adc_start();
for(i=0;i<TT_NUM;i++)
{
for(j=0;j<CH_NUM-1;j++)
f_printf(&fdst, "%d,",ad2[i][j]);
f_printf(&fdst, "%d\r\n",ad2[i][CH_NUM-1]);
}
//printf("2\r\n");
}
}
if(end_flag==1)
{
end_flag=0;
break;
}
}
GPIO_WriteBit(GPIOE,GPIO_Pin_3,Bit_RESET);
printf("end!\r\n");
}
else
{
printf("Open File Failed!\r\n");
//GPIO_WriteBit(GPIOE,GPIO_Pin_4,Bit_RESET);
}
f_close(&fdst); /* 1رÕ′ò¿aμÄÎļt */
printf("closed!\r\n");
}
}
/*******************************************************END OF FILE************/
为什么写入SD卡失败呢?
|
|