UART Driver to receive asynchronous Serial Comms from a Raspberry Pi and parse the results.

Committer:
sk398
Date:
Mon Feb 15 20:10:55 2016 +0000
Revision:
3:b608ee5b9b5d
Parent:
2:cb74b330b285
Child:
4:85353bd571f2
converted to RawSerial data type for RTOS purposes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sk398 0:8ac1280934b4 1 #include "mbed.h"
sk398 0:8ac1280934b4 2 #include "SerialComms.h"
sk398 0:8ac1280934b4 3
sk398 1:bf3fb80028d8 4 SerialComms::SerialComms(PinName tx,PinName rx)
sk398 0:8ac1280934b4 5 {
sk398 3:b608ee5b9b5d 6 _HLC_Conn = new RawSerial(tx,rx);
sk398 0:8ac1280934b4 7 _HLC_Conn-> baud(SERIAL_BAUD_RATE);
sk398 0:8ac1280934b4 8 _HLC_Conn -> format(8,SerialBase::None,1);
sk398 0:8ac1280934b4 9
sk398 3:b608ee5b9b5d 10 _HLC_Conn -> attach(this,&SerialComms::incomingDataISR,RawSerial::RxIrq);
sk398 0:8ac1280934b4 11
sk398 2:cb74b330b285 12 incomingDataUpdate = FALSE;
sk398 0:8ac1280934b4 13 }
sk398 0:8ac1280934b4 14
sk398 0:8ac1280934b4 15
sk398 2:cb74b330b285 16 void SerialComms::incomingDataISR()
sk398 0:8ac1280934b4 17 {
sk398 0:8ac1280934b4 18 int a = 0;
sk398 2:cb74b330b285 19 dataCheck = 0;
sk398 0:8ac1280934b4 20 for(uint8_t charCount=0; charCount<(2*NUM_BYTES_RECEIVING); charCount++)
sk398 0:8ac1280934b4 21 {
sk398 0:8ac1280934b4 22 if((charCount%2) == 1)
sk398 0:8ac1280934b4 23 {
sk398 0:8ac1280934b4 24 receiverBuffer[a] = _HLC_Conn -> getc();
sk398 0:8ac1280934b4 25 a++;
sk398 0:8ac1280934b4 26 }
sk398 0:8ac1280934b4 27 else
sk398 0:8ac1280934b4 28 {
sk398 2:cb74b330b285 29 dataCheck += _HLC_Conn -> getc();
sk398 0:8ac1280934b4 30 }
sk398 0:8ac1280934b4 31 }
sk398 2:cb74b330b285 32 incomingDataUpdate = TRUE;
sk398 0:8ac1280934b4 33 }
sk398 0:8ac1280934b4 34
sk398 0:8ac1280934b4 35 int *SerialComms::returnMotorSpeeds()
sk398 0:8ac1280934b4 36 {
sk398 2:cb74b330b285 37 if(SerialComms::incomingDataUpdate == TRUE && dataCheck == 10)
sk398 0:8ac1280934b4 38 {
sk398 2:cb74b330b285 39 SerialComms::incomingDataUpdate = FALSE;
sk398 0:8ac1280934b4 40 return receiverBuffer;
sk398 0:8ac1280934b4 41 }
sk398 0:8ac1280934b4 42 else
sk398 0:8ac1280934b4 43 {
sk398 0:8ac1280934b4 44 int noNewData = -1;
sk398 0:8ac1280934b4 45 int *noNewDataPtr = &noNewData;
sk398 0:8ac1280934b4 46 return noNewDataPtr;
sk398 0:8ac1280934b4 47 }
sk398 0:8ac1280934b4 48 }