A library for the AX-12+ servo using external ICs instead of the SerialHalf-Duplex class
A library based on the AX-12+ library but using external hardware to convert from full to half duplex as suggested in the AX-12 datasheet. The buffers and NOT gate need to connected as shown below.
Don't forget the pull-up resistor!
Diff: AX12.cpp
- Revision:
- 2:3000c6778d1c
- Parent:
- 1:1dd9cd18975d
diff -r 1dd9cd18975d -r 3000c6778d1c AX12.cpp --- a/AX12.cpp Sun Aug 07 13:06:04 2011 +0000 +++ b/AX12.cpp Sun Oct 07 08:52:25 2012 +0000 @@ -3,10 +3,10 @@ #include "AX12.h" #include "mbed.h" -AX12::AX12(PinName tx, PinName rx, PinName dir, int ID) - : _ax12(tx,rx), _dir(dir) { +AX12::AX12(Serial& bus, PinName dir, int ID) + : _bus(bus), _dir(dir) { - _ax12.baud(1000000); + _bus.baud(1000000); _ID = ID; _dir = TRANSMIT; } @@ -63,7 +63,7 @@ // And send the packet to th AX-12+ Servo... _dir = TRANSMIT; // Switch the hardware to transmit... for (int i = 0; i < 8 ; i++) { // Transmit the packet in one burst with no pausing - _ax12.putc(TxBuf[i]); + _bus.putc(TxBuf[i]); } wait (0.00004); // Wait for data to transmit _dir = RECEIVE; // Switch the hardware back to receive... @@ -74,7 +74,7 @@ Status[4] = 0xFE; // Initailise status[4] return code if (_ID!=0xFE) { // We'll only get a reply if it was not broadcast for (int i=0; i<(6+bytes) ; i++) { // Receive the Status packet 6+ number of bytes read - Status[i] = _ax12.getc(); + Status[i] = _bus.getc(); } for (int i=0; i < Status[3]-2 ; i++) { // Copy the data from Status into data for return data[i] = Status[5+i]; @@ -115,7 +115,7 @@ // And send the packet to th AX-12+ Servo... _dir = TRANSMIT; // Switch the hardware to transmit... for (int i = 0; i < (7 + bytes) ; i++) { // Transmit the packet in one burst with no pausing - _ax12.putc(TxBuf[i]); + _bus.putc(TxBuf[i]); } wait (0.00004); // Wait for data to transmit _dir = RECEIVE; // Switch the hardware back to receive... @@ -126,7 +126,7 @@ Status[4]=0x00; // Initailise status[4] to get correct response if (_ID!=0xFE) { // We'll only get a reply if it was not broadcast for (int i=0; i < 6 ; i++) { // Response is 6 bytes - 0xFF, 0xFF, ID, Length Error, Param(s) Checksum - Status[i] = _ax12.getc(); + Status[i] = _bus.getc(); } } // if (ID!=0xFE) return(Status[4]); // return error code - if no error will return 0x00