AnsweredAssumed Answered

USART3 RXNE IT - does not work

Question asked by hynek.ondrej on Apr 21, 2013
Latest reply on Apr 22, 2013 by Clive One
Hello, i need two USARTs working. First one USART1 (TX only) (Used for debugging purposes). Second one USART3 (TX/RX) Write function will send message to another device and waits for answer.
After initialization of both USARTs if i ONLY use one of these USARTs, everything works how i expect. Problem will occur when i send data from USART1(TX work)
and after i want to comunicate over USART3. USART3 will TX data, but RXNE interrupt will never occur. Everything was checked with oscilloscope and i know that slave device sent answer to USART3.

EDIT: Each USART Init  has its own .c file. Global variables are declared as static.

USART1 Initialization and IRQ Handler: 
01.void Debug_Init(void)
02.{
03.    GPIO_InitTypeDef GPIO_InitStructure;
04.    USART_InitTypeDef USART_InitStructure;
05.    NVIC_InitTypeDef NVIC_InitStructure;
06.     
07.    vSemaphoreCreateBinary(WriteLock);
08. 
09.    Queue_TXComplete = xQueueCreate(10, sizeof(u8));
10.     
11.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
12.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
13.     
14.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
15.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
16.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
17.    GPIO_Init(GPIOA, &GPIO_InitStructure);
18.     
19.    USART_DeInit(USART1);
20.    USART_InitStructure.USART_BaudRate = 115200;
21.    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
22.    USART_InitStructure.USART_StopBits = USART_StopBits_1;
23.    USART_InitStructure.USART_Parity = USART_Parity_No ;
24.    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
25.    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
26.    USART_Init(USART1, &USART_InitStructure);
27.     
28.    USART_Cmd(USART1, ENABLE);
29.     
30.    NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
31.    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 12;
32.    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
33.    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
34.    NVIC_Init(&NVIC_InitStructure);
35.}
36. 
37.void USART1_IRQHandler(void)
38.{
39.    u8 Ch = 1;
40.    long int xHigherPriorityTaskWoken = pdFALSE;
41.     
42.    if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET) {
43.        if (TXPtr < TXLen) {
44.            USART_SendData(USART1,TXBuff[TXPtr++]);
45.        }
46.        else{
47.            TXPtr  = 0;
48.            TXLen  = 0;
49.            TXBuff = NULL;
50.            USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
51. 
52.            xQueueSendFromISR(Queue_TXComplete, &Ch, &xHigherPriorityTaskWoken);
53.        }
54.        USART_ClearITPendingBit(USART1, USART_IT_TXE);
55.    }
56. 
57.    portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
58.}



USART3 Initialization and IRQ Handler: 
01.void XBee_Init(void)
02.{
03.    GPIO_InitTypeDef GPIO_InitStructure;
04.    USART_InitTypeDef USART_InitStructure;
05.    NVIC_InitTypeDef NVIC_InitStructure;
06.     
07.    vSemaphoreCreateBinary(WriteLock);
08.    vSemaphoreCreateBinary(ReadLock);
09.     
10.    Queue_TXComplete = xQueueCreate(1, sizeof(u8));
11.    Queue_RXChar = xQueueCreate(64, sizeof(u8));
12.    Queue_XBeeOK = xQueueCreate(1, sizeof(u8));
13.     
14.    ClearRXBuffer();
15.     
16.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
17.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
18.         
19.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
20.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
21.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
22.    GPIO_Init(GPIOB, &GPIO_InitStructure);
23.     
24.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
25.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
26.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
27.    GPIO_Init(GPIOB, &GPIO_InitStructure);
28.     
29.    USART_DeInit(USART3);
30.    USART_InitStructure.USART_BaudRate = 9600;
31.    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
32.    USART_InitStructure.USART_StopBits = USART_StopBits_1;
33.    USART_InitStructure.USART_Parity = USART_Parity_No ;
34.    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
35.    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
36.    USART_Init(USART3, &USART_InitStructure);
37.    USART_Cmd(USART3, ENABLE);
38.     
39.    USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
40.     
41.    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
42.    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 12;
43.    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
44.    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
45.    NVIC_Init(&NVIC_InitStructure);
46.     
47.    while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) != RESET){
48.        USART_ReceiveData(USART3);
49.    }
50.     
51.    xTaskCreate( Task_USART_RX, ( signed portCHAR * ) "Task_USART_RX", 200, NULL, 3 , NULL );
52.}
53. 
54.void USART3_IRQHandler(void)
55.{
56.    u8 Ch = 1;
57.    long int xHigherPriorityTaskWoken = pdFALSE;
58.    u8 Byte;
59.     
60.    if (USART_GetITStatus(USART3, USART_IT_TXE) != RESET) {
61.        if (TXPtr < TXLen) {
62.            USART_SendData(USART3,TXBuff[TXPtr++]);
63.        }
64.        else{
65.            TXPtr  = 0;
66.            TXLen  = 0;
67.            TXBuff = NULL;
68.            USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
69. 
70.            Ch = 1;
71.            xQueueSendFromISR(Queue_TXComplete, &Ch, &xHigherPriorityTaskWoken);
72.        }
73.        USART_ClearITPendingBit(USART3, USART_IT_TXE);
74.    }
75.    
76.    if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET){
77.        
78.        Byte = USART_ReceiveData(USART3);
79.        xQueueSendFromISR(Queue_RXChar, &Byte, &xHigherPriorityTaskWoken);
80.        USART_ClearITPendingBit(USART3, USART_IT_RXNE);
81.    }
82.     
83.    portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
84.}

Thanks for any replies.

Outcomes