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

Committer:
sk398
Date:
Fri Mar 04 05:53:11 2016 +0000
Revision:
6:74b5ac7719f4
Parent:
4:85353bd571f2
Child:
7:34c5934a01f0
Rewritten to accept only a single character over SerialComms and return a single uint8_t. No parsing has been written and is to be handled by higher level code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sk398 6:74b5ac7719f4 1 /* #####################################################################
sk398 6:74b5ac7719f4 2 SerialComms.cpp
sk398 6:74b5ac7719f4 3 ---------------
sk398 6:74b5ac7719f4 4
sk398 6:74b5ac7719f4 5 Surface Ship, Group 5
sk398 6:74b5ac7719f4 6 ---------------------
sk398 6:74b5ac7719f4 7
sk398 6:74b5ac7719f4 8 Written by: Steven Kay
sk398 6:74b5ac7719f4 9
sk398 6:74b5ac7719f4 10 Date: February 2016
sk398 6:74b5ac7719f4 11
sk398 6:74b5ac7719f4 12 Function: This
sk398 6:74b5ac7719f4 13
sk398 6:74b5ac7719f4 14 Version: 1.0
sk398 6:74b5ac7719f4 15
sk398 6:74b5ac7719f4 16 Version History
sk398 6:74b5ac7719f4 17 ---------------
sk398 6:74b5ac7719f4 18
sk398 6:74b5ac7719f4 19 1.1 rgdfgdfgdfggdfgdg
sk398 6:74b5ac7719f4 20
sk398 6:74b5ac7719f4 21 1.0 gdgddfdddgd
sk398 6:74b5ac7719f4 22
sk398 6:74b5ac7719f4 23 ##################################################################### */
sk398 6:74b5ac7719f4 24
sk398 0:8ac1280934b4 25 #include "mbed.h"
sk398 0:8ac1280934b4 26 #include "SerialComms.h"
sk398 0:8ac1280934b4 27
sk398 1:bf3fb80028d8 28 SerialComms::SerialComms(PinName tx,PinName rx)
sk398 0:8ac1280934b4 29 {
sk398 3:b608ee5b9b5d 30 _HLC_Conn = new RawSerial(tx,rx);
sk398 0:8ac1280934b4 31 _HLC_Conn-> baud(SERIAL_BAUD_RATE);
sk398 0:8ac1280934b4 32 _HLC_Conn -> format(8,SerialBase::None,1);
sk398 0:8ac1280934b4 33
sk398 3:b608ee5b9b5d 34 _HLC_Conn -> attach(this,&SerialComms::incomingDataISR,RawSerial::RxIrq);
sk398 0:8ac1280934b4 35
sk398 2:cb74b330b285 36 incomingDataUpdate = FALSE;
sk398 0:8ac1280934b4 37 }
sk398 0:8ac1280934b4 38
sk398 0:8ac1280934b4 39
sk398 2:cb74b330b285 40 void SerialComms::incomingDataISR()
sk398 0:8ac1280934b4 41 {
sk398 6:74b5ac7719f4 42 receiverBuffer = _HLC_Conn -> getc();
sk398 2:cb74b330b285 43 incomingDataUpdate = TRUE;
sk398 0:8ac1280934b4 44 }
sk398 0:8ac1280934b4 45
sk398 6:74b5ac7719f4 46 uint8_t SerialComms::getCommData()
sk398 0:8ac1280934b4 47 {
sk398 6:74b5ac7719f4 48 if(incomingDataUpdate == TRUE)
sk398 0:8ac1280934b4 49 {
sk398 6:74b5ac7719f4 50 incomingDataUpdate = FALSE;
sk398 0:8ac1280934b4 51 return receiverBuffer;
sk398 0:8ac1280934b4 52 }
sk398 0:8ac1280934b4 53 else
sk398 0:8ac1280934b4 54 {
sk398 6:74b5ac7719f4 55 return 0xFF;
sk398 0:8ac1280934b4 56 }
sk398 0:8ac1280934b4 57 }