embedded - I2C with Atmega168 -


i'm trying control several servos using adafruit pwm servo controller. uses i2c interface communicate micro controller. https://www.adafruit.com/product/815

i'm using atmega 168 attempt send i2c instructions micro controller using simple i2c library.

#include "i2c.h"  void initi2c(void) {   twbr = 32;                               /* set bit rate, see p. 242 */                                      /* 8mhz / (16+2*twbr*1) ~= 100khz */   twcr |= (1 << twen);                                       /* enable */ }  void i2cwaitforcomplete(void) {   loop_until_bit_is_set(twcr, twint); }  void i2cstart(void) {   twcr = (_bv(twint) | _bv(twen) | _bv(twsta));   i2cwaitforcomplete(); }  void i2cstop(void) {   twcr = (_bv(twint) | _bv(twen) | _bv(twsto)); }  uint8_t i2creadack(void) {   twcr = (_bv(twint) | _bv(twen) | _bv(twea));   i2cwaitforcomplete();   return (twdr); }  uint8_t i2creadnoack(void) {   twcr = (_bv(twint) | _bv(twen));   i2cwaitforcomplete();   return (twdr); }  void i2csend(uint16_t data) {   twdr = data;   twcr = (_bv(twint) | _bv(twen));                  /* init , enable */   i2cwaitforcomplete(); } 

i found addresses of servo controller arduino driver i'm having issues setting pwm of board. here code i'm attempting use:

#include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> #include "i2c.h"  #define servo_min 1000 #define servo_max 2000 #define servo_mid 1500  #define pca9685_addr 0x4  #define pca9685_mode1 0x0  #define led0_on_l 0x6 #define led0_on_h 0x7 #define led0_off_l 0x8 #define led0_off_h 0x9  int main(void) {   initi2c();   setupcontroller();   for(int = 1; < 17; i++) {     setservo(i, 0, 4026);   }   return 0; }  void setupcontroller() {     i2cstart();     i2csend(pca9685_addr);     i2csend(pca9685_mode1);     i2csend(0x0);     i2cstop(); }  void setservo(uint8_t id, uint16_t start, uint16_t stop) {     i2cstart();     i2csend(pca9685_addr);     i2csend(led0_on_l+4*id);     i2csend(start);     i2csend(start>>8);     i2csend(stop);     i2csend(stop>>8);     i2cstop(); } 

here driver: https://github.com/adafruit/adafruit-pwm-servo-driver-library

i'm pretty sure i2c isn't set correctly? suggestions?

thank you! :)


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -