cancel
Showing results for 
Search instead for 
Did you mean: 

USARTx->DR not getting updated.

anuja
Associate II
Posted on April 25, 2014 at 20:49

The original post was too long to process during our migration. Please click on the attachment to read the original post.
6 REPLIES 6
Posted on April 25, 2014 at 21:18

I get the Tx interrupt but when I call the void USART_SendData(USART_TypeDef* USARTx, uint16_t Data) , the USARTx-> DR register does not reflect the value it is assigned.

Why would it? It's not a memory cell, it's a peripheral register whose behaviour is different in the read and write contexts because it's pointing at a complete different set of flip-flops.

If you stick the debugger over the USARTx->DR you will break it, and the status reported in USARTx->SR

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
anuja
Associate II
Posted on April 25, 2014 at 22:27

Hi Clive,

Thanks for replying.

I cannot see any data on the oscilloscope. The TXE bit in the SR register is always set.

If i try loop back by connecting Tx to Rx i do not get any Rx interrupt either.

Posted on April 26, 2014 at 05:15

RCC_APB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

AHB1 AHB1
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on April 26, 2014 at 05:24

// STM32 USART IRQ TX/RX Loop (USART3 Tx PB.10, Rx PB.11) STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
volatile char StringLoop[] = ''The quick brown fox jumps over the lazy dog

'';
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* USART3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/* GPIOB clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
}
/**************************************************************************************/
void USART3_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 9600 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
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_TXE, ENABLE);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
}
/**************************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USART3 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**************************************************************************************/
void USART3_IRQHandler(void)
{
static int tx_index = 0;
static int rx_index = 0;
if (USART_GetITStatus(USART3, USART_IT_TXE) != RESET) // Transmit the string in a loop
{
USART_SendData(USART3, StringLoop[tx_index++]);
if (tx_index >= (sizeof(StringLoop) - 1))
tx_index = 0;
}
if (USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) // Received characters modify string
{
StringLoop[rx_index++] = USART_ReceiveData(USART3);
if (rx_index >= (sizeof(StringLoop) - 1))
rx_index = 0;
}
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
NVIC_Configuration();
USART3_Configuration();
while(1); // Don't want to exit
}
/**************************************************************************************/

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
anuja
Associate II
Posted on April 29, 2014 at 23:57

Thanks for spotting that Clive.

hbaeteman9
Associate
Posted on April 06, 2015 at 23:34

shouldn't the interrupt handler also handle other interrupt sources?

The interrupt handler only handles the RXNE and the TXE interrupt. But setting RXNEIE also enables the ORE interrupt.

In your example, the interrupt might jam when the ORE interrupt is not serviced.

An other solution is to add the following to the USART init function:

//Disable overrun detection by forcing ORE to zero

USART_OverrunDetectionConfig(USART3, USART_OVRDetection_Disable);

Best regards