如题,我采用硬件SPI的方式控制CH376,通过IO获取376的中断。每次在调用CH376ByteWrite函数时,写入的字节超过30个就返回0XFA。少于30个就正常。 文件打开后,写入: s = CH376ByteWrite(CH376Buf,40, NULL ); 这里出错。 CH376ByteWrite函数为官方提供的,没有修改过。 UINT8 CH376ByteWrite( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ) /* 以字节为单位向当前位置写入数据块 */ { UINT8 s; xWriteCH376Cmd( CMD2H_BYTE_WRITE ); xWriteCH376Data( (UINT8)ReqCount ); xWriteCH376Data( (UINT8)(ReqCount>>8) ); xEndCH376Cmd( ); if ( RealCount ) *RealCount = 0; while ( 1 ) { s = Wait376Interrupt( ); if ( s == USB_INT_DISK_WRITE ) { s = CH376WriteReqBlock( buf ); xWriteCH376Cmd( CMD0H_BYTE_WR_GO ); xEndCH376Cmd( ); buf += s; if ( RealCount ) *RealCount += s; } else if ( s == USB_INT_SUCCESS ) return( s ); /* 结束 */ else return( s ); /* 错误 */ } } Wait376Interrupt()函数如下: for ( i = 0; i < 100; i ++ ) { if ( Query376Interrupt( ) ) { return( CH376GetIntStatus( ) ); } Delayms(100); Delayms(200);
Query376Interrupt函数如下: /* 查询CH376中断(INT#低电平) */ UINT8 Query376Interrupt( void ) { UINT8 flag,s; flag=CH376_Get_INT(); return !flag; }