使用CH341的USB轉SPI來實現AVR的ISP下載。在讀AVR芯片的ID時老出錯,以下這段代碼是進入AVR下載使能狀態(tài)。即通過SPI寫入4個字節(jié)值0XAC,0X53,0X00,0X00,在第三個SPI操作時回讀一個值,這個值為0X53時,表示AVR單片機進入下載使能狀態(tài)??梢酝ㄟ^SPI總線來下載。請幫看看有什么問題沒有?我一直讀出的值為0XFF。
Status = InitialUSB(iIndex, 0x80); if(Status<0) { return -1; } memset(InBuf,0,10); for(i=0;i<20;i++) //20ms delay { Delay(0.01); } memset(InBuf,0,10); InBuf[0]=0xac; Status = CH341StreamSPI4(iIndex,0x80,1,InBuf); //寫SPI從器件地址和偏移地址 if (Status==0) { return -1; } InBuf[0]=0x53; Status = CH341StreamSPI4(iIndex,0x80,1,InBuf);//寫SPI從器件地址和偏移地址 if (Status==0) { return -1; } InBuf[0]=0x00; Status = CH341StreamSPI4(iIndex,0x80,2,InBuf); //寫SPI從器件地址和偏移地址 if (Status==0) { return -1; } temp = InBuf[1]; InBuf[0]=0x00; Status = CH341StreamSPI4(iIndex,0x80,1,InBuf); //寫SPI從器件地址和偏移地址 if (Status==0) { return -1; } Status = CloseUSB(iIndex); if(Status<0) { return -1; }