AnsweredAssumed Answered

Help with I2C (K64F, KSDK 2.0)

Question asked by Robert Baruch on Feb 27, 2016
Latest reply on Mar 5, 2016 by Robert Baruch

I have a K64F board connected to an Adafruit LCD backpack [schematic] that I have verified works on an Arduino. The backpack is basically an I2C device, an MCP23008 [datasheet]. The backpack is running on 5V.


I wrote some code that is supposed to configure I2C0 for port E pins 24 and 25:


constexpr port_pin_config_t kI2CPortConfig {     kPORT_PullDisable,     kPORT_FastSlewRate,     kPORT_PassiveFilterDisable,     kPORT_OpenDrainEnable,     kPORT_LowDriveStrength,   kPORT_MuxAlt5,     kPORT_UnlockRegister };   I2C::I2C() {   i2c_master_config_t config;       CLOCK_EnableClock(kCLOCK_PortE);     PORT_SetPinConfig(PORTE, 24, &kI2CPortConfig);     PORT_SetPinConfig(PORTE, 25, &kI2CPortConfig);     I2C_MasterGetDefaultConfig(&config);   I2C_MasterInit(I2C0, &config, CLOCK_GetBusClkFreq()); }   status_t I2C::send(uint8_t address, const uint8_t *txBuff, size_t txSize) const {   status_t status = I2C_MasterStart(I2C0, address, kI2C_Write);   if (status != kStatus_Success) {   return status;   }     status = I2C_MasterWriteBlocking(I2C0, txBuff, txSize);   if (status != kStatus_Success) {   return status;   }     return I2C_MasterStop(I2C0); }              


I'm sending data like this:


  uint8_t set_defaults_msg[] = {       kReg_iodir,    0xFF, // set to all inputs    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // all other registers to zero   };     i2c_.send(i2c_addr_, set_defaults_msg, 11);     


Now, I hooked up an analyzer to the I2C0 pins, and got this:




So there are a few questions about this:


1. The analyzer shows the clock is going at 277 kHz, not 100 kHz. Am I using the right clock in I2C_MasterInit?

2. The analyzer shows the clock going between 0 and 3.something volts. But if I configured the ports as open drain, and the backpack has a 4.7k pullup to 5v, why isn't the output going to 5v?

3. Should I be using the functions in drivers/fsl_i2c.h or platform/i2c/drivers/master/fsl_i2c_master_driver.h?

4. I2C_MasterStart is returning kStatus_I2C_Busy. I'm guessing because SDA is low. But I'm not convinced the backpack is doing that. I disconnected the backpack and replaced it with a pair of 4.7k resistors going to +5v, and the same thing happened. So what could be causing the busy status?