共2条
1/1 1 跳转至页
philips51 求助:philips51的单片机读写U盘的问题 附源码
问
这是读写U盘部分的源码
我们的单片机在读写U盘的时候遇到了问题,主要是,U盘里的数据单片机可以读,在写U盘的时候能够成功的写入文件名
用计算机打开文件以后,里面却时空的,没有数据,有能帮忙解决的朋友我请吃饭呀
附程序源码如下:
printf( "Wait Udisk\n" );
while ( CH375DiskStatus != DISK_CONNECT ) xQueryInterrupt( );
mDelay100mS( );
mDelay100mS( );
for ( i = 0; i < 10; i ++ ) {
mDelay100mS( );
printf( "Ready ?\n" );
if ( CH375DiskReady( ) == ERR_SUCCESS ) break;
}
printf( "Open\n" );
mCopyCodeStringToIRAM( mCmdParam.Open.mPathName, "/MY_ADC.TXT" );
i = CH375FileOpen( );
if ( i == ERR_SUCCESS ) {
printf( "File size = %ld\n", CH375vFileSize );
printf( "Locate tail\n" );
mCmdParam.ByteLocate.mByteOffset = 0xffffffff;
i = CH375ByteLocate( );
mStopIfError( i );
}
else if ( i == ERR_MISS_FILE ) {
printf( "Create\n" );
i = CH375FileCreate( );
mStopIfError( i );
}
else mStopIfError( i ); /* 打开文件时出错 */
printf( "Write begin\n" );
i = sprintf( mCmdParam.ByteWrite.mByteBuffer, "此前文件长度= %ld 字节\xd\xa", CH375vFileSize );
mCmdParam.ByteWrite.mByteCount = i;
i = CH375ByteWrite( );
mStopIfError( i );
printf( "Write ADC data\n" );
TR0=1;
for ( hour = 8; hour != 20; hour ++ ) {
month = 5;
date = TL1 & 0x1F;
adc = get_adc_data( );
adc = ( (UINT16)TH0 << 8 ) | TL0;
len = sprintf( mCmdParam.ByteWrite.mByteBuffer, "%02d.%02d.%02d ADC=%u\xd\xa", (UINT16)month, date, (UINT16)hour, adc );
mCmdParam.ByteWrite.mByteCount = (unsigned char)len;
i = CH375ByteWrite( );
mStopIfError( i );
printf( "Current offset ( file point ) is %ld\n", CH375vCurrentOffset );
}
mCmdParam.ByteWrite.mByteCount = 0;
printf( "Write end\n" );
i = mCopyCodeStringToIRAM( mCmdParam.ByteWrite.mByteBuffer, "数据到此结束\xd\xa" );
mCmdParam.ByteWrite.mByteCount = i;
i = CH375ByteWrite( );
printf( "Close\n" );
mCmdParam.Close.mUpdateLen = 1;
i = CH375FileClose( );
mStopIfError( i );
printf( "Take out\n" );
while ( CH375DiskStatus != DISK_DISCONNECT ) xQueryInterrupt( );
mDelay100mS( );
mDelay100mS( );
}
} 答 1: 搞错了吧! 沁恒的片子拿到ARM版来请教。
我们的单片机在读写U盘的时候遇到了问题,主要是,U盘里的数据单片机可以读,在写U盘的时候能够成功的写入文件名
用计算机打开文件以后,里面却时空的,没有数据,有能帮忙解决的朋友我请吃饭呀
附程序源码如下:
printf( "Wait Udisk\n" );
while ( CH375DiskStatus != DISK_CONNECT ) xQueryInterrupt( );
mDelay100mS( );
mDelay100mS( );
for ( i = 0; i < 10; i ++ ) {
mDelay100mS( );
printf( "Ready ?\n" );
if ( CH375DiskReady( ) == ERR_SUCCESS ) break;
}
printf( "Open\n" );
mCopyCodeStringToIRAM( mCmdParam.Open.mPathName, "/MY_ADC.TXT" );
i = CH375FileOpen( );
if ( i == ERR_SUCCESS ) {
printf( "File size = %ld\n", CH375vFileSize );
printf( "Locate tail\n" );
mCmdParam.ByteLocate.mByteOffset = 0xffffffff;
i = CH375ByteLocate( );
mStopIfError( i );
}
else if ( i == ERR_MISS_FILE ) {
printf( "Create\n" );
i = CH375FileCreate( );
mStopIfError( i );
}
else mStopIfError( i ); /* 打开文件时出错 */
printf( "Write begin\n" );
i = sprintf( mCmdParam.ByteWrite.mByteBuffer, "此前文件长度= %ld 字节\xd\xa", CH375vFileSize );
mCmdParam.ByteWrite.mByteCount = i;
i = CH375ByteWrite( );
mStopIfError( i );
printf( "Write ADC data\n" );
TR0=1;
for ( hour = 8; hour != 20; hour ++ ) {
month = 5;
date = TL1 & 0x1F;
adc = get_adc_data( );
adc = ( (UINT16)TH0 << 8 ) | TL0;
len = sprintf( mCmdParam.ByteWrite.mByteBuffer, "%02d.%02d.%02d ADC=%u\xd\xa", (UINT16)month, date, (UINT16)hour, adc );
mCmdParam.ByteWrite.mByteCount = (unsigned char)len;
i = CH375ByteWrite( );
mStopIfError( i );
printf( "Current offset ( file point ) is %ld\n", CH375vCurrentOffset );
}
mCmdParam.ByteWrite.mByteCount = 0;
printf( "Write end\n" );
i = mCopyCodeStringToIRAM( mCmdParam.ByteWrite.mByteBuffer, "数据到此结束\xd\xa" );
mCmdParam.ByteWrite.mByteCount = i;
i = CH375ByteWrite( );
printf( "Close\n" );
mCmdParam.Close.mUpdateLen = 1;
i = CH375FileClose( );
mStopIfError( i );
printf( "Take out\n" );
while ( CH375DiskStatus != DISK_DISCONNECT ) xQueryInterrupt( );
mDelay100mS( );
mDelay100mS( );
}
} 答 1: 搞错了吧! 沁恒的片子拿到ARM版来请教。
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【笔记】生成报错synthdesignERROR被打赏50分 | |
【STM32H7S78-DK评测】LTDC+DMA2D驱动RGBLCD屏幕被打赏50分 | |
【STM32H7S78-DK评测】Coremark基准测试被打赏50分 | |
【STM32H7S78-DK评测】浮点数计算性能测试被打赏50分 | |
【STM32H7S78-DK评测】Execute in place(XIP)模式学习笔记被打赏50分 | |
每周了解几个硬件知识+buckboost电路(五)被打赏10分 | |
【换取逻辑分析仪】RA8 PMU 模块功能寄存器功能说明被打赏20分 | |
野火启明6M5适配SPI被打赏20分 | |
NUCLEO-U083RC学习历程2-串口输出测试被打赏20分 | |
【笔记】STM32CUBEIDE的Noruletomaketarget编译问题被打赏50分 |