高中生
最后登录1970-1-1
在线时间 小时
注册时间2015-10-20
|
楼主 |
发表于 2015-10-30 10:42:27
|
显示全部楼层
#include "stm32f10x.h"
#include "bsp_sdio_sdcard.h"
#include "bsp_usart1.h"
#include "ff.h"
#include "mpu6050.h"
#include "bsp_i2c.h"
#include "stm32f10x_it.h"
#include "stdio.h"
#define uchar unsi
#define TASK_ENABLE 0
extern unsigned int Task_Delay[NumOfTask];
FIL fnew;
u8 i=0;
u8 byte; /* file objects */
FATFS fs; /* Work area (file system object) for logical drives */
FRESULT res;
UINT br, bw; /* File R/W count */
BYTE buffer[10000]; /* file copy buffer */
BYTE write_buf[10];
short Accel[3];
u8 flag=0,j=0;
short Gyro[3];
short Temp;
u16 pointer=0;
void delay (int x)
{ int i,j;
for (i=0;i<x;i++)
for(j=0;j<600;j++);
}
void read(void)
{
res = f_open(&fnew, "0:飞行数据.txt", FA_OPEN_EXISTING | FA_READ);
pointer=fnew.fsize;
res=f_read(&fnew, buffer,sizeof(buffer) , &br);
printf("\r\n %s ", buffer);
printf("\r\n完成\r\n\r\n" );
f_close(&fnew);
}
int main(void)
{
i2c_GPIO_Config();
MPU6050_Init();
USART1_Config();
printf("\r\n 飞行数据采集系统 \r\n");
NVIC_Configuration();
f_mount(0,&fs);
res = f_open(&fnew, "0:飞行数据.txt", FA_CREATE_ALWAYS | FA_WRITE );
f_close(&fnew);
while(1)
{
delay(10000);
if(Task_Delay[1]==0)
{
MPU6050ReadAcc(Accel);
printf("\r\n加速度参考:%8d",Accel[0] );
write_buf[0]='a';
write_buf[1]='c';
write_buf[2]=':';
write_buf[3]=Accel[0]/10000+0X30;
write_buf[4]=Accel[0]%10000/1000+0X30;
write_buf[5]=Accel[0]%1000/100+0X30;
write_buf[6]=Accel[0]%100/10+0X30;
write_buf[7]=Accel[0]%10+0X30;
write_buf[8]=0x0d;
write_buf[9]=0x0a;
}
if ( res == FR_OK )
{
res = f_open(&fnew, "0:飞行数据.txt", FA_CREATE_ALWAYS | FA_WRITE );
pointer=fnew.fsize;
res=f_lseek(&fnew,pointer);
res=f_lseek(&fnew,pointer+j);
res = f_write(&fnew, &write_buf, sizeof(write_buf), &bw);
res=f_sync(&fnew);
i++;
// f_lseek(&fnew, f_size(&fnew));
f_close(&fnew);
printf("\r\n写成功%d",i );
j=j+10;
read();
delay(10000);
}
}
/* Close open files */
/* Unregister work area prior to discard it */
f_mount(0, NULL);
}
|
|