--0__=TiO8dPv70VNi1wmQr1GkYoeAwKST1u2E5sapSvoCyvDJI1PBVmgeHPp1 Content-type: text/plain; charset=us-ascii Here is my code for testing the I2C master software. The program tests the device at adress 0xA0 and sets PortA bit 0 when SlaveActive bit is set. As far as I can see, this should work out fine. The two files included are from AN554. (See attached file: I2C_MAST.ASM) Regards Steen Jensen From: keithh@ARCAM.CO.UK on 04-02-98 12:20 GMT Please respond to PICLIST@MITVMA.MIT.EDU To: PICLIST@MITVMA.MIT.EDU cc: (bcc: Steen Schelle Jensen/Sales/DK_GDK/Grundfos) Subject: Re: I2C with AN554 code Steen Jensen wrote: > I have included some code from AN554 in my program. > I have followed the test examples from Microchip, > but my program does not work I'm not surprised. Their app notes are pretty poor. I started from their AN557, and that has fundamental bugs. If the slave holds SCL low to wait-state the (PIC) master, then the AN557 code thinks this is an error state. I modifed the code to wait until SCL was high, and extended my application to handle errors properly. For example, if arbitration fails (SDA conflict) then back off and retry sending message from the start, and if negative ack, terminate message. If you tell us about the application & malfunctions, we may be able to guess a diagnosis. Good luck. BTW, not waiting for SCL to rise is a mistake one of my colleagues made in his code. Certain bits were misbehaving repeatably. He ran his code on his emulator, it got the data my PIC had sent. "Not my bug" he said. I wasted weeks combing my code for bugs. Eventually I said "look at the storage scope - the signals look perfect. Just what the F*** is wrong with it?". So he puts his emulator on, single steps, and no malfunction. Run in real time, malfunction. "Okay, maybe a timing bug" he says. Within 20 mins he notices his make-SCL-high macro does not wait for it to do so. Changed it to wait, malfunction vanishes! Next time it won't be my head I bash against the wall! --0__=TiO8dPv70VNi1wmQr1GkYoeAwKST1u2E5sapSvoCyvDJI1PBVmgeHPp1 Content-type: application/octet-stream; name="I2C_MAST.ASM" Content-transfer-encoding: base64 O0kyQy1CVVMgTUVEIFBJQyBTT00gTUFTVEVSDQoNCjtSQjEgaXMgU0RBCQkoQW55IEkvTyBQaW4g TWF5IEJlIHVzZWQgaW5zdGVhZCkNCjtSQjAgaXMgU0NMCQkoQW55IEkvTyBQa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