This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I need a help for code..

Hello everybody.
I need to transmit through UART a fixed number in the data block through the command.
I did this :
void USART2_IRQHandler(void)
{

if ( USART_GetITStatus(USART2, USART_IT_RXNE) )
{
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
RX_buffer[RX_write] = USART_ReceiveData(USART2);
RX_write++; //chetchik ukazatel na massive
RX_ct++;
if (RX_ct == 9)
{
if (RX_buffer[0] == 0x01) //ID
{
ID();
}
}
}
}

void ID (uint8_t i)
{
while (!USART_GetFlagStatus(USART2, USART_SR_TXE)) {}
USART_SendData(USART2,i=10);
}


But it's not working...
Parents
  • It's not terribly surprising that that code does not work.  For starters, it's hardly ever a good idea to execute "wait until ... happens" loops inside an interrupt handler routine.  Interrupt handlers are meant to be short.  They need to be over quickly.  Your design, which has a routine inside the interrupt handler quite likely trigger that very same interrupt handler, is even worse.

    And let's hope that somewhere else, there is code to set RX_ct back to != 9, or you'll be sending out your answer for as long as Elvis remains dead.

Reply
  • It's not terribly surprising that that code does not work.  For starters, it's hardly ever a good idea to execute "wait until ... happens" loops inside an interrupt handler routine.  Interrupt handlers are meant to be short.  They need to be over quickly.  Your design, which has a routine inside the interrupt handler quite likely trigger that very same interrupt handler, is even worse.

    And let's hope that somewhere else, there is code to set RX_ct back to != 9, or you'll be sending out your answer for as long as Elvis remains dead.

Children
No data