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.
communicate.h
- Committer:
 - DeguNaoto
 - Date:
 - 2015-11-03
 - Revision:
 - 13:57d8e360e9aa
 - Parent:
 - 11:565fca1ead5b
 - Child:
 - 14:943e663694c3
 
File content as of revision 13:57d8e360e9aa:
/***RS485 Communication.***/
#define RS485_TX p13
#define RS485_RX p14
Serial RS485(RS485_TX, RS485_RX);
#define EnablePin p12
DigitalOut Enable(EnablePin);
#define myaddress 8
inline void initializeRS485(){
    RS485.format(8,Serial::Even);
}
inline void sendData(int address, unsigned int data8) {
    unsigned int data;
    if (data8 <= 15) {
        data = 128 | (address << 4) | (data8 & 15);
        RS485.putc(data);
    }
    else if (data8 <= 255 && data8 >= 16) {
        data = (address << 4) | (data8 >> 4);
        RS485.putc(data);
        wait(0.000001);
        data = 128 | (address << 4) | (data8 & 15);
        RS485.putc(data);
    }
}
/***mbed Serial***/
#define MBED_TX p28
#define MBED_RX p27
Serial MbedSerial(MBED_TX,MBED_RX);
unsigned int a2, b, X, Y;
void getMbed(){
    unsigned int info = MbedSerial.getc();
    if (info & 128){  //B1~B4,B5~B11
        for(int s=1,i=1;i<=7;i++){
            if(info & s){
                b = i;
                break;
            }
            if(i==7) b = 0;
            s <<= 1;
        }
    }
    else{             //A2,X,Y
        Y = info & 7;
        info >>= 3;
        X = info & 7;
        info >>= 3;
        a2 = info & 1;
    }
}
inline void initializeMbedSerial(){
    MbedSerial.baud(9600);
    MbedSerial.format(8,Serial::Even);
    MbedSerial.attach(getMbed,Serial::RxIrq);
}