CH376ByteWrite字节写数据有问题

通过例程里面的CH376ByteWrite函数发送数据,发现死在if ( s == USB_INT_DISK_WRITE )这步,返回的都是14,写不进去数据,自己修改后不加这步直接写入可以,但是后续发现只能写255byte,超过一个字节就写不进去,求解

UINT8CH376ByteWrite( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ) 

{

UINT8s;

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 );  /* ?í?ó */

//    return( s );  /* ?í?ó */

////}

    

    s = Wait376Interrupt();

    xWriteCH376Cmd(CMD_WR_REQ_DATA); 

    if(ReqCount)

    {

        do

        {

            xWriteCH376Data(*buf);

            buf++;

        }while(--ReqCount);

    } 


    xWriteCH376Cmd(CMD_BYTE_WR_GO); 

    s = Wait376Interrupt();        

    

    return s;

}


您好字节写可以写入多字节。UINT8CH376ByteWrite( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount ) ,长度为uint16。您如果写入超过255就无法写入的话,看一下存放数据的缓冲区大小是否大于255,其次调用字节写函数的实参长度是否正确。最后您可以确认一下字节写函数的参数定义是否为uint16类型。这边贴出部分代码提供参考。

//此处为while(1)里面的部分代码。

s = CreateFileAndTime( "/123.TXT", 1, MAKE_FILE_DATE( 2020, 6, 8 ), MAKE_FILE_TIME( 15, 39, 20 ), MAKE_FILE_DATE( 2020, 6, 8 ), MAKE_FILE_TIME( 15, 39, 20 ) );

printf("1\r\n");

mStopIfError( s );

printf("1\r\n");

s=CH376FileOpen("/123.TXT");

mStopIfError( s );

//s=DataToChar( 45678,  buf1 );

//

//s=sizeof(buf_long1);

s = CH376ByteWrite( buf_long1, 512, p );

s = CH376FileClose( TRUE );

Delay_Ms( 20 );


以下为驱动代码。

UINT8CH376ByteWrite( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount )  /* ??×??????????ò?±?°?????????????é */

{

UINT8s;

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 );  /* ?í?ó */

}

}

if ( s == USB_INT_DISK_WRITE )卡在这个判断条件,说明还在做请求写入的操作。您最好看一下长度是否给对。



只有登录才能回复,可以选择微信账号登录