Menu

i2c pic slave sending to i2c pic master

Help
Chris
2012-02-03
2013-05-30
  • Chris

    Chris - 2012-02-03

    I'm having a problem sending data from an i2c slave (pic 16f616) to an i2c master (pic 16f616). I have no problem sending from master to slave, but when I try to receive from the slave I always get 0's. I can receive data from an i2c eeprom so i'm thinking it's a problem in the i2c slave send part of the i2c.h or maybe im not doing something right. Here is my code:
    Master code

    ;Chip Settings
    #chip 16F616,8
    #config OSC=INTRC_OSC_NOCLKOUT, MCLRE=OFF
    ;Defines (Constants)
    #define SendAHigh porta.1= on
    #define SendALow porta.1 = off
    #define RecAHigh porta.2 on
    #define RecALow porta.2 off
    #define I2C_MODE Master
    #define I2C_DATA PORTA.4
    #define I2C_CLOCK PORTA.5
    ;Variables
    Dim ValueIn As byte
    InitSer 1, r4800, 1, 8, 1, None, Invert
    Do Forever
        Wait 250 ms
        I2CStart
        I2CReceive ValueIn
        I2CStop
        SerPrint 1, ValueIn
    Loop
    

    Slave code

    ;Chip Settings
    #chip 16F616,8
    #config OSC=INTRC_OSC_NOCLKOUT, MCLRE=OFF
    ;Defines (Constants)
    #define I2C_MODE slave
    #define I2C_DATA porta.5
    #define I2C_CLOCK porta.4
    Do Forever
        I2CStart
        I2CSend 5
        I2CStop
    Loop
    
     
  • Chris

    Chris - 2012-02-03

    I seem to have found the problem. inside the i2c.h file, in the part where it sends as slave it has this line of code

    I2CByte = 0
    I removed that and now its sending what it should. maybe someone should make a note of this, and why was this is there to begin with?

     
  • Edward LaBudde

    Edward LaBudde - 2012-02-03

    Bowlofpudding, I was just getting interested in trying out the I2C function when you made your post.  I was able to verify your results using a 16F88 using ports b.0 and b.1.  It was interesting that I had to enable the weak pullups before it would work?   That verifies that the I2C.h file is in error.  Thanks for your tip.  Ed

     
  • Chris

    Chris - 2012-02-18

    yeah i used actual pullups in my circuit, either 10k or 100k i forget which, one on data and one on clock. i only just now learned how to enabled weak pull ups which were helpful to eliminate the physical ones for my buttons

     
  • Nobody/Anonymous

    Hi, sorry to thread hijack but how do you use the internal weak pull up resistors?

    thanks Dan

     
  • Nobody/Anonymous

    i should have mentioned its a 16F77.

     
  • Chris

    Chris - 2012-08-01

    according to your datasheet, only port B has internal pull ups, and they cant be individually set. so if you want to set one, you have to set them all. configure them as inputs and put this line of code in Great Cow Basic
    <code>
    Set NOT_RBPU Off
    </code>

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.