Hello,
I want to comunicate 2 primer2, so I connect the pins 16 and 18 of the primers.
I have read some prjects to help me. I new using primer and Im learning to use it. but the program I did, doesn`t work yet. the status of the flags in the programs, always remains in RESET, nothing is arriving to the primer receptor.
Could someone help me to find out why it doesnt work yet.
thanks.
/********************** (C) COPYRIGHT 2007-2009 RAISONANCE ********************
* File Name : Application.c
* Author :
* Date First Issued :
* Description : Circle_App CircleOS application template.
* Revision :
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "circle_api.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.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);
enum UART_MODE {TX,INIT,RX}; // Application mode enum
enum UART_MODE mode; //*Application mode : Transmiter or Receiver*/
//u8 OldPLLFreq; // Old clock frequency
u8 RxData,TxData,status,status2; // Vars holding received or transmited char
char data;
int i;
/* Public variables ----------------------------------------------------------*/
const char Application_Name[8+1] = {"appmenu"}; // Max 8 characters
const char msg[3][64] = { // Messages to display
"",
"Send a char",
"Receive a char"
};
int currentMsgIdx;
/* Private function prototypes -----------------------------------------------*/
void GPIO_Configuration(void);
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART2 Tx (PA.2) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART2 Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/*******************************************************************************
* 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();
}
// TODO: Write your application initialization function here.
// Save old clock frequency
/*OldPLLFreq = UTIL_GetPll();*/
//Enable clock
RCC_APB1PeriphClockCmd(
RCC_APB1Periph_USART2, ENABLE);
/* Enable GPIOA clock */
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE );
void GPIO_Configuration(void);
/* The following example illustrates how to initialize a
USART_InitTypeDef structure */
USART_InitTypeDef USART_InitStructure;
USART_StructInit(&USART_InitStructure);
//USART_DeInit(USART2);
USART_Cmd(USART2, ENABLE);
USART_SetPrescaler(USART2, 0x1);
/* Enables the USART1 transmit interrupt */
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
/* Enables the USART1 Receive interrupt */
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
// Init App
currentMsgIdx = 0;
mode = INIT;
TxData = 'a';
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)
{
// TODO: Write your application handling here.
if(JOYSTICK_GetState()==JOYSTICK_RIGHT)
{
JOYSTICK_WaitForRelease();
ClearScreen();
currentMsgIdx = 2;
mode++;
}
if(JOYSTICK_GetState()==JOYSTICK_LEFT)
{
JOYSTICK_WaitForRelease();
ClearScreen();
currentMsgIdx = 1;
mode--;
}
switch(mode)
{
// Transmission mode
case TX:
// Saving next char to be sended
data = ((char)TxData)+1;
// If the button is pressed...
if(BUTTON_GetState() == BUTTON_PUSHED)
{
BUTTON_WaitForRelease();
// ... we send a char
USART_SendData(USART2, TxData);
if (TxData == 'z')
TxData = 'a';
else
//for(i=1;i<10;i++){
TxData = ((char)TxData)+1;
//}
status=USART_GetFlagStatus(USART2, USART_FLAG_TXE);
if(status == SET){
DRAW_DisplayString( 5, 56, "data: ", 6);
DRAW_SetCursorPos(64, 56);
DRAW_Putc(TxData);
}else if(status==RESET){
DRAW_DisplayString( 5, 36, "data: ", 6);
DRAW_SetCursorPos(64, 36);
DRAW_Putc(TxData);
}
}
// Display the next char
DRAW_DisplayString( 5, 76, "data: ", 6);
DRAW_SetCursorPos(64, 76);
DRAW_Putc(TxData);
break;
// Reception mode
case RX:
// If something has been received...
status2=USART_GetFlagStatus(USART2, USART_FLAG_RXNE);
if(status2==SET){
// ... we get it...
RxData = USART_ReceiveData(USART2);
// ... and display it !
DRAW_DisplayString( 5, 76, "data: ", 6);
DRAW_SetCursorPos(64, 76);
DRAW_Putc(RxData);
}else if(status2==RESET){
RxData = USART_ReceiveData(USART2);
// ... and display it !
DRAW_DisplayString( 5, 36, "data: ", 6);
DRAW_SetCursorPos(64, 36);
DRAW_Putc(RxData);
}
break;
// Main menu
default:
currentMsgIdx = 0;
DRAW_DisplayString( 29, 74, "Receive-->", 10);
DRAW_DisplayString( 25, 50, "<--Transmit", 11);
DRAW_DisplayString( 19, 29, "Press button", 13);
DRAW_DisplayString( 40, 5, "to exit", 7);
// 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();
BUTTON_SetMode(BUTTON_ONOFF_FORMAIN);
return MENU_Quit();
}
#endif
break;
DRAW_DisplayString( 40, 110, Application_Name, sizeof(Application_Name));
DRAW_DisplayString( 5, 90, msg[currentMsgIdx], sizeof(msg[currentMsgIdx]));
}
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;
}
void ClearScreen()
{
LCD_FillRect ( 0,0,127,89, RGB_WHITE );
}