I2c_Rd or I2c_Wr blocking when interrupted.

General discussion on mikroPascal.
Author
Message
yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#16 Post by yo2lio » 17 Aug 2008 22:00

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 ?
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#17 Post by janni » 17 Aug 2008 22:10

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.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#18 Post by janni » 17 Aug 2008 22:28

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: .

zan
Posts: 434
Joined: 15 May 2007 19:35

Re:

#19 Post by zan » 18 Jul 2014 21:29

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}

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: I2c_Rd or I2c_Wr blocking when interrupted.

#20 Post by janni » 19 Jul 2014 01:24

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 

zan
Posts: 434
Joined: 15 May 2007 19:35

Re: I2c_Rd or I2c_Wr blocking when interrupted.

#21 Post by zan » 19 Jul 2014 19:37

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.


Post Reply

Return to “mikroPascal General”