Hej,
to start with usart, you don't have to use interrupt which may casue extra problems for you. you can just test the send and receive funtions of the usart. to do this, the simple way is to connect your RX and TX together(i mean the same usart's RX and TX), then you just send some data, and if the usart works correctly, you can see the received value in data register in the debug mode.
for the baut rate, in this test, maybe it is not so critical. but you shouldn't just believe in the data shown in usart peripheral, because of the library(i use the old lib, i'm not sure how about it now, to get 9600, i set the value to 6400, instead of 9600, because of the crystal used in Primer2 is 12MHz instead of 8MHz, you should check your kit)
following are the codes which i hope can help you:
USART_InitTypeDef USART2_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* 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_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* enable UART peripheral by activating clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* USART2 configuration ------------------------------------------------------*/
USART2_InitStructure.USART_BaudRate = 6400; //BaudRate = 9600 baud
USART2_InitStructure.USART_WordLength = USART_WordLength_8b; //Word Length = 8 Bits
USART2_InitStructure.USART_StopBits = USART_StopBits_1; //Two Stop Bit
USART2_InitStructure.USART_Parity = USART_Parity_No ; //No parity
USART2_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //Hardware flow control disabled (RTS and CTS signals)
USART2_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Receive and transmit enabled
USART_Init(USART2,&USART2_InitStructure);
// USART2->BRR = 0x753;
USART_Cmd(USART2, ENABLE);
//ini done, start to send data
USART_SendData(USART2,0x11);
Last edited by xuwa0800 (2010-12-20 15:44:22)