CH375能寫(xiě)但是不能讀,咋回事???

幫我分析一下,就是簡(jiǎn)單的以扇區(qū)為單位的讀寫(xiě)操作,調(diào)試了一天,還是只能寫(xiě)扇區(qū)(每次只讀或者寫(xiě)一個(gè)扇區(qū)),讀扇區(qū)的時(shí)間就死掉了。要么是發(fā)出讀扇區(qū)命令后反回的是1F(出錯(cuò)),要么是返回USB_INT_DISK_READ,但隨后發(fā)讀命令時(shí)就死掉了,沒(méi)有出現(xiàn)中斷,U盤(pán)的燈一直亮著,導(dǎo)致這種情況可能會(huì)是什么原因? 程序如下: /* CH375.c */

#include "CH375.h" #include "CH375INC.h" #include "c8051F320addr.h"

// Buffer for read/write transfers: unsigned char xdata gScratch[PHYSICAL_BLOCK_SIZE];

void Delay1_2uS(void);

void DelaymS(unsigned char i);

void CH375_WR_CMD_PORT(unsigned char cmd);

void CH375_WR_DAT_PORT(unsigned char dat);

unsigned char CH375_RD_DAT_PORT(void);

unsigned char WaitInterrupt(void) { while (CH375_INT); CH375_WR_CMD_PORT(CMD_GET_STATUS); return(CH375_RD_DAT_PORT()); }

