Exchange data between 20X2 in i2c mode

MTO-33F

New Member
Hello,

I want to store a sequence of characters sent to i2c to a 20X2 slave ( by a 20X2 master ) to treat them later ...

Is there a way to add a delay between sending each character ( currently about 120 µS @ 8 Mhz) because it seems insufficient time to perform the interruption routine !

Otherwise, would you know a simple way to perform this procedure ?

Thank you in advance.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -

MASTER
hi2csetup i2cmaster, $40 , i2cslow , i2cbyte
do
hi2cout ( "ABCDEFGH" )
loop

SLAVE
hi2csetup i2cslave , $40
ptr = 0
setintflags $40 , $40
do
if ptr = 8 then exit
loop
... / ...

interrupt :
get hi2clast , @ptrinc
hi2cflag = 0
return
 

MTO-33F

New Member
Additionnal information

I questioned the timing of my program thinking that the 20X2 working properly, which is not the case !!!

In fact, the first problem is that the slave 20X2, although it correctly recognizes its address, will never generate interrupt at the end of the reception of the frame i2c .

20X2 change does not solve the problem (firmware chips is : C2)

Should an additional statement that setintflags $40,$40?
 

MTO-33F

New Member
Thank you for your interest in my problem , but I had already tried to address one without does not work better .

Do you have another sugggestion ?

( I simplified my test program to the extreme to track the interruption but still nothing happens ... )

MASTER
hi2csetup i2cmaster , $40 , i2cslow , i2cbyte
do
hi2cout 0 , ( $55 )
loop

SLAVE
hi2csetup i2cslave , $40
setintflags $40 , $40
do
loop

interrupt:
high B.0
hi2cflag = 0
pauseus 10
low B.0
return
 

westaust55

Moderator
I have used SETINT but not SETINTFLAGS.

Try adding the SETINTFLAGS command within the Interrupt: routine to re-enable interrupts after the interrupt routine has completed.
See the comments under the SETINT command in PICAXE manual 2 which equally apply to the SETINTFLAGS command

Code:
interrupt:
high B.0
hi2cflag = 0
pauseus 10
low B.0
[COLOR="Red"]setintflags $40 , $40[/COLOR]
return
 

hippy

Ex-Staff (retired)
Westaust55 has hit the nail on the head, though you queried it yourself in post #2 - You need to re-enable the SETINTFLAGS for subsequent interrupts.

This test example shows a 28X2 sending a block of data to a 20X2 I2C Slave ...

Code:
#Picaxe 28X2

HI2cSetup I2cMASTER, $D0, I2CSLOW, I2CBYTE
w7 = 12345
Do
  Pause 1000
  BinToAscii w7, b0,b1,b2,b3,b4
  HI2cout 0,( b0,b1,b2,b3,b4 )
  w7 = w7 + 1
Loop
Code:
#Picaxe 20X2
#Terminal 9600

HI2cSetup I2CSLAVE, $D0

Gosub Interrupt_Enable

Do
Loop

Interrupt:
  SerTxd( #hI2cLast, CR, LF )
  For ptr = 0 To hI2cLast
   SerTxd( 9, #ptr, 9 , #@ptr, 9, @ptr, CR, LF )
  Next

Interrupt_Enable:
  hI2cFlag = 0
  SetIntFlags %01000000, %01000000
  Return
 

MTO-33F

New Member
Thank you for your help ( it was a stupid oversight , because I revalidates many interruptions when I use the timer or hint ! )

However, I have a problem receiving the slave ...

With setfreq identical on the two chips ( 8 Mhz ) , hi2clast is often to 5 (MASTER: hi2cout 0, ("ABCDEF" / pause 3000) , but sometimes 4 !

If I increase the frequency of the two chips at once (up to 32 Mhz) , hi2clast is often 4 instead 5.

In addition , hi2clast decreases sharply ( 0 or 1 ) when I increase the frequency of the slave from the master ... ( I do not understand why : it should be independent ! )

Have - you explanations of these phenomena ?

Thank you in advance - cordially
 

hippy

Ex-Staff (retired)
It sounds like there could be a timing issue. The 'hi2cflag' will be set and an interrupt occur whenever the slave receives I2C bytes; it may be that the interrupt is being activated before all bytes have been passed over.

Adding a PAUSE 1 ( or longer ) at the start of the interrupt routine may fix that.

It's probably also worth posting the exact code you have so others can see what you have, check for any issues there may be and test it themselves, see if they get the same results.
 

MTO-33F

New Member
Bravo, well seen .

In fact , in looking more closely at the scope , we see that the interruption is triggered upon recognition of his address by the slave and not (as I thought) on receipt of the I2C "stop" at the end of the shipment.

From then , subject to check that the data processing does not occur before the end of sending the last byte , it is actually possible to work at any frequency for the master or slave , regardless the each other .

Thank you again ...

NOTE : For some complex instructions , the manual would benefit from a little more explicit , especially to mention examples a little less simplistic.
 
Top