Code for I2C Slave


Closed Thread
Results 1 to 4 of 4
  1. #1
    Balachandar's Avatar
    Balachandar Guest

    Default Code for I2C Slave

    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

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Please do a forum SEARCH on 'I2CSlave' and you will eventually find links to code and examples to play with...

  3. #3
    Balachandar's Avatar
    Balachandar Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks, Melanie.

    But no luck. What I am looking for is a software implemtation of I2C for a slave that can be used in PICs like 16F688 that don't have a Synchronous Serial Port. All the links that I could find pertain to those PICs that have an SSP.

    Regards,
    Bala

  4. #4
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Exclamation

    All my work with I2C shows me:

    I2C-master could be done by hardware or software and speed doen't matter.

    I2C-slave could only be done by hardware. The slave must react very fast on every bit....
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts