cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F10x UART tx hyperterminal

nick2
Associate II
Posted on March 24, 2015 at 14:45

Hello,

I want to sent some characters to a hyperterminal program. But my program wont work..

I dont receive any characters in my hyperterminal. 

I am using the STM32-P107 development kit. The controller on it is the STM32F107VC

I really need help here. I hope someone here see what i am doing wrong. I would really appreciate it. 

This is my code:

/* Includes ------------------------------------------------------------------*/

#include ''stm32f10x.h''

#include ''stm32f10x_gpio.h''

#include ''stm32f10x_rcc.h''

#include ''stm32f10x_usart.h''

#include <stdio.h>

void USART_Print_Nick(void)

{

 int i;

//**************************************RCC Configuration*************************************\

 /* Enable GPIO clock */

 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOC, ENABLE);

 /* Enable UART clock */

 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

//**************************************GPIO Configuration*************************************\

 GPIO_InitTypeDef GPIO_InitStructure;

 /* Configure USART Tx as alternate function push-pull */

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;   // PA.02 USART1.TX

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

 GPIO_Init(GPIOA, &GPIO_InitStructure);

 /* Configure USART Rx as input floating */

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // PA.03 USART1.RX

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

 GPIO_Init(GPIOA, &GPIO_InitStructure);

 //LED TOGGLE.. initialized // PA.08 = output port for LED

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

 GPIO_Init(GPIOC, &GPIO_InitStructure);

//**************************************USART Configuration*************************************\

 USART_InitTypeDef USART_InitStructure;

 USART_InitStructure.USART_BaudRate = 115200;

 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 configuration */

 USART_Init(USART2, &USART_InitStructure);

 /* Enable the USART2 */

 USART_Cmd(USART2, ENABLE);

//******************************************Program**********************************************\

 while(1)

   {

    // 1010.1010

    USART_SendData(USART2, 0xAA);

    //LED toggle

    GPIO_WriteBit(GPIOC, GPIO_Pin_8, 1);

       for(i=0;i<0x100000;i++);

    GPIO_WriteBit(GPIOC, GPIO_Pin_8, 0);

       for(i=0;i<0x100000;i++);

   }

}

15 REPLIES 15
Posted on March 25, 2015 at 12:29

Can you show us the code example that worked, perhaps that will shed some light on why this doesn't work.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 25, 2015 at 12:35

Could it be that the board uses PD5/PD6 for USART2? That you need to use Bank D, and remap the USART2 there?

Last post,

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a//my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F107%20SEND%20RECEIVE%20USART&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=2618

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
nick2
Associate II
Posted on March 25, 2015 at 13:11

THanks for answer again!

No its connected to PA2 (tx) PA3 (rx), i checked again.

I will show you but the software is really diffurrent and has other header / c files.

I hope you can do something with this information. I still can't get it work

This is software with libraries from coocox. I think you can't do much with this.. 

I hope to hear it soon from you again 

//*****************************************************************************

//

//! \file UartPrintf.c

//! \brief Using UART0 to print some data to terminal.

//! \version 1.0

//! \date 6/29/2012

//! \author CooCox

//! \copy

//!

//! Copyright (c) 2009-2011 CooCox.  All rights reserved.

//

//*****************************************************************************

#include ''xhw_types.h''

#include ''xhw_ints.h''

#include ''xhw_nvic.h''

#include ''xhw_memmap.h''

#include ''xdebug.h''

#include ''xcore.h''

#include ''xsysctl.h''

#include ''xgpio.h''

#include ''xuart.h''

#include ''xhw_types.h''

#include ''xhw_memmap.h''

#include ''xhw_ints.h''

#include ''xhw_nvic.h''

#include ''xcore.h''

#include ''xsysctl.h''

#include ''xgpio.h''

//*****************************************************************************

//

//! \brief print some data to terminal.

//!

//! \param None

//!

//! \return None.

//

//*****************************************************************************

void UartPrintf(void)

{

    unsigned long i;

    int y = 0xAA;

    int t;

    int d = 0x55;

    

    //

    //Set System Clock

    //

    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_25MHZ);

    xSysCtlDelay(10000);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);   

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOD);

    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

    xSPinTypeUART(UART2TX,PD5);

    

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART2);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART2);

    xUARTConfigSet(USART2_BASE, 115200, (UART_CONFIG_WLEN_8 |

                                         UART_CONFIG_STOP_ONE | 

                                         UART_CONFIG_PAR_NONE));

    xUARTEnable(USART2_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX));

    //

    // Set GPIO port C pin 6 , 7 output mode.

    //

    xGPIODirModeSet( xGPIO_PORTC_BASE, xGPIO_PIN_6, xGPIO_DIR_MODE_OUT );

    xGPIODirModeSet( xGPIO_PORTC_BASE, xGPIO_PIN_7, xGPIO_DIR_MODE_OUT );

    //

    // Initionalize system clock.

   //

    xSysCtlPeripheralEnable( xSYSCTL_PERIPH_GPIOC );

    while (1)

    {

             // Output low level.

             xGPIOPinWrite( xGPIO_PORTC_BASE, xGPIO_PIN_6 | xGPIO_PIN_7, 0 );

             xUARTCharPut(USART2_BASE, y);

             for(i = 0; i < 1000000; i++);

             // Output high level.

             xGPIOPinWrite( xGPIO_PORTC_BASE, xGPIO_PIN_6 | xGPIO_PIN_7, 1 );

             xUARTCharPut(USART2_BASE, d);

             for(i = 0; i < 1000000; i++);

    }

}

Posted on March 25, 2015 at 13:18

No its connected to PA2 (tx) PA3 (rx), i checked again.

 

Which version of the board? The most recent schematic definitely shows it using PD5/PD6

And in the code that works

xSPinTypeUART(UART2TX,PD5);

Try the code from the example I presented in the other thread.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 25, 2015 at 13:20

https://www.olimex.com/Products/ARM/ST/STM32-P107/resources/STM32-P107_board_revision_C.pdf

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
nick2
Associate II
Posted on March 25, 2015 at 13:54

Thanks a lot man!!

I had a old revision..

I did remap the usart and it works! thanks a lot..!! Now i am gonna try receive etc!

Thanks. Have a nice day man!!