本帖最后由 wanghlady 于 2014-12-25 16:08 编辑
SPI1—SR发送接收始终为空,也就是0x02。
INT#始终为高,mcu和376连接不上,也检测不到U盘
这是初始化,用的B口的345复用,345分别为sck,miso,mosi。stm的片子是主机,所以NSS随便选了PC11。
void SPIx_Init(void)
{
RCC->APB2ENR|=1<<3; //PORTBê±Öóê1Äü
RCC->APB2ENR|=1<<12; //SPI1ê±Öóê1Äü
GPIOB->CRL&=0X00FFF000;
GPIOB->CRL|=0X00BBB000;//PB3.4.5¸′óÃ
RCC->APB2ENR|=1<<4; //PORTC ê±Öóê1Äü
GPIOC->CRH&=0XFF000FFF;//PC4.5
GPIOC->CRH|=0X00383000;//PC4--INT .5--RST íÆíìêä3ö
GPIOC->ODR|=1<<13;//PC5êä3öÎa¸ß
GPIOC->ODR|=1<<11;//PC5êä3öÎa¸ß
GPIOC->IDR|=1<<12;//PC4éÏà-êäèë
////////////////////////////////////////////////////////////////////////////////////
SPI1->CR1|=0<<10;//è«Ë«1¤Ä£ê½
SPI1->CR1|=1<<9; //ÆôóÃèí¼tnss1üàí
SPI1->CR1|=1<<8; //SSM룬NSSμçƽÎa¸ß£¬
SPI1->CR1|=1<<2; //SPIÖ÷»ú
SPI1->CR1|=0<<11;//8bitêy¾Y¸ñê½
SPI1->CR1|=1<<1; //¿ÕÏDÄ£ê½ÏÂSCKÎa1 CPOL=1
SPI1->CR1|=1<<0; //êy¾Y2éÑù′óμú¶t¸öê±¼ä±ßÑØ¿aê¼,CPHA=1
SPI1->CR1|=7<<3; //Fsck=Fcpu/256
SPI1->CR1|=0<<7; //MSBfirst
SPI1->CR1|=1<<6; //SPE=1 é豸ê1Äü
}
下面是ch376的初始化
uint8_t mInitCH376Host( void )
{
uint8_t res;
mDelaymS(200);
mDelaymS(200);
mDelaymS(200);
CH376_PORT_INIT( ); /* ½ó¿úó2¼t3õê¼»ˉ */
xWriteCH376Cmd( CMD11_CHECK_EXIST ); /* 2aêÔμ¥Ƭ»úóëCH376Ö®¼äμÄí¨Ñ¶½ó¿ú */
xWriteCH376Data( 0x55 );
res = xReadCH376Data( );
// printf("res =%02x
",(unsigned short)res);
xEndCH376Cmd( );
if ( res != 0xAA ) return( ERR_USB_UNKNOWN ); /* í¨Ñ¶½ó¿ú2»Õy3£,¿éÄüÔ-òòóD:½ó¿úᬽóòì3£,ÆäËüé豸ó°Ïì(Ƭѡ2»Î¨ò»),′®¿ú2¨ìØÂê,ò»Ö±Ôú¸′λ,¾§Õñ2»1¤×÷ */
xWriteCH376Cmd( CMD11_SET_USB_MODE ); /* é豸USB1¤×÷Ä£ê½ */
xWriteCH376Data( 0x06 ); //06H=òÑÆôóÃμÄÖ÷»ú·½ê½2¢Çò×Ô¶ˉ2úéúSOF°ü ???
mDelayuS( 20 );
res = xReadCH376Data( );
xEndCH376Cmd( );
if ( res == CMD_RET_SUCCESS ) //RES=51 Ãüáî2ù×÷3é1|
{
return( USB_INT_SUCCESS ); //USBêÂÎñ»òÕß′«êä2ù×÷3é1|
}
else
{
return( ERR_USB_UNKNOWN );/* éèÖÃÄ£ê½′íÎó */
}
}
谢谢
此帖出自
小平头技术问答
一周热门 更多>