add uart tests
This commit is contained in:
		
							parent
							
								
									728c4925ea
								
							
						
					
					
						commit
						9f50648334
					
				
					 4 changed files with 398 additions and 0 deletions
				
			
		
							
								
								
									
										45
									
								
								myapps/practice/00a-uart-rx/src/main.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								myapps/practice/00a-uart-rx/src/main.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,45 @@ | |||
| // RXD3/TXD3: PA4/PA5
 | ||||
| 
 | ||||
| 
 | ||||
| #include "CH59x_common.h" | ||||
| #include <stdbool.h> | ||||
| #include <string.h> | ||||
| 
 | ||||
| char b[25]; | ||||
| bool isrx = 0; | ||||
| 
 | ||||
| __INTERRUPT | ||||
| __HIGH_CODE | ||||
| void UART3_IRQHandler() | ||||
| { | ||||
|   GPIOA_InverseBits(GPIO_Pin_8); | ||||
|   UART3_RecvString((uint8_t *)b); | ||||
|   //UART3_SendString((uint8_t *)b, strlen(b));
 | ||||
|   isrx = 1; | ||||
| } | ||||
| 
 | ||||
| int main() | ||||
| { | ||||
|   //char *s = "Hello world\r\n";
 | ||||
|   SetSysClock(CLK_SOURCE_PLL_60MHz); | ||||
|    | ||||
|   GPIOA_SetBits(GPIO_Pin_8);  // LED
 | ||||
|   GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeOut_PP_5mA); | ||||
|    | ||||
|   GPIOA_ModeCfg(GPIO_Pin_4, GPIO_ModeIN_PU);      // RXD3
 | ||||
|   GPIOA_ModeCfg(GPIO_Pin_5, GPIO_ModeOut_PP_5mA); // TXD3
 | ||||
|    | ||||
|   UART3_DefInit(); | ||||
|   UART3_INTCfg(ENABLE, RB_IER_RECV_RDY); | ||||
|   PFIC_EnableIRQ(UART3_IRQn); | ||||
|    | ||||
|   while (1) { | ||||
|      | ||||
|     if (isrx == 1) { | ||||
|       UART3_SendString((uint8_t *)b, strlen(b)); | ||||
|       isrx = 0; | ||||
|     } | ||||
|     mDelaymS(100); | ||||
|   } | ||||
|    | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue