User manual
478
mikoC PRO for dsPIC
MikroElektronika
Soft_I2C_Break
Prototype
void Soft_I2C_Break();
Description All Software I²C Library functions can block the program ow (see note at the top of this page). Calling
this routine from interrupt will unblock the program execution. This mechanism is similar to WDT.
Parameters None.
Returns Nothing.
Requires Nothing.
Example
// Software I2C connections
sbit Soft_I2C_Scl at RC0_bit;
sbit Soft_I2C_Sda at RC1_bit;
sbit Soft_I2C_Scl_Direction at TRISC0_bit;
sbit Soft_I2C_Sda_Direction at TRISC1_bit;
// End Software I2C connections
char counter = 0;
void Timer1Int() org IVT_ADDR_T1INTERRUPT {
if (counter >= 20) {
Soft_I2C_Break();
counter = 0; // reset counter
}
else
counter++; // increment counter
T1IF_bit = 0; // Clear Timer1 overow interrupt ag
}
void main() {
...
// try Soft_I2C_Init with blocking prevention mechanism
IPC0 = IPC0 | 0x1000; // Interrupt priority level = 1
T1IE_bit= 1; // Enable Timer1 interrupts
T1CON = 0x8030; // Timer1 ON, internal clock FCY, prescaler
1:256
Soft_I2C_Init();
T1IE_bit= 0; // Disable Timer1 interrupts
}
Notes Interrupts should be disabled before using Software I²C routines again (see note at the top of this
page).