2024-11-14 05:23 AM
Hello All,
its my first post here - i just started my journey with Nucleo 429ZI board.
I wrote simple app where i want to receive i different way(with-and-without interrupt) data from USART2 and USART6 ports.
While i dont have any troubles getting data on USART2 RX pin, i can't get antyhing on USART6 RX pin (im using same output terminal for both)
Hereby config (i done everything by clicking in IOC configurator):
for USART2 and USART6 - autogenerated code
if(huart->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspInit 0 */
/* USER CODE END USART2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/**USART2 GPIO Configuration
PA3 ------> USART2_RX
PD5 ------> USART2_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* USER CODE BEGIN USART2_MspInit 1 */
/* USER CODE END USART2_MspInit 1 */
}
else if(huart->Instance==USART6)
{
/* USER CODE BEGIN USART6_MspInit 0 */
/* USER CODE END USART6_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART6_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/**USART6 GPIO Configuration
PC6 ------> USART6_TX
PC7 ------> USART6_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USER CODE BEGIN USART6_MspInit 1 */
/* USER CODE END USART6_MspInit 1 */
}
Pins for USART6 are PC6 and PC7
Pins for USART2 are PA3 and PD5
code in main is very simple:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
//ret = HAL_UART_Transmit(&huart2, utx_buff, 12, 1000);
HAL_GPIO_TogglePin(LD1_GPIO_Port,LD1_Pin);
HAL_Delay(1000);
HAL_UART_Receive(&huart2, temp, 5, 1000);
HAL_Delay(1000);
HAL_UART_Receive(&huart6, temp2, 5, 1000);
}
where:
uint8_t temp[8];
uint8_t temp2[8];
im observing temp and temp2 arrays in 'live' view in STM IDE.
While temp is filled with data when i send data over terminal, i cannot see any change in temp2.
Thanks for all support!
2024-11-14 05:46 AM
On Nucleo boards some pins are soldered to something and cannot be used freely. Please check the pin assignment in the documentation. If PC6 and PC7 are not available, try to find alternatives for USART6 (CubeMX/IDE will show) or use other UART.
2024-11-14 05:48 AM
And if you swap the position call of : HAL_UART_Receive(&huart6 ...); and HAL_UART_Receive(&huart2 ...);
HAL_GPIO_TogglePin(LD1_GPIO_Port,LD1_Pin);
HAL_Delay(1000);
HAL_UART_Receive(&huart6, temp2, 5, 1000);
HAL_Delay(1000);
HAL_UART_Receive(&huart2, temp, 5, 1000);
Meanwhile, I suggest to use DMA or interrupt for Rx instead of that kind of programming.
2024-11-14 07:58 AM
What hardware do you use to transmit data from PC to the UARTs? An USB-UART converter, or something else?
JW