2015-12-15 05:21 AM
Hi all, trying to use the UART interrupt fuction, i set up cube and got a close look at theSTM32Cube_FW_F4_V1.9.0\Projects\STM32F4-Discovery\Examples\UART\UART_TwoBoards_ComIT
this is my code, that does not work...#define TXBUFFERSIZE 2
#define RXBUFFERSIZE 2
UART_HandleTypeDef huart2;
__IO ITStatus UartReady = RESET;
uint8_t *USART_Tx_Pointer;
uint8_t *USART_Rx_Pointer;
uint8_t USART_TxBuffer[7];
uint8_t USART_RxBuffer[7];
static void MX_USART2_UART_Init(void);
///////// main ////////
HAL_Init();
SystemClock_Config();
MX_USART2_UART_Init();
USART_TxBuffer[2] = 0x0A;
USART_TxBuffer[3] = 0x0A;
USART_Tx_Pointer = &USART_TxBuffer[0];
USART_Rx_Pointer = &USART_RxBuffer[0];
while (1)
{
if(HAL_UART_Transmit_IT(&huart2, USART_Tx_Pointer, TXBUFFERSIZE)!= HAL_OK)
{
//Error_Handler();
}
/*##-3- Wait for the end of the transfer ###################################*/
while (UartReady != SET)
{
////// stucks HERE
}
/* Reset transmission flag */
UartReady = RESET;
////////// Initialize //////////////
void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__GPIOD_CLK_ENABLE();
////////
}
void MX_USART2_UART_Init(void)
{
huart2.Instance = USART2;
huart2.Init.BaudRate = 19200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&huart2);
}
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(huart->Instance==USART2)
{
/* Peripheral clock enable */
__USART2_CLK_ENABLE();
/**USART2 GPIO Configuration
PD5 ------> USART2_TX
PD6 ------> USART2_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* Peripheral interrupt init*/
HAL_NVIC_SetPriority(USART2_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(USART2_IRQn);
}
}
#usart
2015-12-16 03:47 AM
I tried the HAL_UART_Receive, HAL_UART_Transmit and they send-receive data. although when transmiting it sends the LSB first, anyone know how to change the orfer of transmission?
2015-12-16 11:22 PM
Hi, sending LSB first is the UART standard. Why don't you just swap the bits?
2015-12-21 04:44 AM
Yes after reading a bit i realize LSB first is standard, why thought UART_IT function does not work ? I need the interrupt function for receive.
Is there ANY HELP for the HAL libraries... ??2016-01-19 10:21 AM