• AVR Freaks

Hot!Can I2C slave send command to Master? Using 16F18323

Author
teranz
Starting Member
  • Total Posts : 51
  • Reward points : 0
  • Joined: 2019/03/06 21:45:25
  • Location: 0
  • Status: offline
2019/06/26 06:47:28 (permalink)
0

Can I2C slave send command to Master? Using 16F18323

Hi:
I am using a 16F18323 as an I2C slave and it is working well.  I have also used it as a master.  I have read that it is possible to send a command from a slave to the master, is that possible?  Do it require special coding?  Before I start spending time on this I wanted to get this question resolved.
 
Thanks-
#1

14 Replies Related Threads

    Jim Nickerson
    User 452
    • Total Posts : 6034
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 07:27:41 (permalink)
    +3 (3)
    teranz
    I have read that it is possible to send a command from a slave to the master

    Please do share a link as to where you might have read this ?
    #2
    teranz
    Starting Member
    • Total Posts : 51
    • Reward points : 0
    • Joined: 2019/03/06 21:45:25
    • Location: 0
    • Status: offline
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 08:10:51 (permalink)
    0
    Continued reading supports a slave is only a slave, period.  I get this, but somewhere in my reading related to using ardunio systems it was suggested by someone that they in fact could send commands from a slave.  There was obviously something else going on.
    Adding to this...
    I should also mention I am using (successfully) the PIC16F18323 to communicate on the SMBus of a computer.  The mpu can communicate to the Battery Pack as a master (outside of the computer), and can function as a battery controller in slave mode.  The SMBus spec has a condition called "SMBus Host Notify protocol" when the slave can send commands (notifications) to the master (host).  Again, I suspect there is more going on that I am unaware of but this concept gave me hope the slave could in fact operate as a master.
    I am rethinking now and may use a part that has two separate I2C channels to accomplish what I want.
     
    Tom
    #3
    Antipodean
    Super Member
    • Total Posts : 1713
    • Reward points : 0
    • Joined: 2008/12/09 10:19:08
    • Location: Didcot, United Kingdom
    • Status: online
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 08:38:17 (permalink)
    +1 (1)
    Look at the I2C specification for details of multi-master operation, then read the microchip family reference manual for the I2C periheral for your chip and see how to set it up for that mode.
     
     

    Do not use my alias in your message body when replying, your message will disappear ...

    Alan
    #4
    teranz
    Starting Member
    • Total Posts : 51
    • Reward points : 0
    • Joined: 2019/03/06 21:45:25
    • Location: 0
    • Status: offline
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 09:35:35 (permalink)
    0
    Thanks... will do.
    #5
    NKurzman
    A Guy on the Net
    • Total Posts : 17519
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 09:42:30 (permalink)
    0
    Some Application have an extra connection from the Slave to the Master.  This Notifies the Master the The Slave has Data for it.
     
    Multi-Master is for more than on Master to talk to a slave (or Slaves) Have Then switch back and forth is possible, but not simple.
    #6
    teranz
    Starting Member
    • Total Posts : 51
    • Reward points : 0
    • Joined: 2019/03/06 21:45:25
    • Location: 0
    • Status: offline
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 10:23:50 (permalink)
    0
    In my project the slave (using the 16F18323) is monitored by the computer`s SMBus controller (no alert line I can access).  I was wanting the slave to be able to monitor a separate I2C-capable battery gas gauge, then the slave would report that info back to the SMBus master.  I have started reading the 16F18313 data sheet for accomplishing multi-master mode, it seems the 2 I2C ports would be so much easier and not so error prone.  I will be considering the PIC16F18326 and 18346 MPUs.
     
    UPDATE: I understand now.... multiple masters ok, switching between the operating modes not so ok.
    post edited by teranz - 2019/06/26 10:26:44
    #7
    teranz
    Starting Member
    • Total Posts : 51
    • Reward points : 0
    • Joined: 2019/03/06 21:45:25
    • Location: 0
    • Status: offline
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 10:36:29 (permalink)
    0
    Apparently others have tried (and succeeded) at doing what I want, here is posting title:

    switching bewteen I2C master and slave

    As I was told it would not be easy, but can be done through firmware bit-banging.
    post edited by teranz - 2019/06/26 10:38:13
    #8
    ric
    Super Member
    • Total Posts : 22767
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 13:22:21 (permalink)
    +1 (1)
    teranz
    As I was told it would not be easy, but can be done through firmware bit-banging.

    If you're going to implement bit-banging, use it to create a second I2C port.
    It's much easier to bit bang a Master than a Slave.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    NKurzman
    A Guy on the Net
    • Total Posts : 17519
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 14:13:27 (permalink)
    0
    1. You Shut down the MSSP.  You reconfigure it as the Master.  You make sure you handle Multi Master.  You send you Message. You Shut down the MSSP.  You reconfigure it as the Slave.
    2.Yes 2 I2C Ports makes it easier.
     
    3. What SMBus Messages will you be sending to the Host?  Is your 16F18323  the Battery? or a Charger?  Or are these custom?
    #10
    teranz
    Starting Member
    • Total Posts : 51
    • Reward points : 0
    • Joined: 2019/03/06 21:45:25
    • Location: 0
    • Status: offline
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 14:30:39 (permalink)
    0
    I don`t plan on sending notifications to the SMBus host, just wanted to poll the values in the LI-ion gas gauge chip, another slave.
    #11
    ric
    Super Member
    • Total Posts : 22767
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 15:00:57 (permalink)
    0
    Ahh, so the "host" needs to talk to the same slave?
    In that case you do need to do it as multi master, but that will only work if the host is also designed to work with another Master, which is not guaranteed if it wasn't in the original design brief.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #12
    mbrowning
    Just a Member
    • Total Posts : 1432
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: online
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 15:54:51 (permalink)
    0
    SMBus masters that conform to the specs need to support the “host notify” protocol wherein a slave becomes the master and sends its address to the master. Basically an alert without a separate wire

    Oh well - there's always next year
    #13
    NKurzman
    A Guy on the Net
    • Total Posts : 17519
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/26 16:41:05 (permalink)
    0
    If you bit bang the I2C master on a real SMBus you will need to disable interrupts. The bus has tight timing specs. You can easily lose the bus and weird things happen.
    #14
    P Lameijn
    Super Member
    • Total Posts : 1966
    • Reward points : 0
    • Joined: 2004/01/22 18:30:23
    • Location: The Netherlands
    • Status: online
    Re: Can I2C slave send command to Master? Using 16F18323 2019/06/27 05:27:48 (permalink)
    0
    A lot of i2c libraries are blocking if something unexpected happens.
    (they indefinitely wait for some bit to set or clear what never happens, they don't check for errors)
     
    For slave implementation on a pic I found it very helpful to start with mimicking a 'known' i2c slave like the PCF8574.  (you can test until both behave exactly the same)
     

    Regards,
    Peter
    #15
    Jump to:
    © 2019 APG vNext Commercial Version 4.5