環(huán)境:STM32F103 + CH376S開發(fā)板 + USB掃碼槍

問題: USB設(shè)備初始化過程失敗,獲取設(shè)備描述符返回0x15(USB_INT_CONNECT), 期望的是0x14(USB_INT_SUCCESS)


相關(guān)代碼:

/* 等待INT中斷*/

u8 waitUSBDeviceInterrupt(void) {

unsigned short i;

for ( i = 0; CH375_INT_WIRE != 0; i ++ ) {? // 如果CH375的中斷引腳輸出高電平則等待,通過計(jì)數(shù)防止超時(shí)

delay_us(1);

if ( i == 0xF000 )

{

xWriteCH376Cmd( CMD_ABORT_NAK );?

printf("Wait device timeout, send cmd abort!\n");

}

}

xWriteCH376Cmd( CMD_GET_STATUS );? /* 產(chǎn)生操作完成中斷, 獲取中斷狀態(tài) */

return( xReadCH376Data() );

}


/* 從設(shè)備端獲取描述符 */

unsigned char get_descr( unsigned char type ) {??

xWriteCH376Cmd( CMD_GET_DESCR );

xWriteCH376Data( type );? /* 描述符類型, 只支持1(設(shè)備)或者2(配置) */

printf("write -->cmd=%x, type=%x\n",CMD_GET_DESCR, type);

return( waitUSBDeviceInterrupt() );

}

unsigned char init_scanner() {

#definep_dev_descr((PUSB_DEV_DESCR)buffer)

#definep_cfg_descr((PUSB_CFG_DESCR_LONG)buffer)

unsigned char status, len, c;

printf("init_scanner enter...\n");


status=get_descr(1);? /* 獲取設(shè)備描述符 *///<<<<<<<<<<<<問題點(diǎn)<<<<<<<<<<<<<<<<<<<<

if ( status==USB_INT_SUCCESS ) {

? ? ? ? ? ?/*無法進(jìn)入,因?yàn)間et_descr(1)返回的是0x15*///<<<<<<<<<問題點(diǎn)<<<<<<<<<<<<<<<<<<<<

? ? ? ? ? ?......

}

printf("get descr out, status=%#x\n",status);

return(status);

}


?/* 初始化CH376 */

u8mInitCH376Host( void )?

{

u8res;

//IO init

CH375_Init();

//Check if CH376 coud work

xWriteCH376Cmd( CMD_CHECK_EXIST );

printf("xWriteCH376Cmd= %#x\n", CMD_CHECK_EXIST);

xWriteCH376Data( 0x55 );

res = xReadCH376Data( );

printf("xReadCH376Data= %#x\n", res);

if ( res != 0xAA ) return( CH376_ERR );


printf("set usb mode ---> 6\n");

set_usb_mode( 6 );

printf("wait usb device online...\n");

while ( waitUSBDeviceInterrupt()!=USB_INT_CONNECT );?


#define USB_RESET_FIRST 0

#if USB_RESET_FIRST

printf("reset usb device...\n");

set_usb_mode( 7 );

delay_ms(10);

set_usb_mode( 6 );

delay_ms(100);

printf("wait usb device online again...\n");

while ( waitUSBDeviceInterrupt()!=USB_INT_CONNECT );

#endif


? ? ? ? delay_ms(200);

if ( init_scanner()!=USB_INT_SUCCESS ) while(1);


? return 0;

}


調(diào)試日志:

start

xWriteCH376Cmd= 0x6

xReadCH376Data= 0xaa

set usb mode ---> 6

wait usb device online...

init_scanner enter...

write -->cmd=46, type=1

get descr out, status=0x15 //<<<<<<<<<初始化過程終止<<<<<<<<<<<<<<<<<<<<