高中生
最后登录1970-1-1
在线时间 小时
注册时间2015-10-20
|
#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"
#define uchar unsi
#define TASK_ENABLE 0
extern unsigned int Task_Delay[NumOfTask];
FIL fnew;
/* file objects */
FATFS fs; /* Work area (file system object) for logical drives */
FRESULT res;
UINT br, bw; /* File R/W count */
BYTE buffer[4096]={0}; /* file copy buffer */
BYTE textFileBuffer[] = "Welcome to use Wildfire iso stm32 Development Board today is a good day";
short Accel[3];
short Gyro[3];
short Temp;
void delay (int x)
{ int i,j;
for (i=0;i<x;i++)
for(j=0;j<600;j++);
}
int main(void)
{
i2c_GPIO_Config();
//MPU6050初始化
MPU6050_Init();
/* USART1 config */
USART1_Config();
printf("\r\n 飞行数据采集系统 \r\n");
/* Sdio Interrupt Config */
NVIC_Configuration();
/* Register work area for each volume (Always succeeds regardless of disk status) */
f_mount(0,&fs);
/* function disk_initialize() has been called in f_open */
/* Create new file on the drive 0 */
res = f_open(&fnew, "0:飞行数据.txt", FA_CREATE_ALWAYS | FA_WRITE );
while(1)
{
delay(5000);
if(Task_Delay[1]==0)
{
MPU6050ReadAcc(Accel);
// printf("\r\n加速度: %8d%8d%8d ",Accel[0],Accel[1],Accel[2]);
MPU6050ReadGyro(Gyro);
// printf("陀螺仪: %8d%8d%8d ",Gyro[0],Gyro[1],Gyro[2]);
MPU6050_ReturnTemp(&Temp);
// printf("温度: %d",Temp);
Task_Delay[1]=100;//此值每1ms会减1,减到0才可以重新进来这里,所以执行的周期是100ms
}
if ( res == FR_OK )
{
res = f_write(&fnew, Accel, sizeof(Accel), &bw);
res = f_write(&fnew, Gyro, sizeof(Gyro), &bw);
// f_sync(&fnew);
f_lseek(&fnew, 500);//移动文件指针
// f_lseek(&fnew, f_size(&fnew));
f_close(&fnew);
}
res = f_open(&fnew, "0飞行数据.txt", FA_OPEN_EXISTING | FA_READ);
res = f_read(&fnew, buffer, sizeof(buffer), &br);
printf("\r\n %s ", buffer);
}
/* Close open files */
f_close(&fnew);
/* Unregister work area prior to discard it */
f_mount(0, NULL);
}
|
|