STM32+CH376并口模式,总返回错误值,有整过的朋友帮忙看看!感谢!下面是程序部分:
引脚配置:
const GPIO_INIT CH376_Init[CH376_NBR ]=
{
{GPIOE , GPIO_Pin_0}, //SD_D0
{GPIOE , GPIO_Pin_1}, //SD_D1
{GPIOE , GPIO_Pin_2}, //SD_D2
{GPIOE , GPIO_Pin_3}, //SD_D3
{GPIOE , GPIO_Pin_4}, //SD_D4
{GPIOE , GPIO_Pin_5}, //SD_D5
{GPIOE , GPIO_Pin_6}, //SD_D6
{GPIOE , GPIO_Pin_7}, //SD_D7
{GPIOB , GPIO_Pin_9}, //SD_RST1
{GPIOB , GPIO_Pin_12}, //SD_A0
{GPIOB , GPIO_Pin_13}, //SD_RD
{GPIOB , GPIO_Pin_14}, //SD_WR
{GPIOB , GPIO_Pin_15}, //SD_PCS
};
void GPIO_init(void)
{
int i,j,k,m,n;
/*初始化CH376各个输入引脚:SD_D0,SD_D1,SD_D2,SD_D3,SD_D4,SD_D5,SD_D6,SD_D7,
SD_RST1,SD_A0,SD_RD,SD_WR,SD_PCS*/
for(m=0;m{
GPIO_InitStructure.GPIO_Pin=CH376_Init[m].Pin;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(CH376_Init[m].Port,&GPIO_InitStructure);
}
/*初始化CH376的:SD_INT*/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
CH376.c部分:
#include "Ch376.h"
#include "Delay_ms.h“
void xWriteCH376Cmd(u8 u8Cmd)
{
u8 i;
CH376_CMD_PORT = (u16)u8Cmd;
for (i=100; i!=0; --i)
{
delay_us(2);
if ((xReadCH376Status() & PARA_STATE_BUSY ) == 0 )
{
break;
}
}
}
void xWriteCH376Data(u8 u8Data)
{
CH376_DAT_PORT = (u16)u8Data;
delay_us(2);
}
u8 xReadCH376Data(void)
{
u16 u16Temp = CH376_DAT_PORT;
//DelayMs(2);
delay_us(2);
return (u8)u16Temp;
}
u8 Query376Interrupt(void)
{
return (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_8) ? FALSE : TRUE);
}
u8 mInitCH376Host(void)
{
u8 u8Result;
xWriteCH376Cmd(CMD11_CHECK_EXIST);
xWriteCH376Data(0x65);
delay_ms(10);
u8Result = xReadCH376Data();
if (u8Result != 0x9A )
{
return ERR_USB_UNKNOWN;
}
xWriteCH376Cmd(CMD11_SET_USB_MODE);
xWriteCH376Data(0x06);
//mDelayuS(20);
delay_ms(10);
u8Result = xReadCH376Data();
if (u8Result == CMD_RET_SUCCESS)
{
return USB_INT_SUCCESS;
}
else
{
return(ERR_USB_UNKNOWN);
}
}
然后再主函数写了测试程序(只列取其中一部分):
s=mInitCH376Host();
printf("s=%02x \n",s);
printf( "Wait Disk\n" );
发现返回值不是9A,而是错位值:FA,,,不知道咋回事,各位帮忙看看程序部分有没有问题,感谢!
查看: 5062
回复: 0
STM32+CH376并口模式,总返回错误值
热门产品 :
CH182: 以太网PHY收发器芯片
请勿发布广告和违法内容, 代码可以选择编辑器代码语言格式, 更易他人阅读帮助您, 或者留下联系方式,以便更好更快服务您
只有登录才能回复,可以选择微信账号登录