unsigned char CH375Init(void) { unsigned char i; #ifdef TEST_CH375_PORT unsigned char c; CH375_WR_CMD_PORT(CMD_CHECK_EXIST); CH375_WR_DAT_PORT(0x55); c = CH375_RD_DAT_PORT(); if (c!=0xaa) { for (i=100; i!=0; i--) { CH375_WR_CMD_PORT(CMD_RESET_ALL); c = CH375_RD_DAT_PORT(); } Delay100mS(); } #endif CH375_WR_CMD_PORT(CMD_SET_USB_MODE); CH375_WR_DAT_PORT(6); for (i=0xFF; i!=0; i--) { if (CH375_RD_DAT_PORT()==CMD_RET_SUCCESS) break; } if (i!=0) return(0); //OK else return(0xFF); //False }

unsigned char DiskInit(void) { unsigned char IntStatus; CH375_WR_CMD_PORT(CMD_GET_STATUS); IntStatus = CH375_RD_DAT_PORT(); if (IntStatus==USB_INT_DISCONNECT) return (IntStatus); CH375_WR_CMD_PORT(CMD_DISK_INIT); IntStatus = WaitInterrupt(); if (IntStatus!=USB_INT_SUCCESS) return (IntStatus);

CH375_WR_CMD_PORT(CMD_DISK_SIZE); IntStatus = WaitInterrupt(); if (IntStatus!=USB_INT_SUCCESS) { Delay100mS(); CH375_WR_CMD_PORT(CMD_DISK_SIZE); IntStatus = WaitInterrupt(); }

if (IntStatus!=USB_INT_SUCCESS) { return (IntStatus); }

return (0); }

unsigned char SectRead(unsigned long sector_LBA) { unsigned char IntStatus; unsigned char *BufferPoint; unsigned int BlockCount; unsigned char Length; CH375_WR_CMD_PORT(CMD_DISK_READ); CH375_WR_DAT_PORT((unsigned char)sector_LBA); CH375_WR_DAT_PORT((unsigned char)(sector_LBA>>8)); CH375_WR_DAT_PORT((unsigned char)(sector_LBA>>16)); CH375_WR_DAT_PORT((unsigned char)(sector_LBA>>24)); CH375_WR_DAT_PORT(1); BufferPoint = gScratch; for (BlockCount=1*CH375_BLK_PER_SEC; BlockCount!=0; BlockCount--) { IntStatus = WaitInterrupt(); if (IntStatus==USB_INT_DISK_READ) { CH375_WR_CMD_PORT(CMD_RD_USB_DATA); Length = CH375_RD_DAT_PORT(); while (Length) { *BufferPoint = CH375_RD_DAT_PORT(); BufferPoint++; Length--; } CH375_WR_CMD_PORT(CMD_DISK_RD_GO); } else break; }

if (BlockCount==0) { IntStatus = WaitInterrupt(); if (IntStatus==USB_INT_SUCCESS) return (0); }

return (IntStatus); }

unsigned char SectWrite(unsigned long sector_LBA) { unsigned char IntStatus; unsigned char *BufferPoint; unsigned int BlockCount; unsigned char Length;

CH375_WR_CMD_PORT(CMD_DISK_WRITE); CH375_WR_DAT_PORT((unsigned char)sector_LBA); CH375_WR_DAT_PORT((unsigned char)(sector_LBA>>8)); CH375_WR_DAT_PORT((unsigned char)(sector_LBA>>16)); CH375_WR_DAT_PORT((unsigned char)(sector_LBA>>24)); CH375_WR_DAT_PORT(1); BufferPoint = gScratch;

for (BlockCount=1*CH375_BLK_PER_SEC; BlockCount!=0; BlockCount--) { IntStatus = WaitInterrupt(); if (IntStatus==USB_INT_DISK_WRITE) { CH375_WR_CMD_PORT(CMD_WR_USB_DATA7); Length = CH375_BLOCK_SIZE; CH375_WR_DAT_PORT(Length); while (Length) { CH375_WR_DAT_PORT(*BufferPoint); BufferPoint++; Length--; }

CH375_WR_CMD_PORT(CMD_DISK_WR_GO); } else break; }

if (BlockCount==0) { IntStatus = WaitInterrupt(); if (IntStatus==USB_INT_SUCCESS) return (0); }

return (IntStatus); }

你的c8051單片機(jī)采用的是多大的晶振?c8051單片機(jī)比51的速度要快的多,會(huì)不會(huì)是你三個(gè)讀寫(xiě)子函數(shù)的延時(shí)問(wèn)題。能不能把你的三個(gè)讀寫(xiě)子函數(shù)帖出來(lái)看一下。


void Delay1uS(void) { unsigned char i; for (i=2; i!=0; i--); }

void DelaymS(unsigned int ms) { unsigned int i; unsigned char j; for(j=ms; j>0; j--) for(i=1200; i>0; i--); }

void CH375_WR_CMD_PORT(unsigned char cmd) { Delay1uS(); Delay1uS();

P2 = cmd; CH375_A0 = 1; CH375_CS = 0; CH375_WR = 0; CH375_CS = 0; //Delay 167nS, at least 90nS CH375_WR = 1; CH375_CS = 1; CH375_A0 = 0; P2 = 0xFF; Delay1uS(); Delay1uS(); }

void CH375_WR_DAT_PORT(unsigned char dat) { P2 = dat; CH375_A0 = 0; CH375_CS = 0; CH375_WR = 0; CH375_CS = 0; //Delay 167nS, at least 90nS CH375_WR = 1; CH375_CS = 1; P2 = 0xFF; Delay1uS(); }

unsigned char CH375_RD_DAT_PORT(void) { unsigned char Data; Delay1uS(); P2 = 0xFF; CH375_A0 = 0; CH375_CS = 0; CH375_RD = 0; CH375_CS = 0; //Delay 167nS, at least 90nS Data = P2; CH375_RD = 1; CH375_CS = 1; return(Data); }

CH375用的是單片機(jī)輸出的12MHz晶振,我計(jì)算過(guò)了,延時(shí)沒(méi)有問(wèn)題,Delay1uS()函數(shù)調(diào)用一次到反回總共的機(jī)器指令周期為4(LCALL)+2(MOV ri,#data)+(3/4)*2(DJNZ)+5(RET)=12.5個(gè)時(shí)鐘周期,單片機(jī)時(shí)鐘頻率為12MHz,這樣就有12.5/12>1uS了。還有,我寫(xiě)U盤(pán)和讀取U盤(pán)容量都是正確的,這說(shuō)明對(duì)命令和數(shù)據(jù)的操作應(yīng)該沒(méi)有問(wèn)題啊,就是讀U盤(pán)扇區(qū)時(shí)就死掉了,一直在那里等待中斷(for循環(huán)里的第一個(gè)等待中斷)。U盤(pán)的燈一直亮著。。。


在你產(chǎn)生USB_INT_DISK_READ中斷之后,能讀取到數(shù)據(jù)嗎???


產(chǎn)生不了這個(gè)中斷,一直在等那個(gè)中斷,U盤(pán)燈一直亮著。寫(xiě)U盤(pán)扇區(qū)倒是沒(méi)有問(wèn)題,不同的扇區(qū)我都試過(guò)了,能寫(xiě)進(jìn)去,但讀不出來(lái),一直在那里等中斷


我換了一個(gè)U盤(pán)試了一下,這回產(chǎn)生USB_INT_DISK_READ中斷了,但隨后CH375_WR_CMD_PORT(CMD_RD_USB_DATA0)之后讀出的Length = CH375_RD_DAT_PORT();為零。。。。。。。。郁悶中。。。。。。。。。


應(yīng)該不會(huì)啊,你在你的三個(gè)讀寫(xiě)子程序里面延時(shí)加大點(diǎn),要是還不可以的話(huà),話(huà)一個(gè)375試下看


有的u盤(pán)會(huì)這樣 舊的就不會(huì)了


換了個(gè)CH375,現(xiàn)在OK了,原來(lái)是芯片的問(wèn)題


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频