cancel
Showing results for 
Search instead for 
Did you mean: 

USART3 RXNE IT - does not work

ondrej
Associate II
Posted on April 21, 2013 at 18:35

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:


void
Debug_Init(
void
)

{

GPIO_InitTypeDef GPIO_InitStructure;

USART_InitTypeDef USART_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;


vSemaphoreCreateBinary(WriteLock);


Queue_TXComplete = xQueueCreate(10, 
sizeof
(u8));


RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &GPIO_InitStructure);


USART_DeInit(USART1);

USART_InitStructure.USART_BaudRate = 115200;

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(USART1, &USART_InitStructure);


USART_Cmd(USART1, ENABLE);


NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 12;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

}


void
USART1_IRQHandler(
void
)

{

u8 Ch = 1;

long
int
xHigherPriorityTaskWoken = pdFALSE;


if
(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) {

if
(TXPtr < TXLen) {

USART_SendData(USART1,TXBuff[TXPtr++]);

}

else
{

TXPtr = 0;

TXLen = 0;

TXBuff = NULL;

USART_ITConfig(USART1, USART_IT_TXE, DISABLE);


xQueueSendFromISR(Queue_TXComplete, &Ch, &xHigherPriorityTaskWoken);

}

USART_ClearITPendingBit(USART1, USART_IT_TXE);

}


portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);

}

USART3 Initialization and IRQ Handler:


void
XBee_Init(
void
)

{

GPIO_InitTypeDef GPIO_InitStructure;

USART_InitTypeDef USART_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;


vSemaphoreCreateBinary(WriteLock);

vSemaphoreCreateBinary(ReadLock);


Queue_TXComplete = xQueueCreate(1, 
sizeof
(u8));

Queue_RXChar = xQueueCreate(64, 
sizeof
(u8));

Queue_XBeeOK = xQueueCreate(1, 
sizeof
(u8));


ClearRXBuffer();


RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOB, &GPIO_InitStructure);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOB, &GPIO_InitStructure);


USART_DeInit(USART3);

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(USART3, &USART_InitStructure);

USART_Cmd(USART3, ENABLE);


USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);


NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 12;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);


while
(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) != RESET){

USART_ReceiveData(USART3);

}


xTaskCreate( Task_USART_RX, ( signed portCHAR * ) 
''Task_USART_RX''
, 200, NULL, 3 , NULL );

}


void
USART3_IRQHandler(
void
)

{

u8 Ch = 1;

long
int
xHigherPriorityTaskWoken = pdFALSE;

u8 Byte;


if
(USART_GetITStatus(USART3, USART_IT_TXE) != RESET) {

if
(TXPtr < TXLen) {

USART_SendData(USART3,TXBuff[TXPtr++]);

}

else
{

TXPtr = 0;

TXLen = 0;

TXBuff = NULL;

USART_ITConfig(USART3, USART_IT_TXE, DISABLE);


Ch = 1;

xQueueSendFromISR(Queue_TXComplete, &Ch, &xHigherPriorityTaskWoken);

}

USART_ClearITPendingBit(USART3, USART_IT_TXE);

}


if
(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET){


Byte = USART_ReceiveData(USART3);

xQueueSendFromISR(Queue_RXChar, &Byte, &xHigherPriorityTaskWoken);

USART_ClearITPendingBit(USART3, USART_IT_RXNE);

}


portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);

}

Thanks for any replies.
5 REPLIES 5
Posted on April 21, 2013 at 20:35

Suggest you test outside the clutter of the RTOS.

No need to explicitly clear the interrupt source if you Send/Receive Data.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ondrej
Associate II
Posted on April 21, 2013 at 22:09

Hello clive1, 

thanks for your reply.

I tried to run USART code outside of RTOS. Definitely i dont have any other ideas. Now it doesnt matter if USART1 was used or not. On USART3 RX pin signal looks like its permanently pull-upped. 

EDIT: Code optimizations are off. I tried to use different versions of code sourcery toolchain. Also i tried to combine USART1 & USART2 and USART2&USART3. Everytime with the same result.

STDPeriphLib v3.5.0

EDIT2: I forgot to say when USART3 code did not run within RTOS. IT RXNE was never fired. 

This is image of USART3 RX Pin - Without RTOS. If code run within RTOS and USART1 TX was called, USART3 RX Pin looks same like image above. If USART1 TX not called, signal looks normal.

0690X000006055PQAQ.png

Posted on April 22, 2013 at 01:09

Doesn't look like a valid signal, hardly surprising RXNE is not asserting.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ondrej
Associate II
Posted on April 22, 2013 at 08:34

Of course it isn't. And I know that this signal is a reason why RXNE was never asserted. But how did i say before, if i dont send any data over USART1, USART3 works great. 

Thanks for your time Clive1.

USART3 RX:

0690X000006055UQAQ.png

Posted on April 22, 2013 at 13:14

Ok, then perhaps we should be looking at your hardware and not the software. Suggest you describe the chip and board you're using, ideally with a schematic.

It could be related to software you haven't listed. You could simplify the implementation to the minimal code to demonstrate the failure, and provide a complete example.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..