2012-10-26 01:57 AM
Hi Guys,
Been trying to get the USART to work for a couple of days now and is time to get some help... This is my code:GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f4xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f4xx.c file
*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);
/* GPIO Pins configuration for Alternative Function */
/* for TX Pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* for RX Pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
//GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* USARTx configured as follow:
- BaudRate = 115200 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(USART2, &USART_InitStructure);
/* Output a message on Hyperterminal using printf function */
//printf(''\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r'');
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
//RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
USART_Cmd(USART2,ENABLE);
USART_SendData(USART2, (uint8_t) 0x31);
while (1)
{
}
}
I tried pretty much all the USARTs on the board and I can not send anything.
I looped back the TX & RX pins on my USB to Serial converter and that works fine.
The processor seems to be cycling fine thorough the code when on Debug.
I am complety at a loss why the program will not work, Any assistance would be appreciated.
Best Regards
Luis
2013-04-18 08:40 AM
2013-04-19 04:56 AM
i used your code to send 'I'....but i don t see it in the hyperteminal???
2013-04-19 06:39 AM
Get a scope, check the bit timings on USARTxTX, confirm valid.
Make sure the HSE_VALUE and crystal on you board match, and that the PLL settings in system_stm32f4xx.c reflect the correct HSE frequency. The STM32F4-Discovery boards use an 8 MHz crystal, a lot of the code in the firmware library expects the 25 MHz crystal of the EVAL series boards. If the software and hardware settings are incoherent serial comms will not work as expected.2013-04-19 08:18 AM
2013-04-19 08:32 AM
2013-04-19 08:45 AM
Sorry but in your code you cnfigure GPIOA not GPIOD;;;;I change it and my connexion is OK
Ok, Fixed that.2013-04-21 07:25 AM
2013-04-21 07:32 AM
printf('' USART Test ''); ;;;i used this instruction to send a string to the hyperteminal but it doesn t work,,,,,
Ok, but how would the compiler know that STDIO data would get to your specific USART on your specific board unless you implement code to enable that? In Keil you'd retarget to the serial port via routines you supply.http://www.keil.com/support/man/docs/gsac/gsac_retargetcortex.htm
Alternatively you could sprintf() to a buffer, and then send that buffer to the USART.2013-04-28 03:44 AM