texas instruments - TI TivaC Launchpad I2C Errors -


i trying communicate on i2c pololu minimu9v2 tm4c123gxl launchpad, every time try write bus, getting i2c_master_err_addr_ack , i2c_master_err_data_ack. printing out slave address shows looks right, i'm thinking may may doing wrong use of ti launchpad driver library.

here's initialization routine:

void initi2cbus(void) {     // initialize tm4c i2c hardware i2c0     sysctlclockset(sysctl_sysdiv_1 | sysctl_use_osc | sysctl_osc_main |                    sysctl_xtal_16mhz);     sysctlperipheralenable(sysctl_periph_i2c0);     sysctlperipheralenable(sysctl_periph_gpiob);     gpiopinconfigure(gpio_pb2_i2c0scl);     gpiopinconfigure(gpio_pb3_i2c0sda);     gpiopintypei2c(gpio_portb_base, gpio_pin_3);     // initialize bus     i2cmasterinitexpclk(i2c0_base, sysctlclockget(), false); } 

here code attempts read byte device:

uint8_t readbyte(uint8_t slaveaddr, uint8_t subaddr) {     // write sub     slaveaddr |= 1; // set lsb writemode     i2cmasterslaveaddrset(i2c0_base, slaveaddr, false);      i2cmasterdataput(i2c0_base, subaddr);     i2cmastercontrol(i2c0_base, i2c_master_cmd_single_send);     while(i2cmasterbusy(i2c0_base)) { }      if (checkerror())     {         return 0;     }      // read data     slaveaddr &= ~1; // set lsb readmode     i2cmasterslaveaddrset(i2c0_base, slaveaddr, true);     i2cmastercontrol(i2c0_base, i2c_master_cmd_single_receive);     while(i2cmasterbusy(i2c0_base)) { }     i2cmastercontrol(i2c0_base, i2c_master_cmd_single_receive);     while(i2cmasterbusy(i2c0_base)) { }      uint8_t response = i2cmasterdataget(i2c0_base);      if (checkerror())     {         return 0;     }      return response; } 

any ideas may doing wrong?

i having heck of time getting i2c bus working on board. i'm not sure if issue, here's initialization code i'm using (i'm on i2c2):

1. sysctlperipheralenable(sysctl_periph_i2c2); 2. sysctlperipheralenable(sysctl_periph_gpiof); **3. gpiopintypei2cscl(gpio_portf_base, gpio_pin_6);** 4. gpiopintypei2c(gpio_portf_base, gpio_pin_7); 5. gpiopinconfigure(gpio_pf6_i2c2scl); 6. gpiopinconfigure(gpio_pf7_i2c2sda); 7. i2cmasterinitexpclk(i2c2_base, sysctlclockget(), false); 8. i2cmasterslaveaddrset(i2c2_base, 0x48, false); 

line 3 missing of examples find, , noticed it's missing code. before added line, couldn't i2c bus anything; after adding it's @ least transferring data.

i'm not sure if source of issue or not, thought i'd pass along in case helps.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -