avec thread

Dependencies:   mbed

Fork of T2_STM32 by Atechsys

Committer:
ketingue
Date:
Sun Jan 14 17:39:09 2018 +0000
Revision:
4:b01a3ce6ef01
Parent:
2:ab0ccf9bb38c
test_pwm_01;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Tioneb 2:ab0ccf9bb38c 1 #ifndef Serial_h
Tioneb 2:ab0ccf9bb38c 2 #define Serial_h
Tioneb 2:ab0ccf9bb38c 3
Tioneb 2:ab0ccf9bb38c 4 void FlushIncomingSerial(){
Tioneb 2:ab0ccf9bb38c 5 ///////////////////////////////// Vider le buffer de réception ////////////////////////
Tioneb 2:ab0ccf9bb38c 6 while(Serial.available())
Tioneb 2:ab0ccf9bb38c 7 Serial.read();
Tioneb 2:ab0ccf9bb38c 8 }
Tioneb 2:ab0ccf9bb38c 9
Tioneb 2:ab0ccf9bb38c 10 void ReadSerial(){
Tioneb 2:ab0ccf9bb38c 11 ///////////////////////////////// Attente et lecture de trame //////////////////////////////
Tioneb 2:ab0ccf9bb38c 12 CurrentMillis = millis();
Tioneb 2:ab0ccf9bb38c 13 while (!Serial.available())
Tioneb 2:ab0ccf9bb38c 14 {
Tioneb 2:ab0ccf9bb38c 15 if((millis() - CurrentMillis) >= 500){
Tioneb 2:ab0ccf9bb38c 16 break;
Tioneb 2:ab0ccf9bb38c 17 }
Tioneb 2:ab0ccf9bb38c 18 }
Tioneb 2:ab0ccf9bb38c 19
Tioneb 2:ab0ccf9bb38c 20 ActualAdress = 0;
Tioneb 2:ab0ccf9bb38c 21 if (Serial.read() == Start_Command)
Tioneb 2:ab0ccf9bb38c 22 {
Tioneb 2:ab0ccf9bb38c 23 for(;;)
Tioneb 2:ab0ccf9bb38c 24 {
Tioneb 2:ab0ccf9bb38c 25 RxdBuffer[ActualAdress] = Serial.read();
Tioneb 2:ab0ccf9bb38c 26 if (RxdBuffer[ActualAdress] == 255)
Tioneb 2:ab0ccf9bb38c 27 ActualAdress--;
Tioneb 2:ab0ccf9bb38c 28 if (RxdBuffer[ActualAdress] == Start_Command)
Tioneb 2:ab0ccf9bb38c 29 break;
Tioneb 2:ab0ccf9bb38c 30 else
Tioneb 2:ab0ccf9bb38c 31 {
Tioneb 2:ab0ccf9bb38c 32 ActualAdress++;
Tioneb 2:ab0ccf9bb38c 33 }
Tioneb 2:ab0ccf9bb38c 34 }
Tioneb 2:ab0ccf9bb38c 35 }
Tioneb 2:ab0ccf9bb38c 36 }
Tioneb 2:ab0ccf9bb38c 37
Tioneb 2:ab0ccf9bb38c 38
Tioneb 2:ab0ccf9bb38c 39 void SendSerial(){
Tioneb 2:ab0ccf9bb38c 40 ///////////////////////////////// Envoi de trame dans les 2 ports série //////////////////////////////
Tioneb 2:ab0ccf9bb38c 41 Serial.print(Start_Command);
Tioneb 2:ab0ccf9bb38c 42 Serial.print(Address);
Tioneb 2:ab0ccf9bb38c 43 Serial.print(Command);
Tioneb 2:ab0ccf9bb38c 44 Serial.println(State);
Tioneb 2:ab0ccf9bb38c 45 }
Tioneb 2:ab0ccf9bb38c 46
Tioneb 2:ab0ccf9bb38c 47 #endif