IIC HELP!!!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IIC HELP!!!

1,082 Views
Circuito
Contributor I

Hi,
I have a problem whith my IIC routine, I checked the routine about 10
times, let it check by friend and nobody figures out where the problem
is.

I will call form the main code the Init_I2C, and then I will call
IIC_write, this code should place on the bus the device address, the
memory address and the data, the I2C_read should place on the bus the
device address the memory address, restart and read the data.

Whats happening is that when i try to write, the bus is doing a logic
change, it goes from hi to low and stays there until reset.
no clk is generated, some times it gets stocked on the flag checking.
When I read, when its not get stocked it returns a value that is
completly wrong.

Please help me whit this situation.

I attach the iic c file


thanks very much, Daniel

Labels (1)
0 Kudos
5 Replies

464 Views
kef
Specialist I

Could you or your friend explain what this piece of code should do?:

 

IICS_IICIF = 0;

 

In fact above line makes attempt to

1) clear IAAS flag

2) if ARBL is set, then also clear ARBL

3) preserve contents of IICIF flag

 

Does it help? :smileyhappy:

0 Kudos

464 Views
Circuito
Contributor I

Hi, thanks for reply to my question.

 

IICS_IICIF = 0;

 

this line clears the interrupt flag. in this case this flag will be used to know when a transmit is completed to continue whith the code,

0 Kudos

464 Views
kef
Specialist I

IICS_IICIF = 0; // doesn't clear IICIF. It does what I wrote above. Please read documentation carefully and find that IICIF is cleared writing "1" to it. Also keep in mind that in case other IICS bits are "1" before executing IICS_IICIF=0,  "1" will be written back to such bits. This means that ARBL and IAAS is always cleared executing IICS_IICIF=0, and IICIF is not affected. IICS_IICIF=1 would be little better but still wrong, it would clear all flags in IICS.To clear just IICIF you need to

 

  IICS_IICIF = IICS_IICIF_MASK;

 

or

 

  IICS_IICIF &= IICS_IICIF_MASK;

 

0 Kudos

464 Views
Circuito
Contributor I

Thanks again for your fast reply,

 

I checked the datasheet again and you where right, so I replaced the expression IICS_IICIF = 0; to IICS_IICIF &= IICS_IICIF_MASK; and tried again, but no change, it still not working.

 

Thanks

 

Daniel

0 Kudos

464 Views
kef
Specialist I

No change means still no clock? Try setting up baud register before enabling IIC.

You didn't say what derivative you are using. On some parts IIC modules are routeable to different pins. You should check that.

 

I see you are waiting for RXAK==0 in a loop. This doesn't make a lot of sense. After write to external device is complete, RXAK says you did that external device ACK your data or not. You should not wait for RXAK, but do some useful action on wrong RXAK level, like signal some error, abort transfer etc.

0 Kudos