Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ExoController MODSERIAL SDFileSystem_HelloWorld UI-Honka mbed
Fork of Data Management by
main.cpp@6:784990d5180a, 2015-01-14 (annotated)
- Committer:
- perr1940
- Date:
- Wed Jan 14 23:42:14 2015 +0000
- Revision:
- 6:784990d5180a
- Parent:
- 4:46d4917f2464
- Child:
- 7:66a5ec0c5c26
first attempt at implementing SPI interrupt... not successful yet... going to revert and double check some things
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| perr1940 | 0:cbb61997e231 | 1 | #include "mbed.h" | 
| perr1940 | 0:cbb61997e231 | 2 | #include "MODSERIAL.h" | 
| perr1940 | 0:cbb61997e231 | 3 | #include "initDatabed.h" | 
| perr1940 | 0:cbb61997e231 | 4 | #include "UI.h" | 
| perr1940 | 0:cbb61997e231 | 5 | |
| perr1940 | 0:cbb61997e231 | 6 | Timer t_debug; | 
| perr1940 | 6:784990d5180a | 7 | int dataIn[4], dataOut[4], buffer; | 
| perr1940 | 6:784990d5180a | 8 | int counter=0; | 
| perr1940 | 6:784990d5180a | 9 | int ii=0; | 
| perr1940 | 6:784990d5180a | 10 | |
| perr1940 | 6:784990d5180a | 11 | void slaveComm() | 
| perr1940 | 6:784990d5180a | 12 | { | 
| perr1940 | 6:784990d5180a | 13 | __disable_irq(); | 
| perr1940 | 6:784990d5180a | 14 | while(!comm.receive()); | 
| perr1940 | 6:784990d5180a | 15 | buffer=comm.read(); | 
| perr1940 | 6:784990d5180a | 16 | |
| perr1940 | 6:784990d5180a | 17 | if(buffer==0xFE) { //end of message | 
| perr1940 | 6:784990d5180a | 18 | ii=0; | 
| perr1940 | 6:784990d5180a | 19 | dataIn[3]=buffer; | 
| perr1940 | 6:784990d5180a | 20 | comm.reply(5); | 
| perr1940 | 6:784990d5180a | 21 | counter++; | 
| perr1940 | 6:784990d5180a | 22 | if(BMS.read(msg)) { | 
| perr1940 | 6:784990d5180a | 23 | if(msg.id==0x18FF8320) { | 
| perr1940 | 6:784990d5180a | 24 | //pc.printf("%x\r\n",msg.data[0]); | 
| perr1940 | 6:784990d5180a | 25 | } | 
| perr1940 | 6:784990d5180a | 26 | } | 
| perr1940 | 6:784990d5180a | 27 | phone.attachment(); | 
| perr1940 | 6:784990d5180a | 28 | } else if(buffer==0xFF) { //beginning of message | 
| perr1940 | 6:784990d5180a | 29 | ii=1; | 
| perr1940 | 6:784990d5180a | 30 | dataIn[0]=buffer; | 
| perr1940 | 6:784990d5180a | 31 | comm.reply(UI); | 
| perr1940 | 6:784990d5180a | 32 | } else if(ii==1) { | 
| perr1940 | 6:784990d5180a | 33 | ii++; | 
| perr1940 | 6:784990d5180a | 34 | dataIn[1]=buffer; | 
| perr1940 | 6:784990d5180a | 35 | comm.reply(52); | 
| perr1940 | 6:784990d5180a | 36 | } else if(ii==2) { | 
| perr1940 | 6:784990d5180a | 37 | ii++; | 
| perr1940 | 6:784990d5180a | 38 | dataIn[2]=buffer; | 
| perr1940 | 6:784990d5180a | 39 | comm.reply(25); | 
| perr1940 | 6:784990d5180a | 40 | } | 
| perr1940 | 6:784990d5180a | 41 | __enable_irq(); | 
| perr1940 | 6:784990d5180a | 42 | } | 
| perr1940 | 0:cbb61997e231 | 43 | |
| perr1940 | 0:cbb61997e231 | 44 | int main() | 
| perr1940 | 0:cbb61997e231 | 45 | { | 
| perr1940 | 1:78452728a306 | 46 | dataOut[0]=7; | 
| perr1940 | 1:78452728a306 | 47 | dataOut[1]=30; | 
| perr1940 | 2:b87aaf1bc803 | 48 | mainPower=1;//Don't turn on for initial testing | 
| perr1940 | 0:cbb61997e231 | 49 | initializeDatabed(); | 
| perr1940 | 0:cbb61997e231 | 50 | comm.reply(dataOut[0]);//make this the first message | 
| perr1940 | 6:784990d5180a | 51 | ssel.fall(&slaveComm); | 
| perr1940 | 0:cbb61997e231 | 52 | pc.printf("DataBed On!\r\n"); | 
| perr1940 | 0:cbb61997e231 | 53 | while (1) { //Run these functions as fast as possible | 
| perr1940 | 3:ef7e0cbade6d | 54 | if(counter>=10) { | 
| perr1940 | 3:ef7e0cbade6d | 55 | UI=0;//set the UI to 0 unless it's changed in checkUI_Xbee() | 
| perr1940 | 3:ef7e0cbade6d | 56 | readBuffer(); | 
| perr1940 | 3:ef7e0cbade6d | 57 | checkUI_XBee(); //check UI from Xbee | 
| perr1940 | 3:ef7e0cbade6d | 58 | xbeeUI.rxBufferFlush(); | 
| perr1940 | 3:ef7e0cbade6d | 59 | counter=0; | 
| perr1940 | 4:46d4917f2464 | 60 | pc.printf("UI: %d\r\n", UI); | 
| perr1940 | 3:ef7e0cbade6d | 61 | } | 
| perr1940 | 0:cbb61997e231 | 62 | } | 
| perr1940 | 0:cbb61997e231 | 63 | } | 
