Hi Amit
In your diagram channel 2 (blue) is INT1 (PTC6).
You should find that the pulse repeast every 20ms (50Hz) whereby the pulse width is the time until the data is read via I2C, resetting the interrupt source
If you hit the enter key on the debug port you will see a menu - there is an I2C sub-menu (eneter the menu number 7 plus return to move to it) where you can command "acc_on" so that the values are displayed every 2 seconds - "acc_off" to disable.
In the case of your code I don't know wheher the interrupt is being handled or whether the data is not being read correcly so that the interrupt is not being cleared - this will require you verifiying these two points to idenify what is not happening or what is not correct. As reference I can show the code that is running in the uTasker project. This is using an interrupt driven I2C driver and a simple OS so the code is based on a simple state-event machines. You should get the idea and can certainly verify the I2C messages being used. Perhaps you notice something.
Regards
Mark
// Definition of I2C messages (reads and wries)
//
static const unsigned char ucSetAccelerometerAddress[] = {MMA8451Q_WRITE_ADDRESS, ACC_START_ADDRESS}; // command to set address to read to the start address
static const unsigned char ucReadAccelerometerRegisters[] = {ACC_READ_LENGTH, MMA8451Q_READ_ADDRESS, OWN_TASK}; // command to start a read the defined amount of bytes with the task scheduled when the read has completed
static const unsigned char ucSetAccelerometerRead[] = {MMA8451Q_WRITE_ADDRESS, 0}; // command to set address to read to the first register address (status)
static const unsigned char ucReadAccelerometerState[] = {4, MMA8451Q_READ_ADDRESS, OWN_TASK}; // command to start a read the defined amount of bytes with the task scheduled when the read has completed
static const unsigned char ucRouteIrq[] = {MMA8451Q_WRITE_ADDRESS, ACC_CONTROL_REGISTER_5, (ACC_CONTROL_REGISTER_5_INT_1_DATA_RDY)}; // route interrupt to IRQ1
static const unsigned char ucConfigureIrq[] = {MMA8451Q_WRITE_ADDRESS, ACC_CONTROL_REGISTER_4, (ACC_CONTROL_REGISTER_4_INT_EN_DATA_RDY)}; // command to enable interrupt
static const unsigned char ucSetAccelerometerMode[] = {MMA8451Q_WRITE_ADDRESS, ACC_CONTROL_REGISTER, (ACC_CONTROL_REGISTER_ACTIVE | ACC_CONTROL_REGISTER_DATA_RATE_50Hz | ACC_CONTROL_REGISTER_SLEEP_RATE_6_25Hz | ACC_CONTROL_REGISTER_LNOISE | ACC_CONTROL_REGISTER_F_READ)}; // command to set the mode
// State machine states
//
#define ACC_INITIALISING 0
#define ACC_X_Y_Z 1 // reading X,Y,Z data
#define ACC_WAITING 2 // waiting for accelerometer to interrupt
#define ACC_TRIGGERED 3 // accelerometer has interrupted so we should read data
#define ACC_MAGNETOMETER 4 // reading magnetic data
static int iAccelerometerState = ACC_INITIALISING; // state machine variable
// Initialisation (executeted once to start)
//
static void fnConfigIIC_Interface(void)
{
IICTABLE tIICParameters;
tIICParameters.Channel = OUR_IIC_CHANNEL;
tIICParameters.usSpeed = 50; // 50k
tIICParameters.Rx_tx_sizes.TxQueueSize = 64; // transmit queue size
tIICParameters.Rx_tx_sizes.RxQueueSize = 64; // receive queue size
tIICParameters.Task_to_wake = 0; // no wake on transmission
if ((IICPortID = fnOpen(TYPE_IIC, FOR_I_O, &tIICParameters)) !=0) { // open the channel with defined configurations
fnWrite(IICPortID, (unsigned char *)ucSetAccelerometerAddress, sizeof(ucSetAccelerometerAddress)); // write the register address to read from
fnRead(IICPortID, (unsigned char *)ucReadAccelerometerRegisters, 0); // start the read process of the required amount of bytes
}
}
// Accelerometer data ready (interrupt routine)
//
static void acc_data_ready(void)
{
if (ACC_WAITING == iAccelerometerState) { // if expecting an interrupt
iAccelerometerState = ACC_TRIGGERED; // signal that data is ready and should be read
uTaskerStateChange(OWN_TASK, UTASKER_GO); // schedule the task to handle the new state and request the daa
}
}
// State-event machine for the accelerometer in interrupt driver mode
// - executed on events (I2C message ready or interrupt scheduled)
//
...
switch (iAccelerometerState) {
case ACC_INITIALISING: // initial register dump ready
if (fnRead(IICPortID, ucInputMessage, ACC_READ_LENGTH) != 0) { // if the read has completed
int i = 0;
int iLine;
fnDebugMsg("3-axis accelerometer:\r\n");
while (i < ACC_READ_LENGTH) {
for (iLine = 0; iLine < 15; iLine++) {
fnDebugHex(ucInputMessage[i], (sizeof(ucInputMessage[i]) | WITH_LEADIN | WITH_SPACE)); // display the received register contents
if (++i >= ACC_READ_LENGTH) {
break;
}
}
fnDebugMsg("\r\n");
}
// We now set the operating mode
//
{ // configure a falling edge sensitive interrupt in IRQ1 output
INTERRUPT_SETUP interrupt_setup; // interrupt configuration parameters
interrupt_setup.int_type = PORT_INTERRUPT; // identifier to configure port interrupt
interrupt_setup.int_handler = acc_data_ready; // handling function
interrupt_setup.int_priority = PRIORITY_PORT_C_INT; // interrupt priority level
interrupt_setup.int_port = PORTC; // the port that the interrupt input is on
interrupt_setup.int_port_bits = PORTC_BIT6; // the IRQ input connected (SWITCH_1 on TWR_K60N512)
interrupt_setup.int_port_sense = (IRQ_FALLING_EDGE | PULLUP_ON); // interrupt is to be falling edge sensitive
fnConfigureInterrupt((void *)&interrupt_setup); // configure interrupt
}
iAccelerometerState = ACC_WAITING; // waiting for interrupts from the accelerometer
fnWrite(IICPortID, (unsigned char *)ucRouteIrq, sizeof(ucRouteIrq)); // route interrupt output to IRQ1
fnWrite(IICPortID, (unsigned char *)ucConfigureIrq, sizeof(ucConfigureIrq)); // configure interrupt
fnWrite(IICPortID, (unsigned char *)ucSetAccelerometerMode, sizeof(ucSetAccelerometerMode)); // write the operating mode
if (_READ_PORT_MASK(C, PORTC_BIT6) == 0) { // if the accelerometer is already signalling that it has data (it is possible that it was previouly operating and has data ready, signaled by the interrupt line laread being low)
acc_data_ready(); // start an initial read
}
}
break;
case ACC_WAITING: // ignore in this state
break;
case ACC_TRIGGERED: // accelerometer has indicated that there is data to be read
iAccelerometerState = ACC_X_Y_Z;
fnWrite(IICPortID, (unsigned char *)ucSetAccelerometerRead, sizeof(ucSetAccelerometerRead)); // write the register address to read
fnRead(IICPortID, (unsigned char *)ucReadAccelerometerState, 0); // start the read process of the status
break;
case ACC_X_Y_Z: // we are expecting status data from the accelerometer to arrive
if (fnRead(IICPortID, ucInputMessage, 4) != 0) { // if the status read has completed
static int iDisplayRate = 0;
#define ACC_DISPLAY_FILTER 25
iAccelerometerState = ACC_WAITING;
if (++iDisplayRate > ACC_DISPLAY_FILTER) {
if (iAccelOutput != 0) {
int i = 0;
fnDebugMsg("3-axis state:"); // display the status on a regular basis
while (i < 4) { // display 4 values
fnDebugHex(ucInputMessage[i], (sizeof(ucInputMessage[i]) | WITH_LEADIN | WITH_SPACE)); // display the received register contents
i++;
}
fnDebugMsg("\r\n");
}
iDisplayRate = 0;
}
}
break;
}
...