版主,请问u8CH376ByteRead( u8* buf, u16 ReqCount, u16* RealCount ) 函数中ReqCount最大值可取多少,我现在想将SD卡中的数据转存到U盘中,发现数据个数为45个就不行了,怎么处理,谢谢
ReqCount最大值是65535,ReqCount=45肯定是可以读取的,你监控一下有无错误返回值?读出的buf缓冲区定义有无问题?
我定义的是这样一组数据u8 RSM1[90]={0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};就是数字123456789,当我设置ReqCount为48时,读到的值是48个3,这是怎么回事啊
当我设置ReqCount为49时,读到的值是49个4, 设置90,读到90个9,我用的是FSMC总线方式,这是怎么回事啊
很明显你的错误是有规律的,估计软件编程哪边有问题?首先你得确认你想读出来的数据是什么? 可以把程序贴出来看一下。
#define CH376_DAT_PORT (*( volatile u8 *)0x6C000000) // A0 = 0, CS = 0 #define CH376_CMD_PORT (*( volatile u8 *)0x6C000001) // A0 = 1, CS = 0
u8 RSM1[45]={0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39}; u8 RSM[45]={0}; u8 WCHH[45]; u8 u8Result; u8 u8Length; u8 *pu8Temp = RSM1; u8 *pu8Temp1 = WCHH;
u32 u32FileLen = 0; u32 RealFileLen = 0; u32 u32DataCnt = 0; //描述: 延时函数 //名称: delay //输入参数: 无 //输出参数: 无 //返回值: 无 //说明: 无
#define HRES GPIO_SetBits(GPIOB, GPIO_Pin_12); //CH376复位信号高电平有效 #define LRES GPIO_ResetBits(GPIOB, GPIO_Pin_12); #define CH375_INT_WIRE GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13)
void delay(u32 i) { while (i > 0) { i--; } }
//描述: 查询INT引脚电平 //名称: Query376Interrupt //输入参数: 无 //输出参数: 无 //返回值: u8 -- FALSE 没有中断 // TRUE 有中断 //说明: 无 u8 Query376Interrupt(void) { //u8 temp=0; //temp=GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_15); //delay_ms(10); //return TRUE; return (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13) ? FALSE : TRUE); //0表示没有中断 非0表示有中断 }
//描述: 初始化Ch376芯片 //名称: mInitCH376Host //输入参数: 无 //输出参数: 无 //返回值: u8 -- 初始化结果 // USB_INT_SUCCESS(0x14) 初始化成功 // ERR_USB_UNKNOWN(0xFA) 初始化失败 //说明: 无 u8 mInitCH376Host(void) //数据写完需要关闭文件,否则文本中数据无法更新 { u8 u8Result; FSMC_SRAM_Init(); /* 接口硬件初始化 */ GPIO_SetBits(GPIOE, GPIO_Pin_3); delay_ms(500); HRES; delay_ms(500); LRES; delay_ms(200); xWriteCH376Cmd(CMD11_CHECK_EXIST); /* 06 测试单片机与CH376之间的通讯接口 */ Write376Data(0x55); //手册上为发送55,返回0AA为正确 delay_ms(2); u8Result = Read376Data(); if (u8Result != 0xAA ) //AA { return ERR_USB_UNKNOWN; /* 通讯接口不正常,可能原因有:接口连接异常,其它设备影响(片选不唯一),串口波特率,一直在复位,晶振不工作 */ } //xWriteCH376Cmd(CMD11_SET_USB_MODE); /* 15 设备USB工作模式 */ //Write376Data(0x06); //切换到USB主机模式 xWriteCH376Cmd(CMD11_SET_USB_MODE); /* 15 SD工作模式 */ Write376Data(0x03); //S //CH376_WRITE_REGISTER(CMD11_SET_USB_MODE,0x06); delay_ms(2); u8Result = Read376Data();
if (u8Result == CMD_RET_SUCCESS) { return USB_INT_SUCCESS; } else { return(ERR_USB_UNKNOWN); /* 设置模式错误 */ }
}
void SD_CH376_USB_Function(void) { u8Result = mInitCH376Host();
if (u8Result == USB_INT_SUCCESS) { /*while (CH376DiskConnect() != USB_INT_SUCCESS) //检查设备是否连接 { delay_ms(500); }*/
u8Result = CH376DiskMount(); // 初始化磁盘并测试磁盘是否就绪 if (u8Result != USB_INT_SUCCESS) { while (1); }
else { u8Result=CH376FileCreate("/WCHH.TXT"); // u8Result = CH376FileOpenPath("\\WCH.TXT"); u8Result=CH376FileOpen("/WCHH.TXT"); u8Length = CH376ReadBlock(pu8Temp); }
//if (u8Length != 0) if (u8Result == 0x14) { CH376DiskQuery((u32 *)pu8Temp1); // u8Result=CH376FileCreate("/WCHH.TXT"); u8Result=CH376FileOpen("/WCHH.TXT");
if (u8Result == USB_INT_SUCCESS) { // 获取文件大小 u32FileLen = CH376GetFileSize();
while (u32DataCnt < u32FileLen) { CH376ByteWrite(RSM1, 45, 0); // // pu8Temp++; //CH376ByteRead(pu8Temp1, 2, 0); u32DataCnt += 1; } CH376FileClose(1); u8Result=CH376FileOpen("/WCHH.TXT"); if (u8Result == USB_INT_SUCCESS) { u32DataCnt=0; RealFileLen = CH376GetFileSize(); if (u32DataCnt < RealFileLen) { CH376ByteRead(pu8Temp1, RealFileLen, 0); // CH376ByteWrite((uint8_t *)buf, strlen(buf), NULL ); //CH376ByteRead(pu8Temp1, RealFileLen, 0); //CH376ByteRead(pu8Temp1, RealFileLen, 0); //u32DataCnt++; strcpy(RSM, WCHH ); /* 目标文件名 strcpy( (char *)buf,(const char *)"\\YY.TXT" );*/ } } CH376FileClose(1); } } xWriteCH376Cmd(CMD11_SET_USB_MODE); /* 15 SD工作模式 */ Write376Data(0x06); //S delay_ms(2); u8Result = Read376Data(); if (u8Result == CMD_RET_SUCCESS) { while (CH376DiskConnect() != USB_INT_SUCCESS) //检查设备是否连接 { delay_ms(500); }
u8Result = CH376DiskMount(); // 初始化磁盘并测试磁盘是否就绪 if (u8Result == USB_INT_SUCCESS) { CH376DiskQuery((u32 *)pu8Temp1); u8Result=CH376FileCreate("/HUA.TXT"); u8Result=CH376FileOpen("/HUA.TXT"); if (u8Result == USB_INT_SUCCESS) { // 获取文件大小 u32DataCnt=0; u32FileLen = CH376GetFileSize(); //u32FileLen作为实际长度 while (u32DataCnt < u32FileLen) { CH376ByteWrite(RSM, RealFileLen, 0); // u32DataCnt += 1; } CH376FileClose(1); } } } }
else { while (1); } }
/* 向索引端口写入索引地址 */ //#define Write374Index( a ) { CH374_IDX_PORT = a; } void Write376Index(u8 mIndex ) /* 向CH374写索引地址 */ { //CH376->CH376_REG = mIndex ; CH376_CMD_PORT= mIndex ; delay_ms(2); }
/* 向数据端口写入数据,索引地址自动加1 */ //#define Write374Data( d ) { CH374_DAT_PORT = d & 0xFF; } void Write376Data( u8 mData ) { //CH376->CH376_RAM = mData ; CH376_DAT_PORT = mData ; delay_ms(2); }
/* 从数据端口读出数据,索引地址自动加1 */ //#define Read374Data( ) ( (UINT8)CH374_DAT_PORT ) u8 Read376Data( void ) { //return (CH376->CH376_RAM); delay_ms(2); return (CH376_DAT_PORT); }
/* 从索引端口读出数据,索引地址不变,适用于[读出->修改->写回]操作 */ //#define Read374Data0( ) ( (UINT8)CH374_IDX_PORT ) u8 Read376Data0( void ) { //return( CH376->CH376_RAM ); return (CH376_DAT_PORT); }
/* 从指定寄存器读取数据 */ u8 CH376_READ_REGISTER(u8 mAddr) { //CH376->CH376_REG = mAddr; CH376_CMD_PORT= mAddr ; delay_ms(2); return Read376Data(); }
/* 向指定寄存器写入数据 */ void CH376_WRITE_REGISTER(u8 mAddr, u8 mData) { CH376_CMD_PORT= mAddr ; delay_ms(2); CH376_DAT_PORT=mData; delay_ms(2);
}
void xWriteCH376Cmd(u8 u8Cmd) { u8 i; CH376_CMD_PORT= u8Cmd ; delay_ms(2); for (i=100; i!=0; --i) { delay_ms(1); if ((xReadCH376Status() & PARA_STATE_BUSY ) == 0 ) //CH376_CMD_PORT & PARA_STATE_BUSY(10) { break; } } }
//描述: 向CH376写数据 //名称: xWriteCH376Data //输入参数: u8Data -- 数据 //输出参数: 无 //返回值: 无 //说明: 无 void xWriteCH376Data(u8 u8Data) { //CH376->CH376_RAM =u8Data; CH376_DAT_PORT=u8Data; //DelayMs(2); delay_ms(2); }
//描述: 从CH376读数据 //名称: xReadCH376Data //输入参数: 无 //输出参数: 无 //返回值: u8 -- 总线数据 //说明: 无 u8 xReadCH376Data(void) { u8 u16Temp =CH376_DAT_PORT; delay_ms(2); return u16Temp; },我用的是STM32FSMC总线方式操作的(8位并口),每次写SD卡没有问题,但读出来就不正确,容易掉数据,现在设置的是45个数据,读出来就只要39个,我是想把SD卡中的数据转存到U盘中
不好意思,这个数组里只要36个,但昨天测试的时候读数据经常会出现我昨天描述的问题,90个就是读出90个9,48个数据就是读出48个3
按照你的流程把数据改成写45个数据,读45数据可以正常操作,首先你确保你写正确,或者直接在电脑上创建文件,然后调用读函数。 出现读出90个9还是跟软件编程有关系,有出错的程序才能分析问题。
哦,我在分析下,还有就是比如我采集的电压数据0xfff,也就是满偏电压3.3V,这样写到SD卡中的数据该怎么处理一下,直接写入就是查看就是ASC码
内部读写函数每次写入1字节数据,TXT文档是以ASCII码来查看的。所以你采集到的电压数据得做处理,如分成两个字节。
版主,我直接在电脑上创建文件再读结果是一样的,比如120个,0-17位读出来是好的,后面全是9,你觉得是总线速度的问题吗,写没有任何问题的,下面是设置90时调试的结果
读跟写的操作是类似的,你最好进入CH376ByteRead监控一下,是不是读出buf有问题?