CH376初始化失敗返回0xff,跟例程一樣的,快奔潰了?。。?

用LPC1768的IO口模擬SPI時序,將程序貼上,

#define CH376_SPI_SCK_init() ? gpio_init(LPC_GPIO0,15,1,1)

#define CH376_SPI_SCK_high() ? gpio_output_value(LPC_GPIO0,15,1)

#define CH376_SPI_SCK_low() ? ?gpio_output_value(LPC_GPIO0,15,0)


#define CH376_SPI_SCS_init() ? gpio_init(LPC_GPIO0,16,1,1)

#define CH376_SPI_SCS_high() ? gpio_output_value(LPC_GPIO0,16,1)

#define CH376_SPI_SCS_low() ? ?gpio_output_value(LPC_GPIO0,16,0)


#define CH376_SPI_MISO_init() ?gpio_init(LPC_GPIO0,17,0,1)

#define CH376_SPI_MISO() ? ? ? gpio_read_value(LPC_GPIO0,17)


#define CH376_SPI_MOSI_init() ?gpio_init(LPC_GPIO0,18,1,1)

#define CH376_SPI_MOSI_high() ?gpio_output_value(LPC_GPIO0,18,1)

#define CH376_SPI_MOSI_low() ? gpio_output_value(LPC_GPIO0,18,0)


#define CH376_SPI_RST_init() ? gpio_init(LPC_GPIO0,19,1,1)

#define CH376_SPI_RST_high() ? gpio_output_value(LPC_GPIO0,19,1)

#define CH376_SPI_RST_low() ? ?gpio_output_value(LPC_GPIO0,19,0)


#define CH376_SPI_INT_init() ? gpio_init(LPC_GPIO0,20,0,1)

#define CH376_SPI_INT_state() ?gpio_read_value(LPC_GPIO0,20)

void mDelaymS(uint16_t cnt)

{

? ? uint16_t i,j;

? ? for(i=0;i

? ? {

? ? ? ? ?for(j=0;j<5000;j++); ? ? ??

? ? }

}


void delay_us(uint16_t cnt)

{

uint16_t i,j;

? ? for(i=0;i

? ? { ? ? ? ? ? ? ? ? ? ? ? ? ??

? ? ? ? ?for(j=0;j<10;j++); ? ? ??

? ? }

}

voidCH376_PORT_INIT( void )

{

? ?CH376_SPI_SCS_high();

? CH376_SPI_SCK_high();

}

voidxEndCH376Cmd( void )

{?

CH376_SPI_SCS_high();?

}

voidSpi376OutByte(uint8_t d )

{ ?

?//ssp_write_read_byte(LPC_SSP0,d);?

? uint8_t i;

for(i=0;i<8;i++)

{

CH376_SPI_SCK_low();

if(d&0x80)

{

CH376_SPI_MOSI_high();

}

else

{

? ? CH376_SPI_MOSI_low();

}

d<<=1;

CH376_SPI_SCK_high();

}


}

uint8_t Spi376InByte(void)

{

uint8_t i,d=0;

for(i=0;i<8;i++)

{

CH376_SPI_SCK_low();

d<<=1;

if(CH376_SPI_MISO())

{

?d++;

}

CH376_SPI_SCK_high();

}

return d;

}


/*******************************************************************************

向CH376寫命令

*******************************************************************************/

voidxWriteCH376Cmd( uint8_t mCmd )

{

CH376_SPI_SCS_high(); ??

delay_us(3);

CH376_SPI_SCS_low();

mDelaymS( 10 );

Spi376OutByte( mCmd ); ?

delay_us(2);

}


/*******************************************************************************

向CH376寫數(shù)據(jù)

*******************************************************************************/

voidxWriteCH376Data( uint8_t mData )

{

Spi376OutByte( mData );

delay_us(10); ?

}

/*******************************************************************************

CH376讀數(shù)據(jù)

*******************************************************************************/

uint8_txReadCH376Data( void )

{

uint8_t ?i=0;

delay_us( 10 );

i=Spi376InByte();

? return (i);

}


/*******************************************************************************

查詢INT中斷

*******************************************************************************/

uint8_tQuery376Interrupt( void )

{

uint8_t i;

i = (CH376_SPI_INT_state() ? 0 : 1 );

return( i );?

}


/*******************************************************************************

初始化CH376

*******************************************************************************/

uint8_tmInitCH376Host( void )

{

uint8_tres;

mDelaymS(100);

/*CH376_SPI_RST_high();

mDelaymS(100);

CH376_SPI_RST_low();

mDelaymS(100);*/?

CH376_PORT_INIT( ); ? ? ? ? ??

xWriteCH376Cmd( CMD11_CHECK_EXIST );?

xWriteCH376Data( 0x55 );

res = xReadCH376Data( );

//printf("res =%02x \n",(unsigned short)res);

xEndCH376Cmd( );

if ( res != 0xAA ) return( ERR_USB_UNKNOWN ); ?

xWriteCH376Cmd( CMD11_SET_USB_MODE );?

xWriteCH376Data( 0x06 );?

delay_us( 20 );

res = xReadCH376Data( );

//printf("res =%02x \n",(unsigned short)res);

xEndCH376Cmd( );


if ( res == CMD_RET_SUCCESS ) ?

{

? ?return( USB_INT_SUCCESS );?

}

else?

{

? ?return( ERR_USB_UNKNOWN );

}

}

初始化返回值一直是0xff,不知道怎么回事,淚崩!??!

376SPI接口的選擇需要硬件配置某些管腳。MOSI接376的SDI。

晶振是否起振?

http://www.findthetime.net/bbs/thread-65126-1.html


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频