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);
}