大家好,我近日在調(diào)試ch376s芯片,芯片能正常初始化,能識別并連接u盤,但是打開文件時一直返回0x42(文件不存在),已換了多個不同品牌,不同容量的u盤均不能解決。使用的是stm32 io口模擬并口通信,懷疑是32速度太快,在讀寫函數(shù)中又加了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
? }
?}