I have been using PICs & PBP for the past 5 years and I consider this forum to be the best when it comes to providing useful tips, guidance and help.
My current issue : I am writing code in which the PIC should receive data through RS232 from one device and send it out through I2C to another device.
First I wrote the code in such a way that the PIC is the master. After having received the data (64 bytes) through RS232, it sends it to the other device through I2C. In this configuration, the PIC is the master and initiates I2C communication. The other device is the slave and keeps waiting for the data. This worked satisfactorily.
But I need to reverse the roles. For the I2C communication, the other device will be the master and whenever it queries, the PIC should send data to the master. How do I write I2C code in such a way that the PIC waits and sends data to the master whenever it asks for it? The PIC used is 16F688. In the software implementation of I2C in PBP, there are only two commands: I2CWRITE and I2CREAD and both seem to be those used by the master. In the code shown below, if the acknowledement signal is not received, it tries again and again. Will it work? (I cannot at the moment connect to the other device and check my code.)
GOTO START
NO_ACK:
START:
FOR Count = 0 to 63
I2CWRITE SDA,SCL,%10100000,0,DataOut[Count],NO_ACK
NEXT Count
END
Any help / guidance is highly appreciated.
Regards,
Bala
Bookmarks