Rudy said: > Well, it workes. As long as > the master sends a known number of bytes. > > And that's my problem. I do not know how many bytes the Master will send. Yes, that's true in general. In a slave-write (PIC slave reading data from master), the PIC slave does not know how many bytes the master will send, and must either ACK every byte, or NACK them so the master will know you failed. You can pre-arrange the desired number of bytes, but data corruption can always make it seem more or less, so your software is more robust if it can handle any number of bytes. What I do in my slave-only code is have a buffer which can hold a few more than the expected number of bytes, and if the buffer fills, stop sending ACK, so the master can detect the failure. He sends STOP, and then tries again in another complete transaction. > My solution was to incoorporate the Start & Stop-bits into the program. Yes, that's important, especially in slave-transmit mode, where the master WILL clock in as many bytes as it wants. If you stop loading bytes when the master is asking for more, the PIC will leave SCL locked low and crash the bus forever. So you've got to be prepared to send dummy bytes for the "extra" data byte requests, until you get an interrupt that has the STOP bit set, so you know you're done. > Well, I can detect the Stop-condition all-right, but the combination of > bits in the SSPSTAT register for a Start-condition seems to be the same as > when a NACK is send (well, I mean an ACK is *not* send :-) I don't understand. There are seperate bits for START and STOP. What bit pattern are you seeing that tells you that the master sent a NACK? I think the only way you know that the last byte was NACKed is that the SSP does not ask you for another byte, because the master NACKs the last byte to say it it done. You get an interrupt for the last data byte requested, then later get an interrupt with STOP set. The NACK of the last byte is not really indicated by the SSP (I wish it was). Regards, Barry. ------------ Barry King, KA1NLH NRG Systems "Measuring the Wind's Energy" http://www.nrgsystems.com Check out the accumulated (PIC) wisdom of the ages at: PIC/PICList FAQ: http://www.piclist.org -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! use mailto:listserv@mitvma.mit.edu?body=SET%20PICList%20DIGEST