I'm using a dsPic30f4011 and I'm trying to communicate with a servo via I2C. The reason for I2C is because I replaced the servo's controller board with "open Servo" one:
http://www.openservo.com/ - the open servo project
Only mine is from Spurkfun:
http://www.sparkfun.com/products/9014
I've tried many things but I can't make it work. Is my code written right?
I'm new to I2C, though searched the web a lot till now.
This should move the servo:
I want to make sure that the code is ok, so I can find why i can't make work.
Any help will be appreciated!
http://www.openservo.com/ - the open servo project
Only mine is from Spurkfun:
http://www.sparkfun.com/products/9014
I've tried many things but I can't make it work. Is my code written right?
I'm new to I2C, though searched the web a lot till now.
This should move the servo:
Rich (BB code):
#include <p30f4011.h>
#include <i2c.h> //Header File for I2C module Library routines
unsigned int I2CConfig;
unsigned int I2C_BRG;
int main(void)
{
//Configure the I2C Bus
CloseI2C();
I2CConfig = I2C_ON & //Enable the I2C Bus
I2C_IDLE_CON &
I2C_CLK_HLD &
I2C_IPMI_DIS &
I2C_7BIT_ADD & //Use a 7 Bit Slave Address
I2C_SLW_DIS &
I2C_SM_DIS &
I2C_GCALL_DIS &
I2C_STR_DIS &
I2C_NACK &
I2C_ACK_DIS &
I2C_RCV_DIS &
I2C_STOP_DIS &
I2C_RESTART_DIS &
I2C_START_DIS;
I2C_BRG = 0xB5; //0xB5 = 181 => Fscl=100kHz=Boud Rate, PGD=250ns, Fcy=20MHz
OpenI2C(I2CConfig , I2C_BRG); //Open the I2C Bus
IdleI2C();
while(1)
{
//Setting position of 0x226 = 550 (should be center position)
StartI2C();
MasterWriteI2C(0x40); //7 bit OpenServo address 0x20 + LSB 0 for "write"
MasterWriteI2C(0x08); //Position_high register
MasterWriteI2C(0x02); //High byte
MasterWriteI2C(0x26); //Low byte
StopI2C();
}
}
Any help will be appreciated!