This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EK-TM4C1294XL: Master stays busy while transmitting data using I2C

Part Number: EK-TM4C1294XL

Hello,

Master stays busy while transmitting data using I2C. Also, there is no data transmission happening which i have confirmed using CRO. I'm using 24LC256 EEPROM as my slave. I think there is some initialization issue but i;m unable to point it out. Any lead is much appreciated.

 

Below are initialization and TX functions in my source code:

extern uint32_t u32_SysClock;

const uint32_t u32_slave_addr[3] =
{
0x50 ,
0x51 ,
0x52 ,
};

void i2c_init(void)
{

//
// The I2C0 peripheral must be enabled before use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

//reset module
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);

//
// GPIO port B needs to be enabled so these pins 2 and 3 can
// be used.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

//
// Configure the pin muxing for I2C0 functions on port B2 and B3.
//
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);

//
// Select the I2C function for these pins. This function will also
// configure the GPIO pins pins for I2C operation, setting them to
// open-drain operation with weak pull-ups.
//
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

//
// Enable and initialize the I2C0 master module. Use the system clock for
// the I2C0 module. The last parameter sets the I2C data transfer rate.
// If false the data rate is set to 100kbps and if true the data rate will
// be set to 400kbps. 
//
I2CMasterInitExpClk(I2C0_BASE, u32_SysClock, false);

//clear I2C FIFOs
HWREG(I2C0_BASE + I2C_O_FIFOCTL) = 80008000;

//
// Enable the I2C0 slave module. This module is enabled only for testing
// purposes. It does not need to be enabled for proper operation of the
// I2Cx master module.
//
I2CSlaveEnable(I2C0_BASE);

}

void i2c_tx(uint32_t device, uint32_t addr, uint32_t u32_TxData)
{
addr = addr & 0x0000FFFF;

I2CSlaveInit(I2C0_BASE, u32_slave_addr[device]);


I2CMasterSlaveAddrSet(I2C0_BASE, u32_slave_addr[device], false);


//
// Place the data to be sent in the data register
//
I2CMasterDataPut(I2C0_BASE, (addr >> 8));

I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);

//
// Wait until the slave has received and acknowledged the data.
//
while(!(I2CSlaveStatus(I2C0_BASE) & I2C_SLAVE_ACT_RREQ))
{
}

//
// Place the data to be sent in the data register
//
I2CMasterDataPut(I2C0_BASE, (addr & 0x00FF));

I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);

//
// Wait until the slave has received and acknowledged the data.
//
while(!(I2CSlaveStatus(I2C0_BASE) & I2C_SLAVE_ACT_RREQ))
{
}

//
// Place the data to be sent in the data register
//
I2CMasterDataPut(I2C0_BASE, u32_TxData);

I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);

//
// Wait until the slave has received and acknowledged the data.
//
while(!(I2CSlaveStatus(I2C0_BASE) & I2C_SLAVE_ACT_RREQ))
{
}
}

  • Pardon - yet our 'outsider team' (awaits) vendor agent's (standard)  'Hi (    ).'

    RAKSHIT A R said:
    I2CSlaveEnable(I2C0_BASE);

    In the case of an MCU & small memory device - almost always the MCU becomes the Master.   (And - it is (only) the Master which generates the 'I2C clocks!')    Yet your code has (only) enabled the Slave!

    Should there not be a (similar) function call - commanding your MCU into 'Master I2C Mode?'    (such would describe your report of 'No Output' ... and the Master - rather than being 'busy' - is more likely w/in a (near) coma condition!)

    [edit]: 10:25 CST - Vendor's Bob has described the 'encapsulation' of  "I2CMasterEnable()" w/in "I2CMasterInitExpClk()".     Thus - that is 'removed' as potential cause.

    However it is noted that, "the I2C0 Module has been initialized as (both) I2C0 'Master AND Slave' - w/'No clear switching' between the two!    Might the user code (posted here) been specifically meant for a, 'I2C Loopback Mode' - in which, 'NO External Signals' (especially SCL) are emitted?    It is believed (unusual) for an I2C Module to be 'simultaneously' configured as (both) Master & Slave - user is directed to 'Remove' all 'MCU Slave Configuring code' (but for the address of the memory slave device) and test/verify...

    In addition - the total reliance upon the MCU's internal (very weak) pull-up resistors - proves often 'risky.'    (External resistors (usually 4K7 - 10K) - for each I2C signal line - enable superior signal 'rise-time' - which provides more robust I2C Operation...)

  • Just to check some basics, do you have pull up resistors on SCL and SDA? Have you looked at them with a scope? Are they high or low? Can you see any clocks on SCL (you will need to start a single sweep trigger on the scope and then run your code).

  • May it not be (even) more eventful - that the call to:  I2CMasterEnable()  appears to have been missed?

    [edit]:  08:34   (Unless  "I2CMasterControl()" calls  "I2CMasterEnable()" -  which calls into question the 'justification for/existence' of  "I2CMasterEnable()".

    In addition - does not the presence of "I2CSlaveEnable()" - rather strongly - suggest  its equivalent (Master usage) as well?

  • Hi CB1,

    You may be right that the call to I2CSlaveEnable() may be causing the problem. Calling I2CMasterInitExpClk() will actually enable the master so that I2CMasterEnable() then need not be called unless re-enabling after a call to I2CMasterDisable(). Most of my examples do not make an explicit call to I2CMasterEnable().

  • Hello Bob,

    Thank you - yours is (both) timely & well-thought - staff/I appreciate your clear effort.

    Especially helpful is your noting, "I2CMasterEnable() then need not be called unless re-enabling after a call to I2CMasterDisable()."     

    That 'subtlety' escaped (both) staff & myself - although I have (long) instructed staff, 'Better to generally (actively) include such a function - rather than 'hope/pray' for default or 'buried inclusion' - via another function.

    As an 'exercise' - I challenged the young staff to identify a (likely) case - in which the I2C Master would be 'disabled.'     They could only identify the case presented by, 'Multiple Masters' - in which the issue of the, mandatory singularity of the 'SCL' signal line - must be insured.    (Yet - as the SCL is 'Open Drain' - that 'disabling to prevent SCL bus-contention' - appears less than compelling!)     *** Unless and until that 'Master MCU' is ordered into 'Slave Mode' - yet even then - would not being a 'slave' prevent the MCU from outputting the SCL clock?

    Might you then Bob - be better able to identify those cases - in which it is 'desired' to 'Disable the I2C Master?'     (We've tried - w/out solid results...)

    It is suspected that the "SW-TM4C-DRL-User Guide" would 'benefit' from your clever & insightful wording - absent w/in the present Guide.

  • May it be additionally noted that poster's code selects/sets (both) the MCU's 'Master and Slave'  to the SAME I2C Module!    (I2C0)

    I2CMasterInitExpClk(I2C0_BASE, u32_SysClock, false);

    I2CSlaveEnable(I2C0_BASE);

    I2CSlaveInit(I2C0_BASE, u32_slave_addr[device]);

    Can the I2C module perform as (both) Master & Slave - minus any switching - when initialized in this manner?    (Unless this is 'acceptable' under (some form) of I2C 'Loopback' operation...)

  • Since I have not heard back from you I assume you have resolved this issue. If not, please respond to this thread or ask a related question.

  • Hello Bob,

    Unfortunately, the issue isn't solved yet and I'm still working on it. However my exams are going on, hence the progress is slow. I'll continue with it ASAP and update this thread.

    Thank you for your continued support.

    Regards,

    Rakshit A R