2012-10-24 10:33 PM
Hi,
I'm having problems receiving USART data on the F4. I can see the data is being sent from my LCD on my Saleae logic analyser, but the STM32 won't call the USART RXNE interrupt. I can send data no problems, just not receive Can anyone see a problem in my code?void USART_Configuration(void){
// sort out clocks
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOD, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
NVIC_InitTypeDef NVIC_InitStructure; // this is used to configure the NVIC
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; // we want to configure the USART3 interrupts
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;// this sets the priority group of the USART3 interrupts
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; // this sets the subpriority inside the group
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // the USART3 interrupts are globally enabled
NVIC_Init(&NVIC_InitStructure);
// Configure LED USART3 Tx (PD8) as alternative function input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// Map USART3 to D.08
GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
// Configure USART3 Rx (PD9) as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// Map USART3 to D.09
GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
// Initialize USART
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_Tx | USART_Mode_Rx;
// Configure USART3
USART_Init(USART3, &USART_InitStructure);
// Enable the USART
USART_Cmd(USART3, ENABLE);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); // enable the USART1 receive not empty interrupt
}
void USART3_IRQHandler(void){
(do something)
}
Thanks for your help in advance!
2012-10-25 12:59 AM
Hi Stive,
In USART Rx configuration, try to change ''GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;''
by ''GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
''2012-10-25 02:59 AM
You can try to use a polling based receiver, instead of interrupt, to ensure there is no problem with reception as such.
JW2012-10-25 08:35 AM
Doesn't look hideous, although the IRQ routine needs to clear the interrupt.
I'm using USART3 PB10/11 with interrupts, seem to work fine for me. Here is a quick IRQ demo for the STM32F4 Discovery board using PD8/9// STM32 USART IRQ TX/RX Loop (USART3 Tx PD.8, Rx PD.9) STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h'' volatile char StringLoop[] = ''The quick brown fox jumps over the lazy dog\r\n''; /**************************************************************************************/ void RCC_Configuration(void) { /* --------------------------- System Clocks Configuration -----------------*/ /* USART3 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); /* GPIOD clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); } /**************************************************************************************/ void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /*-------------------------- GPIO Configuration ----------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; 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(GPIOD, &GPIO_InitStructure); /* Connect USART pins to AF */ GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, 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 } /**************************************************************************************/2014-04-01 06:40 AM
Hi,
I want to use UART1 with interrupt in STM32L151R8 . I tried based on your example but I am not getting the output .please help me through following mail id (thirukannan.perumal@eldaas.com) I am waiting for your help .And advance thanks for your help. Regards, Thirukkannan P (thirukannan.perumal@eldaas.com)2014-04-01 07:35 AM
Yeah, that's not how forums work.
[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/stm32l100%20UART&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/AllItems.aspx¤tviews=13]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fSTM32Java%2fstm32l100%20UART&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&TopicsView=https%3A%2F%2Fmy.st.com%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Java%2FAllItems.aspx¤tviews=13