AnsweredAssumed Answered

[STM32F4-Discovery] USART6 Problem

Question asked by chen.liang_yu.001 on Apr 8, 2014
Latest reply on Apr 9, 2014 by Clive One
I wrote this program, but after I uploaded and connect RS232 to my notebook, Putty didn't show anything, what the problem?
The source code is down blow:

#include "stm32f4xx.h"                  // Device header
#include <stdio.h>
#include "misc.h"
#include "stm32f4xx_usart.h"            // Keil::Device:StdPeriph Drivers:USART
 
 
 
 
void STM_EVAL_COMInit(USART_InitTypeDef* USART_InitStruct)
{
  GPIO_InitTypeDef GPIO_InitStructure;
 
  /* Enable GPIO clock */
  //RCC_AHB1PeriphClockCmd(UART4_TX_PIN | UART4_RX_PIN, ENABLE);
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); //clock a PORTC
 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE); //clock alla UART4!
 
  /* Connect PXx to USARTx_Tx*/
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);
 
  /* Connect PXx to USARTx_Rx*/
  GPIO_PinAFConfig( GPIOC, GPIO_PinSource7, GPIO_AF_USART6);
 
 
  /* Configure USART Tx as alternate function  */
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
 
  /* Configure USART Rx as alternate function  */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
 
 
 
 
  /* USART configuration */
  USART_Init(USART6, USART_InitStruct);
 
 
 
  /* Enable USART */
  USART_Cmd(USART6, ENABLE);
}
 
int main(void){
    USART_InitTypeDef Usart6;
    Usart6.USART_BaudRate = 38400;
    Usart6.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    Usart6.USART_Mode = USART_Mode_Tx;
    Usart6.USART_Parity = USART_Parity_No;
    Usart6.USART_StopBits = USART_StopBits_1;
    Usart6.USART_WordLength = USART_WordLength_8b;
     
    STM_EVAL_COMInit(&Usart6);
    USART_ClearFlag(USART6, USART_FLAG_TC);
    USART_ClearITPendingBit(USART6,USART_IT_TXE);
    while(1){
        USART_ClearITPendingBit(USART6,USART_IT_TXE);
        USART_SendData(USART6, (uint16_t)"Testing...\n");
        while(USART_GetFlagStatus(USART6, USART_FLAG_TXE) == RESET);
        USART_ClearFlag(USART6, USART_FLAG_TC);
    }
     
    return 0;
}

Outcomes