cancel
Showing results for 
Search instead for 
Did you mean: 

USART interruptions

francesc
Associate II
Posted on April 07, 2009 at 06:36

USART interruptions

5 REPLIES 5
francesc
Associate II
Posted on May 17, 2011 at 13:08

Hi.

I have make a program to communicate between USART1 and USART2. I have taken most of the code from STM32 library USART examples.

I send data with USART1 (by pooling) and I receive data with USART2 (by IRQ).

The problem that I have is that the USART2 interrupt enters continuously.

The code to program the USART2 is the following:

USART_StructInit(&USART_InitStructure);

USART_InitStructure.USART_BaudRate = 9600;

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_Init(USART2, &USART_InitStructure);

USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);

USART_ITConfig(USART2, USART_IT_TXE, DISABLE);

I only enable the RXNE interrupt, but the USART2 interrupt enters continuously without any data reception.

When the interruption enters, the values in the USART2 registers are:

USART2_SR = 0xC0 // RXNE empty, TC completed and TXE transfered

USART2_CR1 = 0x202c // RE, TE, RXNEIE enabled, TXEIE and other interrupts disabled

Any idea about what is the cause of this interruption?

By the way, Do you plan to make possible RSS subscriptions to the forum?

Best regards

andreas2
Associate II
Posted on May 17, 2011 at 13:08

Please share your interrupt handler and transmission code. What do you mean by ''enters continuously without any data reception''? The ref manual says, that the interrupt flag shall be cleared by a read of the status register SR, followed by a read of the data register DR. How can you not receive any data if you do this?

francesc
Associate II
Posted on May 17, 2011 at 13:08

Thank you very much.

I have been looking a lot of flags of the USART, but not the first line of the interruption code.

The problem is solved

francesc
Associate II
Posted on May 17, 2011 at 13:08

The transmission code is the following:

if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

{

// Read one byte from the receive data register

BufRx[NumBytesRx] = USART_ReceiveData(USART2);

if (BufRx[NumBytesRx]=='\r')

fFinalRx = 1;

NumBytesRx++;

}

And my transmission code (with another USART) is:

for (i=0; Buf[i]!=0; i++)

{

USART_SendData(USART1, Buf[i]);

while (USART_GetFlagStatus(USART1, USART_FLAG_TXE)==RESET);

}

When I comment that the interruption enters continuously without any data reception, it means that the interruption enters without any apparent cause. At the moment that the interruption enters:

* In the USART_SR, the only flags active are TXE and TC (Transmission data register empty and transmission complete).

* In the USART_CR1 I have set the bits RE, TE, RXNEIE, but not the bits that enable the Transmission interrupt.

The problem is that the main program doesn't run, because the micro controller spends all the time in the USART interruption. If the USART receives a byte, the interruption reads it.

pipiluxixi1
Associate II
Posted on May 17, 2011 at 13:08

Quote:

On 06-04-2009 at 08:24, Anonymous wrote:

The transmission code is the following:

if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

{

// Read one byte from the receive data register

BufRx[NumBytesRx] = USART_ReceiveData(USART2);

if (BufRx[NumBytesRx]=='\r')

fFinalRx = 1;

NumBytesRx++;

}

I think it should be ''USART2'' instead of ''USART1'':

if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)