Manual comms between K64F and XBee module.

Dependencies:   mbed

Committer:
georgemm101
Date:
Sat Aug 09 16:41:34 2014 +0000
Revision:
0:75cdb85ebc0e
Initial Version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
georgemm101 0:75cdb85ebc0e 1 #include "mbed.h"
georgemm101 0:75cdb85ebc0e 2 DigitalOut Redled(LED_RED);
georgemm101 0:75cdb85ebc0e 3 DigitalOut Greenled(LED_GREEN);
georgemm101 0:75cdb85ebc0e 4 DigitalOut Blueled(LED_BLUE);
georgemm101 0:75cdb85ebc0e 5
georgemm101 0:75cdb85ebc0e 6 Serial pc(USBTX, USBRX);
georgemm101 0:75cdb85ebc0e 7 Serial XbeeSerial(PTC17, PTC16); //TX,RX
georgemm101 0:75cdb85ebc0e 8
georgemm101 0:75cdb85ebc0e 9 void Setup()
georgemm101 0:75cdb85ebc0e 10 {
georgemm101 0:75cdb85ebc0e 11 pc.baud(9600);
georgemm101 0:75cdb85ebc0e 12 XbeeSerial.baud(9600);
georgemm101 0:75cdb85ebc0e 13 Redled = 1.0; // off
georgemm101 0:75cdb85ebc0e 14 Greenled = 1.0;
georgemm101 0:75cdb85ebc0e 15 Blueled = 1.0;
georgemm101 0:75cdb85ebc0e 16 }
georgemm101 0:75cdb85ebc0e 17
georgemm101 0:75cdb85ebc0e 18 void Header()
georgemm101 0:75cdb85ebc0e 19 {
georgemm101 0:75cdb85ebc0e 20 pc.printf("XBserial_comms_Manual V1.0\n");
georgemm101 0:75cdb85ebc0e 21 pc.printf("Any character typed from the pc will\n");
georgemm101 0:75cdb85ebc0e 22 pc.printf("be sent to the remote XBee \n");
georgemm101 0:75cdb85ebc0e 23 pc.printf("+++ to enter command mode (no CR) \n");
georgemm101 0:75cdb85ebc0e 24 pc.printf("AT should get OK in response \n");
georgemm101 0:75cdb85ebc0e 25 pc.printf("ATAI = 0 Associated\n");
georgemm101 0:75cdb85ebc0e 26 pc.printf("ATSH = Serial No H byte\n");
georgemm101 0:75cdb85ebc0e 27 pc.printf("ATSL = Serial No L byte\n");
georgemm101 0:75cdb85ebc0e 28 pc.printf("ATHV = Hardware version\n");
georgemm101 0:75cdb85ebc0e 29 pc.printf("ATVR = Firmware version\n");
georgemm101 0:75cdb85ebc0e 30 pc.printf("ATTP = Temperature\n");
georgemm101 0:75cdb85ebc0e 31 pc.printf("ATDH = Destination Address\n");
georgemm101 0:75cdb85ebc0e 32 wait(1);
georgemm101 0:75cdb85ebc0e 33 }
georgemm101 0:75cdb85ebc0e 34 // -------- end Header -----------
georgemm101 0:75cdb85ebc0e 35
georgemm101 0:75cdb85ebc0e 36 void Blink(int clr)
georgemm101 0:75cdb85ebc0e 37 // introduces a delay !
georgemm101 0:75cdb85ebc0e 38 {
georgemm101 0:75cdb85ebc0e 39 if (clr == 'R') {
georgemm101 0:75cdb85ebc0e 40 //DigitalOut Redled(LED_RED, 1);
georgemm101 0:75cdb85ebc0e 41 Redled = 0; // on
georgemm101 0:75cdb85ebc0e 42 wait(0.001);
georgemm101 0:75cdb85ebc0e 43 Redled = 1.0; // off
georgemm101 0:75cdb85ebc0e 44 }
georgemm101 0:75cdb85ebc0e 45 if (clr == 'G') {
georgemm101 0:75cdb85ebc0e 46 //DigitalOut Greenled(LED_GREEN, 1);
georgemm101 0:75cdb85ebc0e 47 Greenled = 0; // on
georgemm101 0:75cdb85ebc0e 48 wait(0.001);
georgemm101 0:75cdb85ebc0e 49 Greenled = 1.0; // off
georgemm101 0:75cdb85ebc0e 50 }
georgemm101 0:75cdb85ebc0e 51 if (clr == 'B') {
georgemm101 0:75cdb85ebc0e 52 //DigitalOut Blueled(LED_Blue, 1);
georgemm101 0:75cdb85ebc0e 53 Blueled = 0; // on
georgemm101 0:75cdb85ebc0e 54 wait(0.001);
georgemm101 0:75cdb85ebc0e 55 Blueled = 1.0; // off
georgemm101 0:75cdb85ebc0e 56 }
georgemm101 0:75cdb85ebc0e 57 }
georgemm101 0:75cdb85ebc0e 58 // -------- end Blink -----------
georgemm101 0:75cdb85ebc0e 59
georgemm101 0:75cdb85ebc0e 60 void XbeeRelay()
georgemm101 0:75cdb85ebc0e 61 {
georgemm101 0:75cdb85ebc0e 62 if (XbeeSerial.readable()) {
georgemm101 0:75cdb85ebc0e 63 pc.putc(XbeeSerial.getc()); //get data from Xbee and send to pc(USB)
georgemm101 0:75cdb85ebc0e 64 Blink('R'); // Blink introduces a delay of 1ms
georgemm101 0:75cdb85ebc0e 65 }
georgemm101 0:75cdb85ebc0e 66 if(pc.readable()) {
georgemm101 0:75cdb85ebc0e 67 XbeeSerial.putc(pc.getc()); //get data from pc(USB) and send to Xbee
georgemm101 0:75cdb85ebc0e 68 Blink('G');
georgemm101 0:75cdb85ebc0e 69 }
georgemm101 0:75cdb85ebc0e 70 }
georgemm101 0:75cdb85ebc0e 71 // don't forget to set the destination addresses on both xbees
georgemm101 0:75cdb85ebc0e 72 // -------- end XbeeRelay -----------
georgemm101 0:75cdb85ebc0e 73
georgemm101 0:75cdb85ebc0e 74
georgemm101 0:75cdb85ebc0e 75 int main()
georgemm101 0:75cdb85ebc0e 76 {
georgemm101 0:75cdb85ebc0e 77 Setup();
georgemm101 0:75cdb85ebc0e 78
georgemm101 0:75cdb85ebc0e 79 Header();
georgemm101 0:75cdb85ebc0e 80
georgemm101 0:75cdb85ebc0e 81 Blink('R');
georgemm101 0:75cdb85ebc0e 82 wait(1);
georgemm101 0:75cdb85ebc0e 83 Blink('G');
georgemm101 0:75cdb85ebc0e 84 wait(1);
georgemm101 0:75cdb85ebc0e 85 Blink('B');
georgemm101 0:75cdb85ebc0e 86
georgemm101 0:75cdb85ebc0e 87 while (true) {
georgemm101 0:75cdb85ebc0e 88 XbeeRelay();
georgemm101 0:75cdb85ebc0e 89 }
georgemm101 0:75cdb85ebc0e 90 }