I'm new here and I'm trying to solve my projects problem. I'm trying to send send data over UART from Raspberry Pi B+ to my STM32F407 and process that data in real-time. My problem is: How to actually synchronize main() thred and UART interruption handler not to stop for a long time my UART interruption. Data sent from Raspberry looks like (where n is number): nwnx Code:
void UART4_IRQHandler(void)
{
if(USART_GetITStatus(UART4, USART_IT_RXNE))
{
if(!flag)
{
processing = true;
widthTemp[j] = USART_ReceiveData(UART4);
USART_ClearITPendingBit(UART4, USART_IT_RXNE);
if(widthTemp[j] != 'w')
{
j++;
}
else
{
j = 0;
flaga = true;
processing = false;
//__disable_irq();
NVIC_DisableIRQ(UART4_IRQn);
}
}else if(flag)
{
processing = true;
heightTemp[j] = USART_ReceiveData(UART4);
USART_ClearITPendingBit(UART4, USART_IT_RXNE);
if(heightTemp[j] != 'x')
{
j++;
}
else
{
j++;
heightTemp[j] = '\n';
j = 0;
processing = false;
flag = false;
NVIC_DisableIRQ(UART4_IRQn);
}
}
}
}
and now main code:
while (1)
{
if(!NVIC_GetPendingIRQ(UART4_IRQn))
{
//if()
if(flag == true && processing == false)
{
sscanf(heightTemp, "%d", &height );
USART_puts(UART4, heightTemp); // sending back data to raspberry (temporary)
for(i = 0; i< sizeof(widthTemp);i++)
{
heightTemp[i] = '\0';
}
NVIC_EnableIRQ(UART4_IRQn);
}
if(flag == false && processing == false)
{
sscanf(widthTemp, "%d", &width );
USART_puts(UART4, widthTemp); // sending back data to raspberry (temporary)
for(i = 0; i< sizeof(widthTemp);i++)
{
widthTemp[i] = '\0';
}
NVIC_EnableIRQ(UART4_IRQn);
}
}
}
My problem is that at some point rasbperry is starting to have huge delays in recieved data.
Questions: 1. Can I disable interruptions in interruption handler like I did in my code to let my main() know that it can proceed data ? And if yes, do I check good register for this task ? 2. Is there a better way to send buffer (widthTemp f.e.) to some variable ? Maybe I don't need to complicate my code like this. 3. Can I use maybe threding in my code ? Will it help ? 4. This is my first post so any information about how to format questions, advices about the code etc. will be nice.