|
我的屏幕是 DMG12800L101_01WTC,只有一个usart接口,我用的是TTL的接口,不知道对不对
我看手册,有一个指令,如图,发送这个指令就可以返回一个指令
我用对应硬件的串口发送了指令,同时弄了接收中断,但是什么也接收不到。用stm32控制这个屏,难道不是这个方法吗?我蒙了。谢谢
代码,main函数
- u8 DWBuff[10] = {0};
- u8 DWCnt = 0;
- int main(void)
- {
- Debug_USART1_Cfg();
- DW_Cfg();
- NVIC_DW_Cfg();
- DW_USART3_SendByte(0x5A);
- DW_USART3_SendByte(0xA5);
- DW_USART3_SendByte(0x04);//长度
- DW_USART3_SendByte(0x83);
- DW_USART3_SendByte(0x00);
- DW_USART3_SendByte(0x0F);
- DW_USART3_SendByte(0x01);
- while(1)
- {
- if(DWCnt >=9)
- {
- DEBUG_USART1_SendStr(DWBuff,DWCnt);
- DWCnt = 0;
- }
- }
-
- }
复制代码 中断服务函数
- void USART3_IRQHandler(void)
- {
- u8 ubRx = 0;
- if(USART_GetITStatus( USART3, USART_IT_RXNE) != RESET)
- {
- DWBuff[DWCnt++] = USART_ReceiveData(USART3);
- //USART_SendData(USART1,ubRx);
- USART_ClearITPendingBit(USART3, USART_IT_RXNE);
- }
- }
复制代码 串口配置函数
- void DW_Cfg(void)
- {
- USART_InitTypeDef USART_InitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
- /*打开PB口和串口3的时钟*/
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
- /*配置PB10 PB11的复用功能,不能按位或*/
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
-
- /* USART3 Tx PB10的GPIO配置,参考官方库 */
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//速度这里比官方库慢
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- /* USART3 Rx PB11的GPIO配置,参考官方库 */
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- USART_InitStructure.USART_BaudRate = 115200;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
-
- USART_Init(USART3, &USART_InitStructure);
-
- USART_Cmd(USART3, ENABLE);
-
- USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
- }
复制代码 NVIC函数
- void NVIC_DW_Cfg(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- /* Enable the USARTx Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
复制代码
|
|