Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/13/06 14:25
Read: times


 
#107288 - Re: Why not interrupt.
Responding to: ???'s previous message
Dear Erik,
Thanks for your reply,


I2CON=0x40;
I2CON|=0x20;



This seems ok I2CON=40 makes all other bits 0 except I2C enable bit.


why do you not base it on interrupt? this is a "heavy" as bit banging.


I am using interrupt too but that has been kept shortest possible so that it can read data from ADC at fastest speed possible. The function i posted is used only for channel setting and a dummy read actual reading is done in interrupt. Here is the interrupt.


//ISR for I2C Bus ADC data Receive.
void i2c_isr(void) interrupt 11 using 1
{
    uchar bt2;           // Variable to store adc data
    uint bsqr;		 // Variable to store square data.
    bt2=I2DAT;		 // Fetch data from ADC
    bsqr=bt2*bt2;	 // Square it.

    t1lock=0;    	// Flag set by timer 1 interrupt when it occurs.
    MSSUM+=bsqr;
    samples++;

    if (t1lock)  	// If timer 1 interrupt had occured while above computations
    {
	MSSUM=0;	// Make MSSUM and samples zero.
	samples=0;
    }
    I2CON&=0xF7;	// SI=0
}



These lines in main function initiate the interrupt.

I2CON=0x44;             // Initializing for 94KHz Auto Ack on.
I2CON|=0x20;            // Send a start condition.
while(!(I2CON&0x08));	//Wait for SI
I2CON&=0xDF;	        // Clear start bit.
I2DAT=0x91;		// Slave address 000 and read.
I2CON&=0xF7;		// Clear the SI Flag.
while(!(I2CON&0x08));	//Wait for SI
I2CON&=0xF7;		// Clear the SI Flag.
EI2C=1;			// Set I2C interrupt flag to turn on interrupt.


The above two codes seems working absolutely fine and have possibly no problems only the first function i posted has problems.

Thanks & Regards,
Prahlad Purohit

List of 15 messages in thread
TopicAuthorDate
I2C routine getting stuck.            01/01/70 00:00      
   you can get working code by using            01/01/70 00:00      
      Re: Getting code working            01/01/70 00:00      
         I took aquick look at the I2con use and            01/01/70 00:00      
            Re: Why not interrupt.            01/01/70 00:00      
   24MHz without four layer board?            01/01/70 00:00      
      Re: 24MHz            01/01/70 00:00      
      What max freq can be used with two layer            01/01/70 00:00      
         who knows            01/01/70 00:00      
   I2C routine getting stuck.            01/01/70 00:00      
      Working very well with C668 @ 94khz bus            01/01/70 00:00      
   Bit Bangin Works fine.            01/01/70 00:00      
   Problem Solved.            01/01/70 00:00      
      maybe worth putting it into code library            01/01/70 00:00      
         Uploaded into code library.            01/01/70 00:00      

Back to Subject List