请教大家一下:我的UART的程序是参考ST网站上的写的,应该没有什么问题吧?但是我的超级终端上面什么也收不到,我用的是UART2,请问还要有其他要设置的地方么?我把我的程序贴上: #define UART0_Rx_Pin (0x0001<<8) /* TQFP 64: pin N?63 , TQFP 144 pin N?143 */ #define UART0_Tx_Pin (0x0001<<9) /* TQFP 64: pin N?64 , TQFP 144 pin N?144 */
#define UART1_Rx_Pin (0x0001<<10) /* TQFP 64: pin N?1 , TQFP 144 pin N?1 */ #define UART1_Tx_Pin (0x0001<<11) /* TQFP 64: pin N?2 , TQFP 144 pin N?3 */
#define UART2_Rx_Pin (0x0001<<13) /* TQFP 64: pin N?5 , TQFP 144 pin N?9 */ #define UART2_Tx_Pin (0x0001<<14) /* TQFP 64: pin N?6 , TQFP 144 pin N?10 */
#define UART3_Rx_Pin (0x0001<<1) /* TQFP 64: pin N?52 , TQFP 144 pin N?123 */ #define UART3_Tx_Pin (0x0001<<0) /* TQFP 64: pin N?53 , TQFP 144 pin N?124 */
//#define Use_UART0 //#define Use_UART1 #define Use_UART2 //#define Use_UART3
#ifdef Use_UART0 #define UARTX UART0 #define UARTX_Rx_Pin UART0_Rx_Pin #define UARTX_Tx_Pin UART0_Tx_Pin #define UARTX_Periph UART0_Periph #endif /* Use_UART0 */
#ifdef Use_UART1 #define UARTX UART1 #define UARTX_Rx_Pin UART1_Rx_Pin #define UARTX_Tx_Pin UART1_Tx_Pin #define UARTX_Periph UART1_Periph #endif /* Use_UART1 */
#ifdef Use_UART2 #define UARTX UART2 #define UARTX_Rx_Pin UART2_Rx_Pin #define UARTX_Tx_Pin UART2_Tx_Pin #define UARTX_Periph UART2_Periph #endif /* Use_UARTX */
#ifdef Use_UART3 #define UARTX UART3 #define UARTX_Rx_Pin UART3_Rx_Pin #define UARTX_Tx_Pin UART3_Tx_Pin #define UARTX_Periph UART3_Periph #endif /* Use_UART3 */
unsigned char hex[12]="Hello world", txt[12],Device; unsigned int temp; int Res;
u16 i; u16 UARTStatus; u8 bBuffer[4]={'S','T','R','7'};
int main(void) {
#ifdef DEBUG debug(); #endif /* DEBUG */ RCCU_Div2Config(DISABLE); // Enable DIV2 RCCU_MCLKConfig(RCCU_DEFAULT); // Configure MCLK = RCLK RCCU_FCLKConfig(RCCU_DEFAULT); // Configure FCLK = RCLK RCCU_PCLKConfig(RCCU_DEFAULT); // Configure PCLK = RCLK RCCU_PLL1Config(RCCU_PLL1_Mul_12, RCCU_Div_2) ; // Configure the PLL1 ( * 12 , / 2 ) while(RCCU_FlagStatus(RCCU_PLL1_LOCK) == RESET);// Wait PLL to lock RCCU_RCLKSourceConfig(RCCU_PLL1_Output) ; // Select PLL1_Output as RCLK clock ConfigGPIO(); GPIO_Config(GPIO0, UARTX_Rx_Pin, GPIO_IN_TRI_CMOS); GPIO_Config(GPIO0, UARTX_Tx_Pin, GPIO_AF_PP); // UART_Init(UARTX); UART_OnOffConfig(UARTX, ENABLE); UART_FifoConfig(UARTX, ENABLE); UART_FifoReset(UARTX, UART_RxFIFO); // Reset the UART_RxFIFO UART_FifoReset(UARTX, UART_TxFIFO); // Reset the UART_TxFIFO// Disable FIFOs UART_LoopBackConfig(UARTX, DISABLE); UART_Config(UARTX, 9600, UART_NO_PARITY, UART_1_StopBits, UARTM_8D); // UART_RxConfig(UARTX, ENABLE); // UART_ItConfig(UARTX, UART_RxBufFull, ENABLE); while(!((UART_FlagStatus(UARTX)) & UART_TxEmpty)); GPIO_BitWrite(GPIO2, 12, 0x01); while(1) { for(i=0;i<4;i++) { UART_ByteSend(UARTX, (u8 *)&bBuffer); /* wait until the data transmission is finished */ } while(!((UART_FlagStatus(UARTX)) & UART_TxEmpty)); GPIO_BitWrite(GPIO2, 13, 0x01); // for(i=0;i<4;i++) // { /* wait until data is received */ // while(!(UART_FlagStatus(UARTX) & UART_RxBufFull)); // GPIO_BitWrite(GPIO2, 13, 0x01); /* Get the received data, set the guard time to 0xFF */ // UARTStatus = UART_ByteReceive(UARTX, (u8 *)&bBuffer, 0xFF); // } }
}
|
|