2013-06-23 03:00 PM
I wrote this program whitch send what it receive and each time it toggel the 4 leds in the board !
when i'm debugging the program don't catch the receive interruption !
#include ''stm32f4xx.h''
#include ''stm32f4xx_gpio.h''
#include ''stm32f4xx_rcc.h''
#include ''stm32f4xx_tim.h''
#include ''misc.h''
#include ''stm32f4xx_exti.h''
#include ''stm32f4xx_syscfg.h''
#include ''stm32f4xx_dma.h''
#include ''stm32f4xx_i2c.h''
#include ''stm32f4xx_usart.h''
void UART_Config(){
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_USART1);//TX
GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_USART1);//RX
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
USART_InitStruct.USART_BaudRate = 9600;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_Init(USART1,&USART_InitStruct);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_Cmd(USART1,ENABLE);
}
void GPIO_Configuration(void)
{
/* GPIOD clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
uint16_t a;
void USART1_IRQHandler(void){
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
GPIO_ToggleBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
a=USART_ReceiveData(USART1);
USART_SendData(USART1,a);
}
void main(){
I2C_Config();
UART_Config();
GPIO_Configuration();
while(1){
}
}
2013-06-23 04:00 PM
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
Also you shouldn't need to explicitly clear the IT flag, as reading the data register will clear it.
2013-06-23 10:47 PM
It's working now :) but their is a problem of simpling the data it's lock like that the clock is not set rihght in fact it was configurated as 25Mhz so I generate a new ''system_stm32f4xx.c'' file using ''STM32F4xx_Clock_Configuration_V1.0.1.xls'' to change it to external 8 Mhz and I replaced the old one by this ! but it didn't work the problem of simpling data is always present :\
2013-06-24 06:03 AM
The project would need to be defining HSE_VALUE correctly to reflect the speed of the external crystal (HSE) being used.
2013-06-24 07:37 AM
I'm using IAR6.5 .
I tried to run my code in a template delivred by stm32 for the discovery board witch the clock and every thing is well configurated ! but the same problem is always present : wrong characters send back !2013-06-24 07:51 AM
Then consider how it is connected. The STM32 cannot directly drive RS232 levels.
Observe signal with a scope, verify data and bit timing.2013-06-24 08:05 AM
ok I will do that