cancel
Showing results for 
Search instead for 
Did you mean: 

help at UART2

sengunguven
Associate
Posted on November 20, 2007 at 08:43

help at UART2

2 REPLIES 2
sengunguven
Associate
Posted on May 17, 2011 at 09:48

i tried to test the example UART program (for UART0, UART1, and UART2) with using KEIL development tool.

- Although the program works perfect for UART0 and UART1, it did not work for UART2. There was not an output on debugger, at UART2 screen.

- I controlled the data manual for different pin configurations.

Can someone say where is my mistake?

The modified example code is at below.

Thanks Sengun.

/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************

* File Name : main.c

* Author : MCD Application Team

* Date First Issued : 05/18/2006 : Version 1.0

* Description : Main program body

********************************************************************************

* History:

* 05/24/2006 : Version 1.1

* 05/18/2006 : Version 1.0

********************************************************************************

* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS

* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.

* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,

* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE

* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING

* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.

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

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

#include ''91x_lib.h''

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

#define TxBufferSize (countof(TxBuffer) - 1)

#define RxBufferSize 0xFF

/* Private macro -------------------------------------------------------------*/

#define countof(a) (sizeof(a) / sizeof(*(a)))

/* Private variables ---------------------------------------------------------*/

UART_InitTypeDef UART_InitStructure;

u8 TxBuffer[] = ''UART Example1: UART - Hyperterminal communication using hardware flow control\n\r'';

u8 RxBuffer[RxBufferSize];

u8 NbrOfDataToTransfer = TxBufferSize;

u8 TxCounter = 0;

u8 RxCounter = 0;

/* Private function prototypes -----------------------------------------------*/

void SCU_Configuration(void);

void GPIO_Configuration(void);

/* Private functions ---------------------------------------------------------*/

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

* Function Name : main

* Description : Main program

* Input : None

* Output : None

* Return : None

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

int main()

{

#ifdef DEBUG

debug();

#endif

/* Configure the system clocks */

SCU_Configuration();

/* Configure the GPIO ports */

GPIO_Configuration();

/* UART0 configuration -------------------------------------------------------*/

/* UART0 configured as follow:

- Word Length = 7 Bits

- Two Stop Bit

- No parity

- BaudRate = 115200 baud

- Hardware flow control enabled (RTS and CTS signals)

- Receive and transmit enabled

- Receive and transmit FIFOs are enabled

- Transmit and Receive FIFOs levels have 8 bytes depth

*/

UART_InitStructure.UART_WordLength = UART_WordLength_7D;

UART_InitStructure.UART_StopBits = UART_StopBits_2;

UART_InitStructure.UART_Parity = UART_Parity_No ;

UART_InitStructure.UART_BaudRate = 115200;

UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;

UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;

UART_InitStructure.UART_FIFO = UART_FIFO_Enable;

UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */

UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */

UART_DeInit(UART2);

UART_Init(UART2, &UART_InitStructure);

/* Enable the UART2 */

UART_Cmd(UART2, ENABLE);

/* Communication hyperterminal-UART2 using the hardware flow control */

/* Send a buffer from UART to hyperterminal */

while(NbrOfDataToTransfer--)

{

UART_SendData(UART2, TxBuffer[TxCounter++]);

while(UART_GetFlagStatus(UART2, UART_FLAG_TxFIFOFull) != RESET);

}

/* Receive a string (Max RxBufferSize bytes) from the Hyperterminal ended by '\r' (Enter key) */

do

{

if((UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET)&&(RxCounter < RxBufferSize))

{

RxBuffer[RxCounter] = UART2->DR;

UART_SendData(UART2, RxBuffer[RxCounter++]);

}

}while((RxBuffer[RxCounter - 1] != '\r')&&(RxCounter != RxBufferSize));

while (1);

}

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

* Function Name : SCU_Configuration

* Description : Configures the system clocks.

* Input : None

* Output : None

* Return : None

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

void SCU_Configuration(void)

{

/* Enable the UART2 Clock */

SCU_APBPeriphClockConfig(__UART2, ENABLE);

/* Enable the GPIO3 Clock */

SCU_APBPeriphClockConfig(__GPIO3, ENABLE);

/* Enable the GPIO5 Clock */

SCU_APBPeriphClockConfig(__GPIO5, ENABLE);

}

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

* Function Name : GPIO_Configuration

* Description : Configures the different GPIO ports.

* Input : None

* Output : None

* Return : None

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

void GPIO_Configuration(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_DeInit(GPIO3);

/*Gonfigure UART0_Rx pin GPIO5.1*/

/*Gonfigure UART1_Rx pin GPIO3.2*/

/*Gonfigure UART2_Rx pin GPIO3.1*/

GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ;

GPIO_Init (GPIO3, &GPIO_InitStructure);

GPIO_DeInit(GPIO5);

/*Gonfigure UART0_Tx pin GPIO3.4*/

/*Gonfigure UART1_Tx pin GPIO3.3*/

/*Gonfigure UART2_Tx pin GPIO5.1*/

GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;

GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3 ;

GPIO_Init (GPIO5, &GPIO_InitStructure);

}

/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/

vsilvaamorim
Associate II
Posted on May 17, 2011 at 09:48

Hi

If the board that you are using is the STR912-SK from IAR, the pin corresponding to UART2_TX is P3.0 and not P5.1.

Do not forget to put the jumper in the correct position.

Regards

Vitor