/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / USART

Username:     
Password:     
             

Forum

# 1   2009-09-26 01:37:38 USART

eric_pepo
New member
Registered: 2009-05-03
Posts: 4

USART

Hola a todos escribo en español espero que alguien pueda ayudarme tengo un problema con el USART2 , lo configuro como vi een algunos ejemplos pero a la hora de transmitir me uqeda en alto la salida y no pasa nada, es para conectar un GPS, al Primer1, espero respuestas gracias.
El codigo es el siguiente:

/* Includes ------------------------------------------------------------------*/
#include "circle_api.h"

/* Private defines -----------------------------------------------------------*/

 

// The following should be the minimal CircleOS version needed by your application
#define NEEDEDVERSION "V 3.7"

/* Private functions ---------------------------------------------------------*/
static enum MENU_code MsgVersion(void);

/* Private variables ---------------------------------------------------------*/
USART_InitTypeDef USART_InitStructure;

u8 TxBuffer2[] = "$PFEC,GPint,GGA00,ZDA00,DTM00,VTG00,GSV00*30\n\r";

u8 RxBuffer2[255];
vu8 TxCounter2 = 0x00;
vu8 RxCounter2 = 0x00;

u8 NbrOfDataToTransfer2 = 0x2E;
u8 NbrOfDataToRead2 = 0x08;


/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);


void InitUSART(void)
{
USART_DeInit(USART2);
  /* System Clocks Configuration */
  RCC_Configuration();
       
  /* NVIC configuration */
  NVIC_Configuration();

  /* Configure the GPIO ports */
  GPIO_Configuration();

USART_DeInit(USART2);
/* USART1 and USART2 configuration ------------------------------------------------------*/
/* USART and USART2 configured as follow:
        - BaudRate = 4800 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 = 4800;
  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;


 
  /* Configure USART2 */
  USART_Init(USART2, &USART_InitStructure);

  USART_ClearITPendingBit(USART2, USART_IT_RXNE);
  USART_ClearITPendingBit(USART2, USART_IT_TC);
  USART_ClearITPendingBit(USART2, USART_IT_TXE);

  /* Enable USART2 Receive and Transmit interrupts */
  USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
  USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
  USART_ITConfig(USART2, USART_IT_TC, ENABLE);
  USART_SetPrescaler(0x56);

  /* Enable the USART2 */
  USART_Cmd(USART2, ENABLE);


}
/* Public variables ----------------------------------------------------------*/
const char Application_Name[8+1] = {"TDII"};      // Max 8 characters


/*******************************************************************************
* Function Name  : Application_Ini
* Description    : Initialization function of Circle_App. This function will
*                  be called only once by CircleOS.
* Input          : None
* Return         : MENU_CONTINUE_COMMAND
*******************************************************************************/
enum MENU_code Application_Ini(void)
    {
    // Ensure that the current OS version is recent enough
    if(strcmp(UTIL_GetVersion(), NEEDEDVERSION) < 0)
        {
        return MsgVersion();
        }

InitUSART();
    // TODO: Write your application initialization function here.


    return MENU_CONTINUE_COMMAND;
    }

/*******************************************************************************
* Function Name  : Application_Handler
* Description    : Management of the Circle_App.
*
* Input          : None
* Return         : MENU_CONTINUE
*******************************************************************************/
enum MENU_code Application_Handler(void)
    {



USART_SendData(USART2, 0xAA);

while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET)
    { 
    }
USART_ClearITPendingBit(USART2, USART_IT_TC);           
DRAW_DisplayString(5,50,"ENVIADO",16);



    // TODO: Write your application handling here.


    // This routine will get called repeatedly by CircleOS, until we
    // return MENU_LEAVE

#if 1
    // If the button is pressed, the application is exited
    if(BUTTON_GetState() == BUTTON_PUSHED)
        {
        BUTTON_WaitForRelease();
        return MENU_Quit();
        }
