⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usart0_setup.c

📁 UART developing tutorial module with source codes a褌胁 hints.
💻 C
📖 第 1 页 / 共 2 页
字号:
	//      23       22       21       20       19       18       17       16         
	//
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//	|                    NACK    RXBUFF   TXBUFE  ITERATIO TXEMPTY  TIMEOUT |
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//      15       14       13       12       11       10        9        8         
	//
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//	|  PARE     FRAME    OVRE     ENDTX   ENDRX    RXBRK    TXRDY    RXRDY  |
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//       7          6      5        4        3        2        1        0         
	//  read only, nothing to set up here
	
	
	//		USART0 Receive Holding Register  US_RHR    (read only)
	//
	//	|-----------------------------------------------------------------------|
	//	|                                                                       |
	//	|-----------------------------------------------------------------------|
	//   31                                                                   24      
	//
	//	|-----------------------------------------------------------------------|
	//	|                                                                       |
	//	|-----------------------------------------------------------------------|
	//   23                                                                   16      
	//
	//	|--------|-----------------------------------------------------|--------|
	//	| RXSYNH                                                          RXCHR |
	//	|--------|-----------------------------------------------------|--------|
	//      15    14                                                  9     8         
	//
	//	|-----------------------------------------------------------------------|
	//	|                             RXCHR                                  Y  |
	//	|-----------------------------------------------------------------------|
	//   7                                                                     0      
	//  this is where any incoming character will be
	
	
	//		USART0 Transmit Holding Register  US_THR    (write only)
	//
	//	|-----------------------------------------------------------------------|
	//	|                                                                       |
	//	|-----------------------------------------------------------------------|
	//   31                                                                   24      
	//
	//	|-----------------------------------------------------------------------|
	//	|                                                                       |
	//	|-----------------------------------------------------------------------|
	//   23                                                                   16      
	//
	//	|--------|-----------------------------------------------------|--------|
	//	| TXSYNH                                                          TXCHR |
	//	|--------|-----------------------------------------------------|--------|
	//      15    14                                                  9     8         
	//
	//	|-----------------------------------------------------------------------|
	//	|                             TXCHR                                  Y  |
	//	|-----------------------------------------------------------------------|
	//   7                                                                     0      
	//  this is where we place characters to be transmitted

	
	//		USART0 Baud Rate Generator Register US_BRGR    (read/write)
	//
	//	|-----------------------------------------------------------------------|
	//	|                                                                       |
	//	|-----------------------------------------------------------------------|
	//    31                                                                  24      
	//
	//	|--------------------------------------------|--------------------------|
	//	|                                                     FP                |
	//	|--------------------------------------------|--------------------------|
	//   23                                        19 18                      16      
	//
	//	|-----------------------------------------------------------------------|
	//	|                              CD                                       |
	//	|-----------------------------------------------------------------------|
	//   15                                                                    8      
	//
	//	|-----------------------------------------------------------------------|
	//	|                              CD                                    Y  |
	//	|-----------------------------------------------------------------------|
	//   7                                                                     0      

	pUSART0->US_BRGR = 0x139;		// CD = 0x139  (313 from above calculation)  FP=0 (not used)


	//		USART0 Receiver Time-out Register US_RTOR    (read/write)
	//
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//	|                                                                       |
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//      31       30       29       28       27       26       25       24         
	//
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//	|                                                                       |
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//      23       22       21       20       19       18       17       16         
	//
	//	|-----------------------------------------------------------------------|
	//	|                               TO                                      |
	//	|-----------------------------------------------------------------------|
	//   15                                                                    9      
	//
	//	|-----------------------------------------------------------------------|
	//	|                               TO                                      |
	//	|-----------------------------------------------------------------------|
	//   7                                                                     0      
	//  
	pUSART0->US_RTOR = 0;						// receiver time-out (disabled)
	
	
	//		USART0 transmitter TimeGuard Register US_TTGR    (read/write)
	//
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//	|                                                                       |
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//      31       30       29       28       27       26       25       24         
	//
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//	|                                                                       |
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//      23       22       21       20       19       18       17       16         
	//
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//	|                                                                       |
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//      15       14       13       12       11       10        9       8          
	//
	//	|-----------------------------------------------------------------------|
	//	|                               TG                                      |
	//	|-----------------------------------------------------------------------|
	//   7                                                                     0      
	//  
	pUSART0->US_TTGR = 0;						// transmitter timeguard (disabled)
	
	
	
	//		USART0 FI DI RatioRegister   US_FIDI    (read/write)
	//
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//	|                                                                       |
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//      31       30       29       28       27       26       25       24         
	//
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//	|                                                                       |
	//	|--------|--------|--------|--------|--------|--------|--------|--------|
	//      23       22       21       20       19       18       17       16         
	//
	//	|--------|--------|--------|--------|--------|--------------------------|
	//	|                                                  FI_DI_RATIO          |
	//	|--------|--------|--------|--------|--------|--------------------------|
	//      15       14       13       12       11       10        9       8          
	//
	//	|-----------------------------------------------------------------------|
	//	|                           FI_DI_RATIO                                 |
	//	|-----------------------------------------------------------------------|
	//   7                                                                     0      
	//  not used, nothing to set up here
	
	
	
	//		USART0 Number of Errors Register   US_NER    (read only)
	//
	//	|-----------------------------------------------------------------------|
	//	|                                                                       |
	//	|-----------------------------------------------------------------------|
	//   31                                                                   24      
	//
	//	|-----------------------------------------------------------------------|
	//	|                                                                       |
	//	|-----------------------------------------------------------------------|
	//   23                                                                   16      
	//
	//	|-----------------------------------------------------------------------|
	//	|                                                                       |
	//	|-----------------------------------------------------------------------|
	//   15                                                                    8      
	//
	//	|-----------------------------------------------------------------------|
	//	|                           NB_ERRORS                                   |
	//	|-----------------------------------------------------------------------|
	//   7                                                                     0      
	//  Read-only, nothing to set up here
	
	
	
	//		USART0 IrDA Filter Register  US_IF   (read/write)
	//	|-----------------------------------------------------------------------|
	//	|                                                                       |
	//	|-----------------------------------------------------------------------|
	//   31                                                                   24      
	//
	//	|-----------------------------------------------------------------------|
	//	|                                                                       |
	//	|-----------------------------------------------------------------------|
	//   23                                                                   16      
	//
	//	|-----------------------------------------------------------------------|
	//	|                                                                       |
	//	|-----------------------------------------------------------------------|
	//   15                                                                    8      
	//
	//	|-----------------------------------------------------------------------|
	//	|                           IRDA_FILTER                                 |
	//	|-----------------------------------------------------------------------|
	//   7                                                                     0      
	//  not used, nothing to set up here
	
	// Set up the Advanced Interrupt Controller (AIC)  registers for USART0  
	volatile AT91PS_AIC	pAIC = AT91C_BASE_AIC;			// pointer to AIC data structure
	pAIC->AIC_IDCR = (1<<AT91C_ID_US0);					// Disable USART0 interrupt in AIC Interrupt Disable Command Register			
	pAIC->AIC_SVR[AT91C_ID_US0] =						// Set the USART0 IRQ handler address in AIC Source 
    	(unsigned int)Usart0IrqHandler;        			// Vector Register[6]
	pAIC->AIC_SMR[AT91C_ID_US0] =						// Set the interrupt source type(level-sensitive) and  
   		(AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 0x4 ); 		// priority (4)in AIC Source Mode Register[6]
	pAIC->AIC_IECR = (1<<AT91C_ID_US0); 				// Enable the USART0 interrupt in AIC Interrupt Enable Command Register
	
	// enable the USART0 receiver and transmitter
	pUSART0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
	
	// enable the USART0 receive interrupt
	pUSART0->US_IER = AT91C_US_RXRDY;					// enable RXRDY usart0 receive interrupt
	pUSART0->US_IDR = ~AT91C_US_RXRDY;					// disable all interrupts except RXRDY
	
	// set up buffer pointer and character counter
	pBuffer = &Buffer[0];
	nChars = 0;

	// enable IRQ interrupts 
	enableIRQ();

	// at this point, only the USART0 receive interrupt is armed!
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -