Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of StewartPlatform by
usart.cpp
00001 #include "usart.h" 00002 00003 Serial usart(USBTX, USBRX); 00004 00005 char positionTemp[7]; 00006 char position[6]; 00007 bool instructionReceived = false; 00008 00009 //serial interupt service function 00010 //ͨÐÅÐÒé£bpositionTemp = {0xff, ID, angle, 0xEE} 00011 // angle·¶Î§£º[0,180]£¬¶ÔÓ¦[-90, 90] 00012 typedef enum 00013 { 00014 CheckS,CheckW,Checka,Checkb,Checkc,Checkd,Checke,Checkf,CheckSum 00015 }STATE; 00016 00017 void usart_ISR() { 00018 //if (usart.readable()) 00019 { 00020 char data = usart.getc(); 00021 //usart.printf("%d \n", data); 00022 static STATE State = CheckS; 00023 switch(State) 00024 { 00025 case CheckS: 00026 if(data==0XFF) { 00027 State=CheckW; 00028 //usart.printf("receive S\n"); 00029 //instructionReceived = false; 00030 } 00031 else 00032 State=CheckS; 00033 break; 00034 case CheckW: 00035 if(data==0XFE){ 00036 State=Checka; 00037 //usart.printf("receive W\n"); 00038 } 00039 else if(data==0XFF) 00040 State=CheckW; 00041 else 00042 State=CheckS; 00043 break; 00044 case Checka: 00045 positionTemp[0]=data; 00046 State=Checkb; 00047 //usart.printf("receive pos 0 \n"); 00048 break; 00049 case Checkb: 00050 positionTemp[1]=data; 00051 State=Checkc; 00052 //usart.printf("receive pos 1 \n"); 00053 break; 00054 case Checkc: 00055 positionTemp[2]=data; 00056 //usart.printf("receive pos 2 \n"); 00057 State=Checkd; 00058 break; 00059 case Checkd: 00060 positionTemp[3]=data; 00061 //usart.printf("receive pos 3 \n"); 00062 State=Checke; 00063 break; 00064 case Checke: 00065 positionTemp[4]=data; 00066 //usart.printf("receive pos 4 \n"); 00067 State=Checkf; 00068 break; 00069 case Checkf: 00070 positionTemp[5]=data; 00071 //usart.printf("receive pos 5 \n"); 00072 State=CheckSum; 00073 break; 00074 case CheckSum: 00075 positionTemp[6]=data; 00076 //usart.printf("receive sum \n"); 00077 //if(positionTemp[6]==(char)(positionTemp[0]+positionTemp[1]+positionTemp[2]+positionTemp[3]+positionTemp[4]+positionTemp[5])) 00078 { 00079 position[0] = positionTemp[0]; 00080 position[1] = positionTemp[1]; 00081 position[2] = positionTemp[2]; 00082 position[3] = positionTemp[3]; 00083 position[4] = positionTemp[4]; 00084 position[5] = positionTemp[5]; 00085 instructionReceived = true; 00086 } 00087 State=CheckS; 00088 break; 00089 default: 00090 State=CheckS; 00091 //instructionReceived = false; 00092 break; 00093 } 00094 00095 } 00096 } 00097 00098 00099 void usart_init(int baud) { 00100 usart.baud(baud); 00101 usart.attach(&usart_ISR); // attach serial interupt service function 00102 wait(1); 00103 //usart.printf("this is a testing code \n"); 00104 }
Generated on Mon Jul 25 2022 15:47:41 by
