This is a driver to control the SD20 20 Channel I2C to Servo Driver Chip from www.robot-electronics.co.uk (http://www.robot-electronics.co.uk/htm/sd20tech.htm). This driver will allow a servo channel to be started up, stopped and the duty cycle altered in standard mode. No attempt to include the extended mode is included.
Revision 6:973d6a66dbf7, committed 2016-03-04
- Comitter:
- sk398
- Date:
- Fri Mar 04 23:04:28 2016 +0000
- Parent:
- 5:eba9f639154c
- Commit message:
- Modified updateChannel to accept 2 chars instead of char *; ; Still having huge issue with printf statement, only working with this.
Changed in this revision
| SD20.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SD20.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SD20.cpp Thu Feb 25 20:26:24 2016 +0000
+++ b/SD20.cpp Fri Mar 04 23:04:28 2016 +0000
@@ -31,17 +31,21 @@
_bus -> frequency(BUS_FREQ);
}
-int SD20::UpdateChannel(char *newDutyCycle)
+int SD20::UpdateChannel(char channelReg, char channelSpeed)
{
// Output new duty cycle to SD20, return 0 if successful, 1 if unsuccessful
- if(_bus -> write(SD20_ADDRESS,newDutyCycle,OUT_BUF_LEN))
+ updateDutyCycle[0] = channelReg;
+ updateDutyCycle[1] = channelSpeed;
+
+ if(_bus -> write(SD20_ADDRESS,updateDutyCycle,2))
{
- printf("I2C Failed to write\r\n");
+// printf("I2C Failed to write\r\n");
return 1;
}
else
{
-// printf("Reg: 0x%02x Data: 0x%02x\r\n",*newDutyCycle,*(newDutyCycle+1));
+// updateDutyCycle = *(updateDutyCycle+1)
+ printf("Reg: 0x%02x Data: 0x%02x\r\n",*updateDutyCycle,*(updateDutyCycle+1));
return 0;
}
}
@@ -51,10 +55,10 @@
// Startup a new channel, return 0 if successful, 1 if unsuccessful
if(Start == CHANNEL_START)
{
- char newDutyCycle[] = {ServoChannel,CHANNEL_START};
- if(_bus -> write(SD20_ADDRESS,newDutyCycle,OUT_BUF_LEN))
+ char startDutyCycle[] = {ServoChannel,CHANNEL_START};
+ if(_bus -> write(SD20_ADDRESS,startDutyCycle,OUT_BUF_LEN))
{
- printf("I2C Failed to write\r\n");
+// printf("I2C Failed to write\r\n");
return 1;
}
else
@@ -67,10 +71,10 @@
// Stop channel, return 0 if successful, 1 if unsuccessful
else
{
- char newDutyCycle[] = {ServoChannel,CHANNEL_STOP};
- if(_bus -> write(SD20_ADDRESS,newDutyCycle,OUT_BUF_LEN))
+ char stopDutyCycle[] = {ServoChannel,CHANNEL_STOP};
+ if(_bus -> write(SD20_ADDRESS,stopDutyCycle,OUT_BUF_LEN))
{
- printf("I2C Failed to write\r\n");
+// printf("I2C Failed to write\r\n");
return 1;
}
else
@@ -86,7 +90,7 @@
char outputBuf[] = {STD_ETD_MODE_CTRL,STD_MODE};
if(_bus -> write(SD20_ADDRESS,outputBuf,OUT_BUF_LEN))
{
- printf("I2C Failed to write\r\n");
+// printf("I2C Failed to write\r\n");
return 1;
}
else
--- a/SD20.h Thu Feb 25 20:26:24 2016 +0000
+++ b/SD20.h Fri Mar 04 23:04:28 2016 +0000
@@ -94,7 +94,8 @@
private:
I2C *_bus;
-
+
+ char updateDutyCycle[2];
public:
/** Create a SD20 Constructor, connected over I2C Master connection
@@ -120,7 +121,7 @@
* parameter mode: Select whether debug mode[0] and prints result or implementation mode [1]
* where print commands are skipped to save operational time
*/
- int UpdateChannel(char *DataOutput);
+ int UpdateChannel(char channelReg, char channelSpeed);
int SetStandardMode();