Page 2 of 2

Posted: 17 Aug 2008 22:00
by yo2lio
I made another test, with TMR4 interrupt at every 40 us and now system crash !

Janni , please explain me, why cI2C_wr is function in your code example ?

Posted: 17 Aug 2008 22:10
by janni
yo2lio wrote:I made another test, with TMR4 interrupt at every 40 us and now system crash !
Thanks, you saved me some effort :) .
Janni , please explain me, why cI2C_wr is function in your code example ?
It's a reconstruction of original ME's function from assembly (with the bug fixed, naturally), not an example :!: . Check it's description in help - it's supposed to be a function.

Posted: 17 Aug 2008 22:28
by janni
Dany wrote:Perhaps those I2c routines are not of the same structure as those of the PIC18F67J60.
Nope :cry:
As far as I understand it the problem is the order of the first statements in I2c_Rd...
To be precise, the same bug is repeated two times in I2c_Rd and once in I2c_Wr :cry: .

Re:

Posted: 18 Jul 2014 21:29
by zan
Hello

I know this is old topic, but could someone translate this code to mikroBasic?

Thank you

janni wrote:

Code: Select all

function cI2C_rd(ack:byte): byte;
 begin
  PIR1.SSPIF:=0;
  SSPCON2.RCEN:=1;
  while PIR1.SSPIF=0 do begin end;
  result:=SSPBUF;
  SSPCON2.ACKDT:=0;
  if ack<>0 then SSPCON2.ACKDT:=1;
  PIR1.SSPIF:=0;
  SSPCON2.ACKEN:=1;
  while PIR1.SSPIF=0 do begin end;
 End;{cI2C_rd}
 

function cI2C_wr(data:byte): byte;
 begin
  PIR1.SSPIF:=0;
  SSPBUF:=data;
  while PIR1.SSPIF=0 do begin end;
  if SSPCON2.ACKSTAT=0 then result:=0
   else
    begin
     SSPCON2.PEN:=1;
     result:=2;
    end;
 End;{cI2C_wr}
 
procedure cI2C_Stop;
 begin
  SSPCON2.PEN:=1;
 End;{cI2C_Stop}

Re: I2c_Rd or I2c_Wr blocking when interrupted.

Posted: 19 Jul 2014 01:24
by janni
You do not really need it as mE corrected I2C library since then, but here you are

Code: Select all

sub function cI2C_rd(dim ack as byte) as byte 
  PIR1.SSPIF=0
  SSPCON2.RCEN=1
  while PIR1.SSPIF=0 wend
  result=SSPBUF
  SSPCON2.ACKDT=0
  if ack<>0 then SSPCON2.ACKDT=1  end if
  PIR1.SSPIF=0
  SSPCON2.ACKEN=1
  while PIR1.SSPIF=0 wend
 end sub 'cI2C_rd 


sub function cI2C_wr(dim data as byte) as byte 
  PIR1.SSPIF=0
  SSPBUF=data
  while PIR1.SSPIF=0 wend
  if SSPCON2.ACKSTAT=0 then result=0
   else
     SSPCON2.PEN=1
     result=2
   end if
 end sub 'cI2C_wr 

sub procedure cI2C_Stop 
  SSPCON2.PEN=1
 end sub 'cI2C_Stop 

Re: I2c_Rd or I2c_Wr blocking when interrupted.

Posted: 19 Jul 2014 19:37
by zan
janni, thank you very much for your code.

I'm using older version of mikroBasic compiler, and I have same problem as title of this thread.
I will try your code and I hope I can solve the problem.

Thanks again.

Re: I2c_Rd or I2c_Wr blocking when interrupted.

Posted: 19 Jul 2014 20:28
by janni
Good luck then :) .