2014-02-07 06:23 AM
Hi,
I am trying to use two USARTs at the same time, but I can't get it to work.First:
void RCC_Configuration(void){ /* USART1 clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* USART2 clock enable */ RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* GPIOA clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);}Then:
void GPIO_Configuration(void){ GPIO_InitTypeDef GPIO_InitStructure; /* GPIO Configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; 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(GPIOA, &GPIO_InitStructure); /* Connect USART pins to AF */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7); // USART1_TX GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7); // USART1_RX /* GPIO Configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; 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(GPIOA, &GPIO_InitStructure); /* Connect USART pins to AF */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_7); // USART2_TX GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_7); // USART2_RX}And finally:
void USART1_Configuration(void){ USART_InitTypeDef USART_InitStructure; /* USARTx configuration ------------------------------------------------------*/ /* 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; //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(USART1, &USART_InitStructure); USART_Cmd(USART1, ENABLE);}void USART2_Configuration(void){ USART_InitTypeDef USART_InitStructure; /* USARTx configuration ------------------------------------------------------*/ /* 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; //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(USART2, &USART_InitStructure); USART_Cmd(USART2, ENABLE);}And of cause i am calling them all from main: RCC_Configuration(); GPIO_Configuration(); USART1_Configuration(); USART2_Configuration();But I can only send data via USART 1... What can be wrong?!
Kind regards,
Michael #usart #discovery #stm322014-02-07 06:26 AM
/* USART2 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
APB1 !! APB1 !!2014-02-10 12:12 AM
Friday + copy+paste + DO'H (http://www.youtube.com/watch?v=g6GuEswXOXo)!
But thanks! :)Kind regards,Michael