UART Driver to receive asynchronous Serial Comms from a Raspberry Pi and parse the results.
SerialComms.cpp
- Committer:
- sk398
- Date:
- 2016-02-20
- Revision:
- 4:85353bd571f2
- Parent:
- 3:b608ee5b9b5d
- Child:
- 5:d497795761a5
- Child:
- 6:74b5ac7719f4
File content as of revision 4:85353bd571f2:
#include "mbed.h" #include "SerialComms.h" SerialComms::SerialComms(PinName tx,PinName rx) { _HLC_Conn = new RawSerial(tx,rx); _HLC_Conn-> baud(SERIAL_BAUD_RATE); _HLC_Conn -> format(8,SerialBase::None,1); _HLC_Conn -> attach(this,&SerialComms::incomingDataISR,RawSerial::RxIrq); incomingDataUpdate = FALSE; } void SerialComms::incomingDataISR() { int a = 0; dataCheck = 0; for(uint8_t charCount=0; charCount<(2*NUM_BYTES_RECEIVING); charCount++) { if((charCount%2) == 1) { receiverBuffer[a] = _HLC_Conn -> getc(); a++; } else { dataCheck += _HLC_Conn -> getc(); } } incomingDataUpdate = TRUE; } int *SerialComms::returnCommData() { if(SerialComms::incomingDataUpdate == TRUE && dataCheck == 15) { SerialComms::incomingDataUpdate = FALSE; return receiverBuffer; } else { int noNewData = -1; int *noNewDataPtr = &noNewData; return noNewDataPtr; } }