大家好,我近日在调试ch376s芯片,芯片能正常初始化,能识别并连接u盘,但是打开文件时一直返回0x42(文件不存在),已换了多个不同品牌,不同容量的u盘均不能解决。使用的是stm32 io口模拟并口通信,怀疑是32速度太快,在读写函数中又加了10ms延时也无用,所以来请教各位老师。
void CH376_PORT_INIT(void)
{
RCC->APB2ENR|=1<<3;
RCC->APB2ENR|=1<<4;
GPIOB->CRL=0X88888333;
CH376_WR = 1;
CH376_RD = 1;
CH376_A0 = 0;
CH376_DATA_DIR_IN( );
}
void xWriteCH376Cmd(u8 u8Cmd)
{
u8 i;
CH376_DATA_DIR_OUT();
CH376_A0 = 1;
CH376_WR = 0;
CH376_RD =1;
CH376_DATA_DAT_OUT(u8Cmd);
delay_ms(10);
CH376_WR = 1;
CH376_RD =0; /* ?????????, ????CH376?? */
//CH376_CS = 1;
CH376_A0 = 0;
CH376_DATA_DIR_IN(); /* ?????? */
for (i=100; i!=0; --i)
{
delay(110);
if ((xReadCH376Status() & PARA_STATE_BUSY ) == 0 )
{
break;
}
}
}
void xWriteCH376Data(u8 u8Data)
{
// CH376_DAT_PORT = (u16)u8Data;
CH376_DATA_DIR_OUT( );
/* ?CH376??????? */
/* ????????? */
CH376_A0 = 0;
//CH376_CS = 0;
CH376_WR = 0;
CH376_RD=1;
CH376_DATA_DAT_OUT( u8Data );
delay_ms(10);
//CH376_CS = 0;
CH376_WR = 1;
CH376_RD=0;
//CH376_CS = 1;
CH376_DATA_DIR_IN( );
delay(270);
}
u8xReadCH376Status() /* ?CH376???,??????? */
{
u8mData;
CH376_DATA_DIR_IN( ); /* ????????? */
CH376_A0 = 1;
//CH376_CS = 0;
CH376_RD = 0;
CH376_WR=1; /* ?????????, ?CH376??????? */
//CH376_CS = 0; /* ??????,????,CH376??????????40nS,????????????????????????????? */
mData = GPIOC->IDR; /* ?CH376??????? */
delay_ms(10);
CH376_RD = 1; /* ?????????, ????CH376?? */
CH376_WR=0;
//CH376_CS = 1;
CH376_A0 = 0;
return( mData );
}
主程序
u8Result = mInitCH376Host();
//printf("%x\n",u8Result );
if (u8Result == USB_INT_SUCCESS)
{
//printf("ok");
while (CH376DiskConnect()!= USB_INT_SUCCESS)
{
printf("wrong\n");
delay_ms(1000);
}
// printf("right\n");
u8Result = CH376DiskMount();
if (u8Result != USB_INT_SUCCESS)
{
printf("wrong_1\n");
while (1);
}
else
{
//printf("right_1\n");
u8Length = CH376ReadBlock(pu8Temp);
printf("%d\n",u8Length);
}
if (u8Length != 0)
{
CH376DiskQuery((u32*)pu8Temp);
strcpy((char*)pu8Temp,"123.txt");
printf("%s\n",pu8Temp);
u8Result = CH376FileOpen(pu8Temp);
printf("%x\n",u8Result );
if (u8Result == USB_INT_SUCCESS)
{
u32FileLen = CH376GetFileSize();
printf("%x\n",u32FileLen);
}
//CH376DiskCapacity
}
}