2018-04-10 04:14 AM
Hello,
i've followed many tutorial to try to get UART with interrupt working on my stm32l476rg (nucleo board) :
at the main.c, before while(1) loop :
HAL_UART_Transmit_IT(&huart4, (uint8_t *)welcome_str,sizeof(welcome_str));
this doesn't work, but in polling mode, it's working :
HAL_UART_Transmit(&huart4, (uint8_t *)welcome_str,sizeof(welcome_str),100);
i'm using hc-06 bluetooth dongle, and receiving it on android Phone, it should be able to receive interrupt without any problem...?
what i'm missing here ? any triggering stuff or ..?
thank you
#uart-it #stm32l4+Solved! Go to Solution.
2018-04-10 03:16 PM
hum, it seems Interrupt wasn't enabled in NVIC uart init... :
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{GPIO_InitTypeDef GPIO_InitStruct;
if(huart->Instance==UART4) { /* USER CODE BEGIN UART4_MspInit 0 *//* USER CODE END UART4_MspInit 0 */
/* Peripheral clock enable */ __HAL_RCC_UART4_CLK_ENABLE(); /**UART4 GPIO Configuration PC10 ------> UART4_TX PC11 ------> UART4_RX */ GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11; 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_UART4; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);HAL_NVIC_SetPriority(UART4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(UART4_IRQn);}
}
after adding last two lines it's fine (y)
2018-04-10 01:17 PM
up!
2018-04-10 02:04 PM
For the interrupt to work:
It must be enabled on the device
It must be enabled on the NVIC
The vector table needs to point to a UART4_IRQHandler
You need your own UART4_IRQHandler
For the HAL the IRQ handler needs to call the HAL_UART_IRQHandler(&UartHandle4)
>>what i'm missing here ? any triggering stuff or ..?
Probably, got zero visibility into your implementation from here..
Perhaps review some examples?
STM32Cube_FW_L4_V1.10.0\Projects\STM32L476RG-Nucleo\Examples\UART\UART_TwoBoards_ComIT
Use strlen() rather than sizeof()
2018-04-10 03:16 PM
hum, it seems Interrupt wasn't enabled in NVIC uart init... :
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{GPIO_InitTypeDef GPIO_InitStruct;
if(huart->Instance==UART4) { /* USER CODE BEGIN UART4_MspInit 0 *//* USER CODE END UART4_MspInit 0 */
/* Peripheral clock enable */ __HAL_RCC_UART4_CLK_ENABLE(); /**UART4 GPIO Configuration PC10 ------> UART4_TX PC11 ------> UART4_RX */ GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11; 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_UART4; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);HAL_NVIC_SetPriority(UART4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(UART4_IRQn);}
}
after adding last two lines it's fine (y)
2018-04-10 04:08 PM
>>up!
Yeah, let's not do that, it's annoying.
Consider if the lack of responses is due to inadequacies in the original post/question. If you feel the need to bump things, try to add something to the context either with more code, or project content instead of pulling two lines out of the air and wondering why it doesn't work.
2018-04-10 04:53 PM
2018-04-10 06:39 PM
rolly loysney wrote:
after adding last two lines it's fine (y)
So please mark the thread as answered:
2018-06-05 03:20 AM
Hi,
I am working on STM32F413H disco EVAL. UART2 is interfaced to BLE modem.
From BLE modem , it is further sent to the iOS app.
I have enabled interrupt in NVIC setting also.
If I send the data in following way, I am able to see it on the app.
uint8_t *ConnectResp = 'ConnectOK\n\r';
HAL_UART_Transmit_IT(&huart2,ConnectResp,11);
I have following issue.
I want to send the CRC with data so I am trying to send the data in following way.
uint8_t payload[20];
payload[0] = 0x39; //0x39 is 9 which is length of the data
payload[1] = 'C'; payload[2] = 'o'; payload[3] = 'n'; payload[4] = 'n'; payload[5] = 'e'; payload[6] = 'c'; payload[7] = 't'; payload[8] = 'O'; payload[9] = 'K'; payload[10] = (uint8_t)((CRC_ConnectResp & 0xFFFFFFFF) >> 24); // CRC-ConnectResp is holding the 4byte CRC payload[11] = (uint8_t)((CRC_ConnectResp & 0xFFFFFF) >> 16); payload[12] = (uint8_t)((CRC_ConnectResp & 0xFFFF) >> 8); payload[13] = (uint8_t)(CRC_ConnectResp & 0xFF); payload[14] = '\n'; payload[15] = '\r';HAL_UART_Transmit_IT(&huart2,payload,16);
When I print this payload --> '9ConnectOKøtg'
On the app ---> getting data in hex format only once.
2018-06-05 05:02 AM
Thanks Clive.
I have one more issue w.r.t. transmit.
If I follow sequence 'receive after transmit or vice-versa' then it works fine.
But if I do 'transmit transmit ' then I am able to get only first few bytes of first transmit, even though I am checking txDone=1.
My Code looks like this:-
volatile bool txDone = 0;
uint8_t Msg1[21] = 'Raw Data-Transfer\n\r';
HAL_UART_Transmit_IT(&huart2,payload,16); //payload is same as above
if(txDone == 1) //txDone = 1 in tx callback function
{
HAL_UART_Transmit_IT(&huart2,Msg1,21);
txDone = 0;
}
I am able to get only -- > '9Con' //first 4 bytes of first transmit.
Anything wrong with my code or transmit should follow receive ?
Thanks,
Poonam
2018-06-05 06:34 AM
As the CRC is going to use the full 8-bit space you're going to get non-printable ASCII characters.
If you need ASCII consider using sprintf(buf,'%08X', CRC_ConnectResp);