2015-02-27 06:34 PM
Hi all,
I am using STM32F103RCT6 and CP2102 as UART controller driver.I have problem with USART when I use SysTick Timer to generate 1us Delay.The problem is that when I configure SysTick at frequency 1Mhz, the program does not work.SysTick_Config(SystemCoreClock / 1000000) // SystemCoreClock is 72 MhzI use SysTick to generate 1us Delay: void Delay(__IO uint32_t nTime){
TimingDelay = nTime; // Timing Delay is a volatile uint32_t variable
while(TimingDelay != 0);
}
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
SysTick handlervoid SysTick_Handler(void){
TimingDelay_Decrement();
Tick++; // my private variable for counting
}
That is how I create my Delay function in microsecond.It works well, but when I want to add USART code, the program doesn't work. When I call USART_Configuration(); in main, the program stucks.void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* Configure PA9 for USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure PA10 for USART Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
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 configuration */
USART_Init(USART1, &USART_InitStructure);
/* Enable USART */
USART_Cmd(USART1, ENABLE);
}
I tried to configure SysTick at 100Khz (delay with resolution 10us), it worked.SysTick_Config(SystemCoreClock / 100000);But my application needs a delay at us. I don't know what is the reason and how to solve it. Can anyone give me some advice. Thank you for reading. #it''s-deja-vu-all-over-again
2015-02-27 07:43 PM
Interrupting at 1 MHz is insane, 72 machine cycles, 22 cycles for an interrupt doing nothing, perhaps 3 cycles per FLASH read. You really need to ponder how the machine works.
[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Systick%20Delay%20functions&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=120]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FSystick%20Delay%20functions&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=1202015-02-27 10:03 PM
2015-02-28 07:24 AM
But the granularity is a little courser, and the math is more awkward.. Not sure that's a win