UART Driver to receive asynchronous Serial Comms from a Raspberry Pi and parse the results.
SerialComms.cpp
- Committer:
- sk398
- Date:
- 2016-02-15
- Revision:
- 2:cb74b330b285
- Parent:
- 1:bf3fb80028d8
- Child:
- 3:b608ee5b9b5d
File content as of revision 2:cb74b330b285:
#include "mbed.h" #include "SerialComms.h" SerialComms::SerialComms(PinName tx,PinName rx) { _HLC_Conn = new Serial(tx,rx); _HLC_Conn-> baud(SERIAL_BAUD_RATE); _HLC_Conn -> format(8,SerialBase::None,1); _HLC_Conn -> attach(this,&SerialComms::incomingDataISR,Serial::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; // for(int c = 0; c < 4; c++) // { // printf("recieved: %d\r\n",receiverBuffer[c]); // } } int *SerialComms::returnMotorSpeeds() { if(SerialComms::incomingDataUpdate == TRUE && dataCheck == 10) { SerialComms::incomingDataUpdate = FALSE; return receiverBuffer; } else { int noNewData = -1; int *noNewDataPtr = &noNewData; return noNewDataPtr; } }