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.

TMS570LS3137: I2C TX problem with interrupts in the TMS570LS3137

Part Number: TMS570LS3137
Other Parts Discussed in Thread: HALCOGEN

Hi,

I am having some problems to get the tms570 transmiting with I2C with interruptions mode.

The situation is the following:

-First, I tested the I2C communication with the "example_i2c_pcf8570.c" example avaiable in halcogen( my slave device is also a memory with the same configuration). It worked fine, so I can say that with polling mode is everything correct.

-After that, I analyzed the "example_i2cInterrupt_Communication.c"  to see what should I change to switch from polling mode to interrupt mode( I deducted that there was no need to make a change), I made the needed changes in halcogen for making the reception with interrupts and I runned the program. It worked fine, so with RX the interrupts everything was correct.

-Then, I tried with the TX  in interrupt mode. and it didn't work.

The problem is the following:

-I use i2cSend(), and I can see how it use the interrupt, and it sends correctly the packages. However , when it comes to the next function, while(i2cIsBusBusy(i2cREG1) == true), it gets stuck there(it did not happened with the polling mode)

-The most annoying thing is that if I run the program from the begining, it always reach the point of getting stuck, but if instead of running continuosly, o run making steps, it does not get stucked, and it can keep on advancing in the program, and everything will work fine. 

The main function is the next one:

int main(void)
{
/* USER CODE BEGIN (3) */


int repeat = 0; int delay =0;

/* I2C Init as per GUI
* Mode = Master - Transmitter
* baud rate = 100KHz
* Count = 10
* Bit Count = 8bit
*/
_enable_interrupt_();
i2cInit();

///////////////////////////////////////////////////////////////
// Master Transfer Functionality //
///////////////////////////////////////////////////////////////

/* Configure address of Slave to talk to */
i2cSetSlaveAdd(i2cREG1, PCF8570_ADDRESS);

/* Set direction to Transmitter */
/* Note: Optional - It is done in Init */
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);

/* Configure Data count */
/* Data Count + 2 ( Word Address) */
i2cSetCount(i2cREG1, DATA_COUNT + 2);

/* Set mode as Master */
i2cSetMode(i2cREG1, I2C_MASTER);

/* Set Stop after programmed Count */
i2cSetStop(i2cREG1);

/* Transmit Start Condition */
i2cSetStart(i2cREG1);

/* Send the Word Address */
i2cSendByte(i2cREG1, Slave_Word_address);
i2cSendByte(i2cREG1, Slave_Word_address);

/* Tranmit DATA_COUNT number of data in Polling mode */
i2cSend(i2cREG1, DATA_COUNT, TX_Data_Master);

/* Wait until Bus Busy is cleared */
while(i2cIsBusBusy(i2cREG1) == true); //THE PROBLEM HAPPENS HERE

/* Wait until Stop is detected */
while(i2cIsStopDetected(i2cREG1) == 0);

/* Clear the Stop condition */
i2cClearSCD(i2cREG1);

/* Simple Dealya before starting Next Block */
/* Depends on how quick the Slave gets ready */
for(delay=0;delay<100000;delay++);


///////////////////////////////////////////////////////////////
// Master Receive Functionality //
///////////////////////////////////////////////////////////////

/*****************************************/
//// Setup Slave to receving the data
/*****************************************/

/* wait until MST bit gets cleared, this takes
* few cycles after Bus Busy is cleared */
while(i2cIsMasterReady(i2cREG1) != true);

/* Configure address of Slave to talk to */
i2cSetSlaveAdd(i2cREG1, PCF8570_ADDRESS);

/* Set direction to Transmitter */
/* Note: Optional - It is done in Init */
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);

/* Configure Data count */
/* Slave address + Word address write operation before reading */
i2cSetCount(i2cREG1, Receive_data_setup);

/* Set mode as Master */
i2cSetMode(i2cREG1, I2C_MASTER);

/* Set Stop after programmed Count */
i2cSetStop(i2cREG1);

/* Transmit Start Condition */
i2cSetStart(i2cREG1);

/* Send the Word Address */
i2cSendByte(i2cREG1, Slave_Word_address);
i2cSendByte(i2cREG1, Slave_Word_address);

/* Wait until Bus Busy is cleared */
while(i2cIsBusBusy(i2cREG1) == true);

/* Wait until Stop is detected */
while(i2cIsStopDetected(i2cREG1) == 0);

/* Clear the Stop condition */
i2cClearSCD(i2cREG1);

/*****************************************/
//// Start receving the data From Slave
/*****************************************/

/* wait until MST bit gets cleared, this takes
* few cycles after Bus Busy is cleared */
while(i2cIsMasterReady(i2cREG1) != true);

/* Configure address of Slave to talk to */
i2cSetSlaveAdd(i2cREG1, PCF8570_ADDRESS);

/* Set direction to receiver */
i2cSetDirection(i2cREG1, I2C_RECEIVER);

/* Configure Data count */
/* Note: Optional - It is done in Init, unless user want to change */
i2cSetCount(i2cREG1, DATA_COUNT);

/* Set mode as Master */
i2cSetMode(i2cREG1, I2C_MASTER);

/* Set Stop after programmed Count */
i2cSetStop(i2cREG1);

/* Transmit Start Condition */
i2cSetStart(i2cREG1);

/* Tranmit DATA_COUNT number of data in Polling mode */
i2cReceive(i2cREG1, DATA_COUNT, RX_Data_Master);

/* Wait until Bus Busy is cleared */
while(i2cIsBusBusy(i2cREG1) == true);

/* Wait until Stop is detected */
while(i2cIsStopDetected(i2cREG1) == 0);

/* Clear the Stop condition */
i2cClearSCD(i2cREG1);

asm(" nop");
asm(" nop");
asm(" nop");

while(1);
}

What is happening?What should I do to fix the problem?

Ander