Raspberry-mbedsoftware

Dependencies:   C12832 mbed

Fork of XBee_read by Alex Louden

Committer:
Perijah
Date:
Thu Mar 24 14:53:25 2016 +0000
Revision:
1:bd4ee148c0c8
Parent:
0:2eaf86314aea
mbed connected to raspberry will be equiped with this software.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alex89 0:2eaf86314aea 1 #include "mbed.h"
Perijah 1:bd4ee148c0c8 2 #include "C12832.h"
alex89 0:2eaf86314aea 3
alex89 0:2eaf86314aea 4 Serial xbee1(p9, p10);
Perijah 1:bd4ee148c0c8 5 DigitalOut rst1(p30);
Perijah 1:bd4ee148c0c8 6 int dataRecieved[10]; //array to store the data that's recieved. Max amount is 10.
alex89 0:2eaf86314aea 7
Perijah 1:bd4ee148c0c8 8 Serial pc(USBTX, USBRX); // tx, rx
Perijah 1:bd4ee148c0c8 9
Perijah 1:bd4ee148c0c8 10
alex89 0:2eaf86314aea 11
Perijah 1:bd4ee148c0c8 12 void lezen() //read the data
Perijah 1:bd4ee148c0c8 13 {
Perijah 1:bd4ee148c0c8 14 int flag = 0;
Perijah 1:bd4ee148c0c8 15 int adress = 0;
Perijah 1:bd4ee148c0c8 16 int size = 0;
Perijah 1:bd4ee148c0c8 17 int checkSum = 0;
Perijah 1:bd4ee148c0c8 18 int checkCompare = 0; //checksum must be equal to checkCompare
Perijah 1:bd4ee148c0c8 19 wait_ms(100);
Perijah 1:bd4ee148c0c8 20 flag = xbee1.getc(); //get flag. If flag is correct the transmission can continue. If not, this methode ends and will be called again in the main method.
Perijah 1:bd4ee148c0c8 21 if(flag == 0x7E) {
Perijah 1:bd4ee148c0c8 22 adress = xbee1.getc(); //get the adress.
Perijah 1:bd4ee148c0c8 23 checkCompare =(checkCompare+ adress); //build checkCompare
Perijah 1:bd4ee148c0c8 24 size = xbee1.getc(); //size of the data that is to be recieved. This will help filling the array dataRecieved.
Perijah 1:bd4ee148c0c8 25 for(int n=0 ; n<size ; n++) {
Perijah 1:bd4ee148c0c8 26 dataRecieved[n] = xbee1.getc();
Perijah 1:bd4ee148c0c8 27 checkCompare +=dataRecieved[n];
Perijah 1:bd4ee148c0c8 28 }
Perijah 1:bd4ee148c0c8 29 checkCompare = checkCompare % 256;
Perijah 1:bd4ee148c0c8 30 checkSum = xbee1.getc();
Perijah 1:bd4ee148c0c8 31
Perijah 1:bd4ee148c0c8 32 if(checkSum==checkCompare) {//if everything is correct it will print on to the pc.
Perijah 1:bd4ee148c0c8 33 pc.printf("%x,%x,%x,%x \n\r",adress,size,dataRecieved[0],checkSum);
Perijah 1:bd4ee148c0c8 34 }
alex89 0:2eaf86314aea 35
Perijah 1:bd4ee148c0c8 36 } else { //if the flag is incorrect, the method ends.
Perijah 1:bd4ee148c0c8 37
Perijah 1:bd4ee148c0c8 38 }
Perijah 1:bd4ee148c0c8 39
Perijah 1:bd4ee148c0c8 40
Perijah 1:bd4ee148c0c8 41 }
Perijah 1:bd4ee148c0c8 42
Perijah 1:bd4ee148c0c8 43
Perijah 1:bd4ee148c0c8 44
Perijah 1:bd4ee148c0c8 45
Perijah 1:bd4ee148c0c8 46
Perijah 1:bd4ee148c0c8 47
Perijah 1:bd4ee148c0c8 48
Perijah 1:bd4ee148c0c8 49 int main()
Perijah 1:bd4ee148c0c8 50 {
Perijah 1:bd4ee148c0c8 51
Perijah 1:bd4ee148c0c8 52 xbee1.baud(57600);
Perijah 1:bd4ee148c0c8 53
alex89 0:2eaf86314aea 54 rst1 = 0; //Set reset pin to 0
Perijah 1:bd4ee148c0c8 55
alex89 0:2eaf86314aea 56 wait_ms(1);
alex89 0:2eaf86314aea 57 rst1 = 1; //Set reset pin to 1
alex89 0:2eaf86314aea 58 wait_ms(1);
alex89 0:2eaf86314aea 59
Perijah 1:bd4ee148c0c8 60
Perijah 1:bd4ee148c0c8 61
alex89 0:2eaf86314aea 62
Perijah 1:bd4ee148c0c8 63 xbee1.attach(lezen); //interrupt triggerd
Perijah 1:bd4ee148c0c8 64
alex89 0:2eaf86314aea 65
alex89 0:2eaf86314aea 66 while (1) {
alex89 0:2eaf86314aea 67
Perijah 1:bd4ee148c0c8 68
alex89 0:2eaf86314aea 69 }
alex89 0:2eaf86314aea 70 }