![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Receive data and clock for data communications example
Diff: main.cpp
- Revision:
- 15:0f8871dd3324
- Parent:
- 14:5a55a41dc118
- Child:
- 16:ca9f769ff024
--- a/main.cpp Tue Apr 14 04:11:25 2015 +0000 +++ b/main.cpp Thu Apr 16 02:45:37 2015 +0000 @@ -22,6 +22,7 @@ unsigned char temp, data[MAX], crc_calc; //temp byte storage, storage array, transmitted crc value unsigned char preamble, address, i, j, k; //increment variables unsigned char data_flag, rflag, d_flag, done, temp_data; //data flags +int crc_passed = 0; //crc flag int temp_crc = 0; //stores values for crc check. //funtion prototypes @@ -44,6 +45,7 @@ i = 0; d_flag = 0; done = 0; + crc_passed=0; //clear lcd screen, print current build message lcd.cls(); @@ -98,6 +100,7 @@ crc_calc = read_byte(NIBBLE); if(check_crc(temp_crc, crc_calc)) { + crc_passed=1; lcd.cls(); lcd.locate(0,3); lcd.printf("Data passes CRC verification"); @@ -117,12 +120,17 @@ //stop and reset the timer t.stop(); t.reset(); + if(crc_passed){//if crc passes display data, send ACK //clear debugging messages - and reset lcd to original position before printing data. + //send ACK lcd.cls(); lcd.locate(0,3); lcd.printf("Received: "); for(k=0; k<=i; k++) lcd.printf("%c", data[k]); + }else{//if crc fails, send NOACK + + } } void check_byte(int value) @@ -190,7 +198,7 @@ { rflag = 1; lcd.printf("Multicast received"); - } + }//can add if Network==0 and address==x send to x in every network else printf("Wrong address received");