I need to communicate with a device using SMBus and display SOC on a seven segment display. I use PIC18F26K83. Seven Segment Display needs I2C connection. The problem is I will be using 2 different I2C modules with 2 different I2C clocks. SMBus needs to be between 10 kHz and 100 kHz. I use 8 MHz MCU clock. With seven segment display part I cannot make it work without setting I2CxCLK register to HFINTOSC (0010). I tried using TMR2 post scaled output for it. Timer code is below:
void InitTimer2(){
T2CLK =0b00000101; //500 kHz
T2CON.B7 = 1; //Timer 2 is on
T2CON.B3=0;
T2CON.B3=0;
T2CON.B3=0; //Timer 2 PostScaler = 1:2 (500/2 = 250 kHz)
T2CON.B3=1;
}
Then I call this InitTimer2() function in the main method. After that I choose I2CxCLK to be TMR2 post scaled output (0110). However, it does not work... If I directly set I2CxCLK HFINTOSC then it works. (In all cases MCU Clock is 8 MHz). So my questions are:
Is that timer initialization correct?
Does my MCU frequency, affect the timer frequency?
Shouldn't be InitTimer2 function as the following:
void InitTimer2(){
T2CLK =0b00000101; //500 kHz
T2CON.B7 = 1; //Timer 2 is on
T2CON.B3=0;
T2CON.B2=0;
T2CON.B1=0;
T2CON.B0=1; //Timer 2 PostScaler = 1:2 (500/2 = 250 kHz)
}
Also please check the PMD function of the PIC. See pg.275 and pg.277 of the datasheet. Make sure TMR2MD=0.