Wierd I2C stop sequence (MCF52235)

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

Wierd I2C stop sequence (MCF52235)

1,992 Views
cmag
Contributor I
Howdy,
 
Got a problem and I'm pretty new to this so hopefully I'm just making a stupid mistake.
 
 
I'm using i2c between my MCF52235 and another chip and the freescale is the master.
 
 
The chip I'm working with has what I think is a strange sequence as far as the freescale being able to read from it.
 
The first byte I'm sending the chip is the address obviously, and the read bit is set.  I'm getting an ack back.
 
Here's the problem.  If the first byte I read from the chip is the number of bytes I'm going to be receiving in total.  If I get all zero's (meaning zero bytes), I'm supposed to NAK and kill the session.  If I get anything else, I'm supposed to ACK and the chip will keep sending until I get to the last byte, and then I NAK to kill it.
 
However, how am I supposed to read that first byte and then immediatly either NAK or ACK depending on the value.  I thought I'm supposed to tell the MCF52235 that it is to NAK and ACK before I do the final read.  I can't really do that if the first byte I read determines that.
 
Any ideas?
 
Thanks,
cmag


Message Edited by cmag on 2008-03-27 12:13 AM

Message Edited by cmag on 2008-03-27 12:15 AM
Labels (1)
0 Kudos
Reply
4 Replies

616 Views
mjbcswitzerland
Specialist V
cmag

Have you tried always not ACKing the first byte, reading the data and then setting the ACK bit accordingly? I don't know at exactly which point in time the transmitter signals that its byte transfer has completed (either after 8 bits or after 9 bits). If it is after 8 bits it may work, but if it is only after 9 it may well be a problem.

In the worst case you can always use the ports as GPIO and bit bang this - or possibly only bit bang the first transmitted byte.

Regards

Mark

www.uTasker.com


0 Kudos
Reply

616 Views
cmag
Contributor I
Hey Mark, thanks for the response.
 
My understanding is that when the data register is read the ACK bit is set according to the TXAK setting.  It's very possible I'm miss interpreting this.  If not, and that is the case, then in order to set my TXAK I would have to know what's in byte one before I read it.
 
I do believe I tried doing an ACK for the first byte even when it's all zeros and hoping I would just get all ones on the next byte because the slave let the SDA go.  I think according to the slaves specs it fully expects the NAK on the first byte if it's zero and it seems to freeze up.
 
Either I'm doing something very wrong or this think is just too finicky.
 
So what's this bit pounding your referring to.  Is there a way to read the register bit by bit and not have it send the ACK/NAK?
 
Thanks,
cmag
0 Kudos
Reply

616 Views
mjbcswitzerland
Specialist V
cmag

When it is time to read the first byte, reprogram the IIC port back to GPIO mode.
Generate 8 clocks on the GPIO line shared with SCL - and read the state on the other port (programmed as input) to collect the 8 data bits. (Due to max. speed of I2C bus it will be necessary to slow the clocking down with a small wait loop).

After interpreting the data in the first byte, generate the 9th clock pulse and program the GPIO line shared with SDA as output to drive the ACK, if appropriate. After the 9th clock reprogram the GPIO as I2C function again and send either the stop condition or else continue receiving bytes.

If you are only doing a small amount of work with the I2C device the whole I2C stuff can be generated using GPIOs - the criteria is that it must be master function since bit banging a slave interface doesn't really work.

Regards

Mark


0 Kudos
Reply

616 Views
cmag
Contributor I
Brilliant, that sounds like it would work.
 
Thanks alot Mark.
 
cmag
0 Kudos
Reply