??? 08/21/10 11:31 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#178173 - Stop fooling yourself Responding to: ???'s previous message |
Must I repeat myself?
Your master may repeat, if it doesn't get data. But your slave does not synchronize with any repeat, with less than receiving a request to restart. You do not implement a communication protocol that requires the slave to restart from the reset vector (which isn't even a proper reset). You implement a protocol where the slave rests the transmit state (normal variables, not full processor state) as soon as it receivers a new request from the master. Whenever it sees a transfer with the 9th bit set, the slave should synchronize. - If the received address was for another slave, then the slave should stop sending any data, and clear the send state. - If the received address was for this slave and a request for data, the slave should either restart (from first byte) the previous data transfer, or (if last transfer was sent in full including receiving an acknowledge) start with the first byte of the next packet of data. Don't spend so much time explaining that your code works. Your system that you are testing the code on should be proof enough that the code does not work. So wehen someone points out a synchronization problem with the code, you shouldn't be so quick to explain to me that it works, but onstead spend time proving to yourself if it really works or not. You have described your slave logic as: SEND SLAVE PROTOCOL START BYTE - WAIT FOR DATA ACKNOWLEDGE SEND DATA FRAME TYPE BYTE (TB8 = 0) - WAIT FOR DATA ACKNOWLEDGE SEND DATA BYT - WAIT FOR DATA ACKNOWLEDGE SEND DATA BYTE - WAIT FOR DATA ACKNOWLEDGE SEND SLAVE PROTOCOL END BYTE - WAIT FOR DATA ACKNOWLEDGE It should be described as: 1) Send slave protocol start byte 2) Wait for acknowledge. a) If acknowledge received, go to 3. b) If timeout - fail transfer, and wait for master to address slave again. c) If other than acknowledge - fail transfer, and wait for mater to address slave again. 3) Send data byte 4) Wait for acknowledge a) If acknowledge received, go to 5. b) If timeout - fail transfer, and wait for master to address slave again. c) If other than acknowledge - fail transfer, and wait for mater to address slave again. .. Solve your problems instead of convincing yourself that the code is already working. Isn't the lockups you are seeing already proof that the code is not working? Right now, your slave code does not synchronize with the master unless you force it to reset. That is because the slave code logic is broken, having while loops forcing a full message to be sent even if the communication gets a failure in the middle of the data byte sequence. |