#endif

    return MENU_CONTINUE;   // Returning MENU_LEAVE will quit to CircleOS
    }

/*******************************************************************************
* Function Name  : MsgVersion
* Description    : Display the current CircleOS version and the version needed
*                  exit to main menu after 4 secondes
*
* Input          : None
* Return         : MENU_REFRESH
*******************************************************************************/
static enum MENU_code MsgVersion(void)
{
   int hh,mm,ss,ss2;
   
   DRAW_DisplayString(5,60,"CircleOS",17);
   DRAW_DisplayString(80,60,UTIL_GetVersion(),6);
   DRAW_DisplayString(5,34,NEEDEDVERSION,6);
   DRAW_DisplayString(50,34," required",12);
   
   RTC_GetTime( &hh, &mm, &ss);
   ss = ss + 4;                  // 4 secondes
   ss = ss%60;
   
   do
        {
        RTC_GetTime( &hh, &mm, &ss2 );
        }
   while ( ss2 != ss );           // do while < 4 secondes
   
   DRAW_Clear();
   return MENU_REFRESH;
}


/*******************************************************************************
* Function Name  : RCC_Configuration
* Description    : Configures the different system clocks.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RCC_Configuration(void)
{
    /* RCC system reset(for debug purpose) */
    RCC_DeInit();

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, DISABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

    /* Enable USART2 clocks */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, DISABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, 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;

  //podria ser GPIO_Mode_IPD
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  /* Configure USART2 Rx as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
 
  /* Configure USART2 Tx as alternate function push-pull */

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_Init(GPIOA, &GPIO_InitStructure);




}

/*******************************************************************************
* Function Name  : NVIC_Configuration
* Description    : Configures the nested vectored interrupt controller.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  /* Configure the NVIC Preemption Priority Bits */ 
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
 
  /* Enable the USART2 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

Offline

 

# 2   2009-09-28 10:01:20 USART

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: USART

No escribo espanol... so I will try to help you in English.
With the latest version of RIDE+RLitARM, the peripheral view for the UART will display (dynamically, on the fly) the current baud rate. Most of the issues are related to the baud rate, and I suggest that you first check the baud rate by this way.

Offline

 

# 3   2009-09-28 21:14:14 USART

eric_pepo
New member
Registered: 2009-05-03
Posts: 4

Re: USART

Francis, si logras entender, te cuento, que mi problema esta en que no logro sacar nada por el usart2, lo miro con un osciloscopio, y solo se pone en alto mi salida Tx, por eso subi mi codigo para que vean si tiene algun error, muchas gracias por responder
Eric

Offline

 

# 4   2009-09-29 06:23:15 USART

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: USART

At a first step, you should discard the interrupt management. Now, the rest looks pretty sufficent...  Did you try to debug. Are you stuck in the loop ("while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET)"). If yes, did you check whether the very first character has been transmitted?

Offline

 

# 5   2009-09-29 21:32:31 USART

eric_pepo
New member
Registered: 2009-05-03
Posts: 4

Re: USART

Francis

Mira no queda atascado en ("while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET)"), sale y me muestra en pantalla “ENVIADO”, hoy probé recibir datos por él RX y recibe bien, es la transmisión con la que tengo problema al testearlo con el osciloscopio solo veo que queda en alto la salida (TX).

Eric

Offline

 

# 6   2009-10-01 17:39:02 USART

eric_pepo
New member
Registered: 2009-05-03
Posts: 4

Re: USART

Administrator:

Te cuento que conecte el Kit con la PC, recibo bien los caracteres pero el USART_DR no se vacía luego de leerlo hay que hacer algo para borrarlo, miro todas las configuraciones de los registros y parecen estar bien, cuando escribo manualmente el USART_DR para enviar se vuelve a escribir lo que la PC mando anteriormente, ¿porqué puede ser?, necesito ayuda no puedo enviar nada.
Eric

Offline

 

Board footer