yuki kusakabe
/
R1350N_test
mmbed cli test
main.cpp@0:daa2647a8c40, 2017-11-15 (annotated)
- Committer:
- yuqlid
- Date:
- Wed Nov 15 17:36:34 2017 +0000
- Revision:
- 0:daa2647a8c40
publish;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yuqlid | 0:daa2647a8c40 | 1 | #include "mbed.h" |
yuqlid | 0:daa2647a8c40 | 2 | |
yuqlid | 0:daa2647a8c40 | 3 | DigitalOut myled(LED1); |
yuqlid | 0:daa2647a8c40 | 4 | DigitalOut resetimu(p11); |
yuqlid | 0:daa2647a8c40 | 5 | Serial pc(USBTX, USBRX); // tx, rx |
yuqlid | 0:daa2647a8c40 | 6 | Serial r1350n(p9, p10); // tx, rx |
yuqlid | 0:daa2647a8c40 | 7 | |
yuqlid | 0:daa2647a8c40 | 8 | |
yuqlid | 0:daa2647a8c40 | 9 | char buf[] = "Hello World!"; |
yuqlid | 0:daa2647a8c40 | 10 | int state = 0 , counter = 0; |
yuqlid | 0:daa2647a8c40 | 11 | unsigned char buffer[15]; |
yuqlid | 0:daa2647a8c40 | 12 | |
yuqlid | 0:daa2647a8c40 | 13 | void dev_rx () { |
yuqlid | 0:daa2647a8c40 | 14 | unsigned char data; |
yuqlid | 0:daa2647a8c40 | 15 | data = r1350n.getc(); |
yuqlid | 0:daa2647a8c40 | 16 | switch (state) { |
yuqlid | 0:daa2647a8c40 | 17 | case 0: |
yuqlid | 0:daa2647a8c40 | 18 | if (data == 0xaa) { |
yuqlid | 0:daa2647a8c40 | 19 | state++; |
yuqlid | 0:daa2647a8c40 | 20 | } |
yuqlid | 0:daa2647a8c40 | 21 | break; |
yuqlid | 0:daa2647a8c40 | 22 | case 1: |
yuqlid | 0:daa2647a8c40 | 23 | if (data == 0x00) { |
yuqlid | 0:daa2647a8c40 | 24 | state++; |
yuqlid | 0:daa2647a8c40 | 25 | } |
yuqlid | 0:daa2647a8c40 | 26 | else { |
yuqlid | 0:daa2647a8c40 | 27 | counter = 0; |
yuqlid | 0:daa2647a8c40 | 28 | state = 0; |
yuqlid | 0:daa2647a8c40 | 29 | } |
yuqlid | 0:daa2647a8c40 | 30 | break; |
yuqlid | 0:daa2647a8c40 | 31 | case 2: |
yuqlid | 0:daa2647a8c40 | 32 | buffer[counter++] = data; |
yuqlid | 0:daa2647a8c40 | 33 | if (counter >= 13) { |
yuqlid | 0:daa2647a8c40 | 34 | int sum = 0; |
yuqlid | 0:daa2647a8c40 | 35 | for (int i = 0; i < 11; i++) sum += buffer[i]; |
yuqlid | 0:daa2647a8c40 | 36 | if ((sum & 0xff) == buffer[12]) { |
yuqlid | 0:daa2647a8c40 | 37 | pc.printf("Angle = %4d,AccX = %4d,AccY = %4d,AccZ = %4d\r\n", |
yuqlid | 0:daa2647a8c40 | 38 | (buffer[2] << 8) | buffer[1], |
yuqlid | 0:daa2647a8c40 | 39 | (buffer[6] << 8) | buffer[5], |
yuqlid | 0:daa2647a8c40 | 40 | (buffer[8] << 8) | buffer[7], |
yuqlid | 0:daa2647a8c40 | 41 | (buffer[10] << 8) | buffer[9] |
yuqlid | 0:daa2647a8c40 | 42 | ); |
yuqlid | 0:daa2647a8c40 | 43 | wait(0.01); |
yuqlid | 0:daa2647a8c40 | 44 | //Serial.flush(); |
yuqlid | 0:daa2647a8c40 | 45 | } |
yuqlid | 0:daa2647a8c40 | 46 | state = 0; |
yuqlid | 0:daa2647a8c40 | 47 | counter = 0; |
yuqlid | 0:daa2647a8c40 | 48 | } |
yuqlid | 0:daa2647a8c40 | 49 | break; |
yuqlid | 0:daa2647a8c40 | 50 | } |
yuqlid | 0:daa2647a8c40 | 51 | } |
yuqlid | 0:daa2647a8c40 | 52 | |
yuqlid | 0:daa2647a8c40 | 53 | int main() { |
yuqlid | 0:daa2647a8c40 | 54 | r1350n.baud(115200); |
yuqlid | 0:daa2647a8c40 | 55 | resetimu = 0; |
yuqlid | 0:daa2647a8c40 | 56 | wait(0.1); |
yuqlid | 0:daa2647a8c40 | 57 | resetimu = 1; |
yuqlid | 0:daa2647a8c40 | 58 | wait(2); |
yuqlid | 0:daa2647a8c40 | 59 | //pc.attach(pc_rx, Serial::RxIrq); |
yuqlid | 0:daa2647a8c40 | 60 | pc.printf("Hello World!\n"); |
yuqlid | 0:daa2647a8c40 | 61 | r1350n.attach(dev_rx, Serial::RxIrq); |
yuqlid | 0:daa2647a8c40 | 62 | //pc.attach(pc_tx, Serial::TxIrq); |
yuqlid | 0:daa2647a8c40 | 63 | |
yuqlid | 0:daa2647a8c40 | 64 | while(1){ |
yuqlid | 0:daa2647a8c40 | 65 | myled = 1; |
yuqlid | 0:daa2647a8c40 | 66 | wait(0.2); |
yuqlid | 0:daa2647a8c40 | 67 | myled = 0; |
yuqlid | 0:daa2647a8c40 | 68 | wait(0.2); |
yuqlid | 0:daa2647a8c40 | 69 | } |
yuqlid | 0:daa2647a8c40 | 70 | } |