Ah sorry,
I fixed my problem, now USART2 works, but not like it should work...
I want on HyperTerminal the output "ABCDEFG...." but it shows "PNNNNNNNN..."
I think my Bautrate is correct...
What made I wrong???
Here is the code:
(By the way: This programm has its origin from the "toggle_with_circleOS" example-project)
char msg [15];
static int CurrentLedMode = LED_OFF;
static int toggle_count=0;
int i;
int zbs;
void InitUSART()
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* Enable USART2 clocks */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
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);
/* 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 (PA.3) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USART2 configuration ------------------------------------------------------*/
/* USART2 configured as follow:
- BaudRate = 9600 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
- USART Clock disabled
- USART CPOL: Clock is active low
- USART CPHA: Data is captured on the second edge
- USART LastBit: The clock pulse of the last data bit is not output to
the SCLK pin
*/
USART_InitStructure.USART_BaudRate = 9600;
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_Init(USART2, &USART_InitStructure);
/* Enable the USART2 */
USART_Cmd(USART2, ENABLE);
}
u16 uartv;
enum MENU_code Application_Handler(void)
{
zbs = 0;
if (zbs==0)
{
BUTTON_SetMode ( BUTTON_ONOFF);
InitUSART();
zbs = 1;
}
if (zbs == 1)
{
LCD_SetBackLight(0x8000);
UTIL_SetPll(SPEED_VERY_HIGH);
toggle_count++;
USART_SendData(USART2, 'a'+(toggle_count%26));
if (toggle_count >= MAX_TOGGLE_COUNT)
{
BUTTON_SetMode ( BUTTON_ONOFF);
toggle_count=0;
toggle_count++;
CurrentLedMode = (CurrentLedMode == LED_ON) ? LED_OFF : LED_ON;
LED_Set ( LED_GREEN,CurrentLedMode);
LED_Set ( LED_RED,!CurrentLedMode);
BUZZER_SetMode(BUZZER_SHORTBEEP);
LCD_SetBackLightOn();
if ( BUTTON_GetState() == BUTTON_PUSHED )
{
LCD_SetBackLight(0x8000);
LED_Set ( LED_GREEN,LED_ON);
LED_Set ( LED_RED,LED_OFF);
BUZZER_SetMode (BUZZER_OFF) ;
DRAW_Clear();
for( i = 0; i < 100; i++)
{
sprintf(msg,"%d", i);
DRAW_DisplayString( 112, 118, msg, 4); // X, Y, string, length
}
}
}
}
if (zbs == 0)
{
DRAW_Clear();
UTIL_SetPll(SPEED_VERY_LOW);
LCD_SetBackLight(0x1000);
if ( BUTTON_GetState() == BUTTON_PUSHED )
{
LED_Set ( LED_GREEN,LED_ON);
LED_Set ( LED_RED,LED_OFF);
DRAW_SetCharMagniCoeff(1);
LCD_SetBackLightOn();
DRAW_Clear();
UTIL_SetPll(SPEED_VERY_LOW);
LCD_SetBackLight(0x1000);
return MENU_Quit();
}
}
return MENU_CONTINUE;
}
Can anyone help me?
Thanks
Last edited by Mysterio (2009-06-25 11:12:25)