板子自带的LCD用的FSMC的FSMC_Bank1_NORSRAM4,16b宽度的数据线。
STM32ZE与CH376模块引脚的连接如下:
STM32ZE CH376 D0-D7 --------------- D0-D7 A0(LCD_CON RS) ------ A0 PD4(LCD_CON RD) ----- CH375RD# PD5(LCD_CON WR) ----- CH375WR# PG6(FSMC_INT2) ------ CH375INT# PD7(FSMC_OE1) ------ CH375CS#
端口初始化如下: void CH376_PORT_INIT(void) { FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef p; GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG|RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10; GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOG, &GPIO_InitStructure);
p.FSMC_AddressSetupTime = 0; p.FSMC_AddressHoldTime = 2; p.FSMC_DataSetupTime = 4; p.FSMC_BusTurnAroundDuration = 0; p.FSMC_CLKDivision = 0; p.FSMC_DataLatency = 0; p.FSMC_AccessMode = FSMC_AccessMode_A;
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); }
CH376.H 中如下设置: #define CH376_DAT_PORT (*( vu32 *)0x60000000) // A0 = 0, CS = 0 #define CH376_CMD_PORT (*( vu32 *)0x60000002) // A0 = 1, CS = 0
在芯片初始化中卡住了:
u8 mInitCH376Host(void) { // u8 u8Result; CH376_PORT_INIT(); /* 接口硬件初始化 */
/* 测试单片机与CH376之间的通讯接口 */ // 发送测试命令 xWriteCH376Cmd(CMD11_CHECK_EXIST); // 发送测试数据 xWriteCH376Data(0x65); // 读数据 u8Result = xReadCH376Data(); // 通讯正常的情况下将能读到测试数据的取反 if (u8Result != 0x9A ) { /* 通讯接口不正常,可能原因有:接口连接异常,其它设备影响(片选不唯一),串口波特率,一直在复位,晶振不工作 */ return ERR_USB_UNKNOWN; } /* 设备USB工作模式:主机模式 */ xWriteCH376Cmd(CMD11_SET_USB_MODE); xWriteCH376Data(0x06); DelayMs(10); u8Result = xReadCH376Data();
if (u8Result == CMD_RET_SUCCESS) { return USB_INT_SUCCESS; } else { /* 设置模式错误 */ return(ERR_USB_UNKNOWN); } }
每次都是返回未知错误。。。请大侠赐教。