Searching \ for '[PIC:] I2C woes' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/i2cs.htm?key=i2c
Search entire site for: 'I2C woes'.

Exact match. Not showing close matches.
PICList Thread
'[PIC:] I2C woes'
2004\06\22@045341 by Jinx

face picon face
part 1 1719 bytes content-type:text/plain; (decoded 7bit)

My first foray into I2C on the F452 is turning into something of
a test of patience. Bit-banging on older PICs worked out OK.
I've not used its MMSP before, but I thought I'd done enough
reading beforehand to get it going. Set up code shown below.

I just can't get a low ACK from the slave on the 9th clock and
the whole thing stalls

What piece of the jigsaw am I missing ? I've tried a heap of
arrangements but the analyser grab always looks depressingly
the same ;-(((

PCB traces are ~ 50mm (SDA signal on pin 5, SCL pin 6), 5V,
2k2 pullups on each, 0.1uF ceramic across 5V/0V pins, no noise
detected on Vcc

TIA

        mov     b'11011000',trisc  ;SDA, SCL as i/p

;        Read address A3
;        Write address A2

        mov     b'00101000',sspcon1
;                    1               SSPEN
;                      1000          master

        mov     b'10000000',sspstat
;                  1                 slew rate off

        mov     0x61,sspadd        ;I2C baud rate, 100kHz

        bsf     portb,3      ;analyser trigger
        nop
        bcf     portb,3

        bsf     startb       ;send start bit
        btfsc   sspcon2,sen
        bra     $-2

        mov     0xa2,sspbuf  ;slave address
        btfsc   sspstat,r_w
        bra     $-2

        bsf     portb,3

        btfsc   sspcon2,ackstat   ;wait for ACK
        bra     $-2

        bcf     portb,3        ;never happens

==============================================
Research is what I'm doing when I don't know what I'm doing
- Wernher von Braun

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.




part 2 1279 bytes content-type:image/gif; (decode)

2004\06\22@052702 by Jinx

face picon face
I think I may have found the problem. Being the persistent type
and double-checking that the IC is still alive I prodded around
with the scope and found that Reset was low, even though it
has a pullup. There was the minutest solder bridge to 0V under
some flux. Man, I had to look hard for it, but it's gone now and
the code flow has improved markedly. Well, it would do wouldn't
it ?

Now, Ken, should I still trust myself after working all day with a
chip that's been in flipping reset ? 8-O

BTW, if anyone does still see room for improvement in the
posted code that would be appreciated

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2004\06\22@055025 by ISO-8859-1?Q?Ruben_J=F6nsson?=

flavicon
face
> I think I may have found the problem. Being the persistent type
> and double-checking that the IC is still alive I prodded around
> with the scope and found that Reset was low, even though it
> has a pullup. There was the minutest solder bridge to 0V under
> some flux. Man, I had to look hard for it, but it's gone now and
> the code flow has improved markedly. Well, it would do wouldn't
> it ?
>
> Now, Ken, should I still trust myself after working all day with a
> chip that's been in flipping reset ? 8-O
>
> BTW, if anyone does still see room for improvement in the
> posted code that would be appreciated

What about a timeout when waiting for the ack?

If the slave doesn't respond (due to being busy with a previous request or being disturbed by noise) the code will hang forever waiting for an ack that will never come.

Regards / Ruben
==============================
Ruben Jönsson
AB Liros Electronic
Box 9124, 200 39 Malmö, Sweden
TEL INT +46 40142078
FAX INT +46 40947388
spam_OUTrubenTakeThisOuTspampp.sbbs.se
==============================

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2004\06\22@061332 by Jinx

face picon face
> BTW, if anyone does still see room for improvement in the
> posted code that would be appreciated

What about a timeout when waiting for the ack?

Yes, thanks. I'd been looking through MC's error handling
examples, but of course that assumes you're working with
a slave that's actually conscious !

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2004\06\22@061953 by hael Rigby-Jones

picon face
{Quote hidden}

If you look at the timing diagrams for master mode transmission, the RW bit
is only cleared after the ACK bit has been clocked in.  Therefore the loop
waiting for the the ACKSTAT bit to become set is not required, the ACKSTAT
bit is valid as soon as RW has cleared.  In fact this loop will cause the
code to hang if the slave does not ACK your request, as you have noticed.

Also, you have an 18F part but you are doing bit operations on the PORTx
register instead of the LATx register (I know it's only for debugging, but
debugging your debugging code is quite frustrating IME...).

Regards

Mike




=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================
Any questions about Bookham's E-Mail service should be directed to
.....postmasterKILLspamspam.....bookham.com.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2004\06\22@073226 by Jinx

face picon face
Thanks for your comments Mike. I very well could have had the
correct code in an earlier attempt, but got seriously waylaid by
my failure to spot the reset problem. Now that it is going past
byte 1 I can start proper debugging

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...