PhilWinder
Joined: 16 Apr 2005 Posts: 23
|
Questions regarding "Mark's" I2C communication rou |
Posted: Sun Dec 10, 2006 9:40 am |
|
|
[Note: the link to the code is here]
Hi, first off, this code is pretty impressive.
As you probably know, its quite hard to interpret other people's code. So far I have it basically working with a 18f2520 as a master and a 16F88 as a slave, and I have also tested it the other way round, so it does work as a multi-master solution.
The only problem lies somewhere within the 16f88 code, when in the section where you interpret the input commands ( I2C_Process_Message() ), after the example blink_led function, a command to send a message back to blink the original senders LED. I.e.
Code: |
if (PORTAbits.RA0) output_low(PIN_A0); // Slightly changed so when the command is sent, it just inverts the LED
else output_high(PIN_A0);
Blink_Back_LED(0x6E, 14); // Send a I2C message back to the "master" Pic.
|
Basically, when it comes round to actually sending the new message back via the tasks routine, then into the Tx routine, it does not send the message because the SDA line is still low (active state) (i.e. it hasnt been reset to the high impedance state), and returns a collision error.
Now, if I remove the blink back LED routine, and run it normally (no debug) then the line does return to the High Z state, eventually (note it is not quick enough to send the message). BUT, if I debug (the slave) it and step through the code (breaking just after it has recieved the full message), the LED comes on ok (on the slave) and the line NEVER returns to High Z; even if I set it to run again.
I am using Hardware on the 18F and software on the 16F.
Any Ideas/Questions?
Cheers,
Phil
P.s. It is also tested to have happened the other way round. it fails at this point (when stepping)
Code: |
if (I2C_State != I2C_IDLE)
return(FALSE);
|
|
|