在spi通信中加入延遲mBuffer[ k++ ] = mCH341A_CMD_UIO_STM_DLY | delay;,加入后一個字節(jié)需要5*8=40字節(jié), 因?yàn)橐粋€包長度32字節(jié),于是將j=8的循環(huán)分為2個循環(huán),構(gòu)造2個包,即2個包才完成一個字節(jié)有效數(shù)據(jù)的發(fā)送和接收。但是結(jié)果不正確。是不是CH341WriteRead( index, k, mBuffer, 8, OutLen, &j, mBuffer );的參數(shù)也要修改???
沒有加入延遲的代碼如下: for( i = 0; i != OutLen; i++ ) { tem = *p; mBuffer[ k++ ] = mCH341A_CMD_UIO_STREAM; // 命令碼 for( j = 0; j != 8; j++ ) { c = tem & 0x80 ? 0x20 : 0; // D5 數(shù)據(jù)輸出 mBuffer[ k++ ] = mCH341A_CMD_UIO_STM_OUT | c; // D3=0, I/O_CLOCK=LOW mBuffer[ k++ ] = mCH341A_CMD_UIO_STM_OUT | c | 0x08; // D3=1, I/O_CLOCK=HIGH mBuffer[ k++ ] = mCH341A_CMD_UIO_STM_IN; // input from D7 tem <<= 1; } mBuffer[ k++ ] = mCH341A_CMD_UIO_STM_OUT | c | 0x00; // D3=0, I/O_CLOCK=LOW mBuffer[ k++ ] = mCH341A_CMD_UIO_STM_END; // 當(dāng)前命令包提前結(jié)束 k += mCH341_PACKET_LENGTH - 1; k &= ~ ( mCH341_PACKET_LENGTH - 1 ); p++; } i = CH341WriteRead( index, k, mBuffer, 8, OutLen, &j, mBuffer );