STM32足回りプログラム
Dependencies: mbed ros_lib_kinetic
Diff: library/ScrpSlave.cpp
- Revision:
- 1:7b0db5ea0ab7
- Parent:
- 0:a202e1bc38a1
--- a/library/ScrpSlave.cpp Mon Jun 17 13:41:24 2019 +0000 +++ b/library/ScrpSlave.cpp Tue Jul 09 07:47:43 2019 +0000 @@ -84,13 +84,14 @@ uint8_t tx_dataH = tx_data >> 8; uint8_t tx_sum = id + cmd + tx_dataL + tx_dataH; - const uint8_t data[] = {DMY, STX, id, cmd, tx_dataL, tx_dataH, tx_sum}; + const uint8_t data[] = {DMY, STX, id, cmd, tx_dataL, tx_dataH, tx_sum, DMY}; if(!serial[port]->writeable())return -1; - if(mode%2 == 1 && id == 0)rede->write(1); - for(int i = 0;i<7;i++){ + if(mode%2 == 1 && port == 0)rede->write(1); + for(int i = 0;i<8;i++){ serial[port]->putc(data[i]); } - if(mode%2 == 1 && id == 0)rede->write(0); + while(!serial[port]->writeable()); + if(mode%2 == 1 && port == 0)rede->write(0); int i = 0; bool received = false; @@ -168,12 +169,13 @@ uint8_t tx_dataH = tx_data >> 8; uint8_t tx_sum = my_id + rx_cmd + tx_dataL + tx_dataH; - const uint8_t data[] = {DMY, STX, my_id, rx_cmd, tx_dataL, tx_dataH, tx_sum}; + const uint8_t data[] = {DMY, STX, my_id, rx_cmd, tx_dataL, tx_dataH, tx_sum, DMY}; if(!serial[port]->writeable())return; if(mode%2 == 1 && port == 0)rede->write(1); - for(int i = 0;i<7;i++){ + for(int i = 0;i<8;i++){ serial[port]->putc(data[i]); } + while(!serial[port]->writeable()); if(mode%2 == 1 && port == 0)rede->write(0); return; }