硬件:买的CH376S模块。
1:5V供电采用并口方式。
2:测试晶振起振了。
3:上电RST和RST#都是低电平。与手册不符合。25脚 RST 输出 电源上电复位和外部复位输出,高电平有效,26脚 RST# 输出 电源上电复位和外部复位输出,低电平有效。
软件:
#if ( CH375_PORT_MODE==2 || CH375_PORT_MODE==3 )
//DATAPORT: B0~B7
//WR: B8
//CS: B9
//A0: B10
//RD: B11
//INT: C13
#define CH375_WR PBout(8)
#define CH375_CS PBout(9)
#define CH375_A0 PBout(10)
#define CH375_RD PBout(11)
#define CH375_DATA_DIR_IN() GPIOB->CRL = 0x44444444
#define CH375_DATA_DIR_OUT() GPIOB->CRL = 0x33333333
#define CH375_DATA_DAT_OUT( mCmd ) GPIOB->ODR = (GPIOB->ODR & 0xFF00) | (uint8_t)mCmd
#define CH375_DATA_DAT_IN( ) (uint8_t)GPIOB->IDR
//CH375写命令函数
void xWriteCH375Cmd( UINT8 mCmd )
{
CH375_DATA_DAT_OUT( mCmd ); /* 向CH376的并口输出数据 */
CH375_DATA_DIR_OUT( ); /* 设置并口方向为输出 */
CH375_A0 = 1;
CH375_CS = 0;
CH375_WR = 0; /* 输出有效写控制信号, 写CH376芯片的命令端口 */
CH375_WR = 0; /* 该操作无意义,仅作延时,CH376要求读写脉冲宽度大于40nS */
CH375_WR = 1; /* 输出无效的控制信号, 完成操作CH376芯片 */
CH375_CS = 1;
CH375_A0 = 0;
CH375_DATA_DIR_IN( ); /* 禁止数据输出 */
delay_us(2);
}
//CH375写数据函数
void xWriteCH375Data( UINT8 mData )
{
CH375_DATA_DAT_OUT( mData ); /* 向CH376的并口输出数据 */
CH375_DATA_DIR_OUT( ); /* 设置并口方向为输出 */
CH375_A0 = 0;
CH375_CS = 0;
CH375_WR = 0; /* 输出有效写控制信号, 写CH376芯片的数据端口 */
CH375_WR = 0; /* 该操作无意义,仅作延时,CH376要求读写脉冲宽度大于40nS */
CH375_WR = 1; /* 输出无效的控制信号, 完成操作CH376芯片 */
CH375_CS = 1;
CH375_DATA_DIR_IN( ); /* 禁止数据输出 */
delay_us( 1 ); /* 确保读写周期大于0.6uS */
}
//CH375读数据函数
UINT8 xReadCH375Data( void )
{
UINT8mData;
delay_us( 1 ); /* 确保读写周期大于0.6uS */
CH375_DATA_DIR_IN( ); /* 设置并口方向为输入 */
CH375_A0 = 0;
CH375_CS = 0;
CH375_RD = 0; /* 输出有效读控制信号, 读CH376芯片的数据端口 */
CH375_RD = 0; /* 该操作无意义,仅作延时 */
mData = CH375_DATA_DAT_IN( ); /* 从CH376的并口输入数据 */
CH375_RD = 1;
CH375_CS = 1; /* 输出无效的控制信号, 完成操作CH376芯片 */
return( mData );
}
void CH375_Init( void )
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = 0x0FFF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
#ifdef CH375_INT_WIRE
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//INT
GPIO_Init(GPIOC, &GPIO_InitStructure);
#endif
CH375_CS = 1;
CH375_WR = 1;
CH375_RD = 1;
CH375_A0 = 0;
CH375_DATA_DIR_IN( ); /* 设置并口输入 */
}
int main(void)
{
unsigned char i,s;
unsigned short len;
delay_init();
USART_Config();
CH375_Init();
printf("start...\n");
// 发送测试命令
xWriteCH375Cmd(CMD11_CHECK_EXIST);
// 发送测试数据
xWriteCH375Data(0x11);
// 读数据
s = xReadCH375Data();
printf("s:%x\n",s);