Associate
May 6, 2015
Question
USART application DELAY error on STM32F4
- May 6, 2015
- 3 replies
- 1002 views
Posted on May 06, 2015 at 21:33
I have develop an app and one button is sending the string A. However when i connect the STM32F407 and run the program it only can execute one command line instead of all command under the char A. Is there anyway to tackle this problem? I KNOW IT IS RELATED TO DELAY PROBLEM. BUT HOW CAN I SOLVE IT BY PROGRAMMING? THANKS!!!
&sharpinclude ''stm32f4xx.h''&sharpinclude ''usart_config.h''&sharpinclude ''String.h''&sharpinclude ''config.h''&sharpinclude ''delay.h''void usart_lowLevelInit(){ GPIO_InitTypeDef GPIO_InitStructure; /**************************GPIO Configuration*****************************/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Connect USART pins to AF */ GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3); //*************************USARTx configuration ***************************** USART_InitTypeDef USART_InitStructure; /* USARTx configuration -------------------------------/ / * USARTx configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - Two Stop Bit - Odd parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 9600; 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_TC, ENABLE);*/ USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //***************************Interruption Config*********************************** NVIC_InitTypeDef NVIC_InitStructure; /* Configure the NVIC Preemption Priority Bits */ //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); /* Enable the USART3 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); }//------------------Fonction de Reception ---------------------------------extern __IO uint8_t cursor,flag;extern __IO char buffer[20],result[20];extern __IO char c;void usart_receive(char c){ if (c=='A') { moteur2(1550); delay_nms(100); moteur17(1500); delay_nms(100) ; moteur3(2150); delay_nms(100) ; moteur18(1300); delay_nms(100) ; moteur2(1750); delay_nms(100); moteur17(1200); delay_nms(100) ; moteur8(1200); delay_nms(100); moteur11(1600); delay_nms(100) ; moteur12(500); delay_nms(100) ; moteur9(1400); delay_nms(100); moteur8(1500); delay_nms(100); moteur11(1300); delay_nms(100) ; moteur5(1500);delay_nms(100); moteur14(2100); delay_nms(100); moteur15(1000); delay_nms(100) ; moteur6(1100); delay_nms(100) ; moteur5(1800); delay_nms(100); moteur14(1800); delay_nms(100); moteur3(1850); moteur18(1600); moteur12(900); moteur9(1000); moteur15(1400); moteur6(700); } else if (c=='B') { moteur2(1550); delay_nms(100); moteur17(1500); delay_nms(100) ; moteur3(1650); delay_nms(100) ; moteur18(1700); delay_nms(100) ; moteur2(1750);delay_nms(100); moteur17(1200); delay_nms(100) ; moteur8(1200); delay_nms(100); moteur11(1600); delay_nms(100) ; moteur12(1200); delay_nms(100); moteur9(700); delay_nms(100); moteur8(1500); delay_nms(100); moteur11(1300); delay_nms(100) ; moteur5(1500);delay_nms(100); moteur14(2100); delay_nms(100); moteur15(1800); delay_nms(100) ; moteur6(300); delay_nms(100) ; moteur5(1800); delay_nms(100); moteur14(1800); delay_nms(100); moteur3(1850); moteur18(1600); moteur12(900); moteur9(1000); moteur15(1400); moteur6(700);} } /*----------Dans Le Fichier stm32f4xx_it on ajoute----------------extern char c;extern __IO uint8_t cursor;extern __IO char buffer[64],result[64];void USART3_IRQHandler(void){ c= (char)USART_ReceiveData( USART3);usart_receive(c);} *///------------------Dans Le fichier Main---------------------------- //usart_lowLevelInit()//if (flag==0) flag=1;//&sharpinclude ''usart_config.h'' #stm32 #stm32f4 #usart