硬件:買的CH376S模塊。
1:5V供電采用并口方式。
2:測試晶振起振了。
3:上電RST和RST#都是低電平。與手冊不符合。25腳? RST? 輸出? 電源上電復(fù)位和外部復(fù)位輸出,高電平有效,26腳? RST#? 輸出? 電源上電復(fù)位和外部復(fù)位輸出,低電平有效。
軟件:
#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寫命令函數(shù)
void xWriteCH375Cmd( UINT8 mCmd )
{
CH375_DATA_DAT_OUT( mCmd );? /* 向CH376的并口輸出數(shù)據(jù) */
CH375_DATA_DIR_OUT( );? /* 設(shè)置并口方向為輸出 */
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( );? /* 禁止數(shù)據(jù)輸出 */
delay_us(2);
}
//CH375寫數(shù)據(jù)函數(shù)
void xWriteCH375Data( UINT8 mData )
{
CH375_DATA_DAT_OUT( mData );? /* 向CH376的并口輸出數(shù)據(jù) */
CH375_DATA_DIR_OUT( );? /* 設(shè)置并口方向為輸出 */
CH375_A0 = 0;
CH375_CS = 0;
CH375_WR = 0;? /* 輸出有效寫控制信號, 寫CH376芯片的數(shù)據(jù)端口 */
CH375_WR = 0;? /* 該操作無意義,僅作延時,CH376要求讀寫脈沖寬度大于40nS */
CH375_WR = 1;? /* 輸出無效的控制信號, 完成操作CH376芯片 */
CH375_CS = 1;
CH375_DATA_DIR_IN( );? /* 禁止數(shù)據(jù)輸出 */
delay_us( 1 );? /* 確保讀寫周期大于0.6uS */
}
//CH375讀數(shù)據(jù)函數(shù)
UINT8 xReadCH375Data( void )
{
UINT8mData;
delay_us( 1 );? /* 確保讀寫周期大于0.6uS */
CH375_DATA_DIR_IN( );? /* 設(shè)置并口方向為輸入 */
CH375_A0 = 0;
CH375_CS = 0;
CH375_RD = 0;? /* 輸出有效讀控制信號, 讀CH376芯片的數(shù)據(jù)端口 */
CH375_RD = 0;? /* 該操作無意義,僅作延時 */
mData = CH375_DATA_DAT_IN( );? /* 從CH376的并口輸入數(shù)據(jù) */
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( );? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/* 設(shè)置并口輸入 */
}
int main(void)
{
unsigned char i,s;
unsigned short len;
delay_init();
USART_Config();
CH375_Init();
printf("start...\n");
// 發(fā)送測試命令?
xWriteCH375Cmd(CMD11_CHECK_EXIST);?
// 發(fā)送測試數(shù)據(jù)?
xWriteCH375Data(0x11);?
// 讀數(shù)據(jù)?
s = xReadCH375Data();?
printf("s:%x\n",s);