SMBus, SBS, I2CWrite, I2CRead


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Jun 2015
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: SMBus, SBS, I2CWrite, I2CRead

    This is kind of a new direction, but people on this thread may be curious - I am trying to program a smart battery (smbus master), to recognize whether or not a level 2 smart charger (smbus slave) is attached to it. I figure if the charger is not there, I could look for an acknowledge bit to be false when I send the charger address. The problem is, the ACKSTAT bit never sets and is always low (asserted) with no charger present. I thought it would be easy because the master is just talking to an open bus (with pullups attached), but it won't work for me. Here is my code:

    SSP1CON1 = %00101000 'MSSP1 is the smbus master
    SSP1CON2 = %00000000 'default
    SSP1ADD = $27 'baud rate for 100KHz smbus (16 MHz osc, PIC18F67K90)

    SSP1IF = 0 'reset interrupt flag
    WCOL = 0 'clear the collision flag
    SEN = 1 '(SSP1CON2.0) initiate smbus START
    DO WHILE SEN = 1 'wait for start delay to complete
    LOOP
    SSP1BUF = $12 'send address 18 (level 2 smart charger)
    SSP1IF = 0 'reset interrupt flag
    DO WHILE BF = 1 'wait for buffer to empty
    LOOP
    IF ACKSTAT = 1 THEN.....(skip smart charger module)

    The hardware is functioning correct - the /ACK bit is high at the falling edge of the ninth clock with no charger. I tried to use I2CWRITE but it hangs up for some reason and my 1 second watchdog resets the pic.

  2. #2
    Join Date
    Jun 2015
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: SMBus, SBS, I2CWrite, I2CRead

    Solved my own problem! I have to wait at least 1 clock pulse (15 usec) after the BF flag resets (buffer is empty) before looking at ACKSTAT, to allow the ninth clock pulse to complete. My fix:

    SEN = 1 '(SSP1CON2.0) initiate smbus START
    DO WHILE SEN = 1 'wait for start delay to complete
    LOOP
    SSP1BUF = $12 'send address 18 (level 2 smart charger)
    SSP1IF = 0 'reset interrupt flag
    DO WHILE BF = 1 'wait for buffer to empty
    LOOP
    PAUSEUS 15
    IF ACKSTAT = 1 THEN.....(NACK - skip smart charger module)

  3. #3
    Join Date
    Aug 2011
    Posts
    461


    Did you find this post helpful? Yes | No

    Default Re: SMBus, SBS, I2CWrite, I2CRead

    After you write to the SSPBUF if you wait for SSPIF instead of BF then ACKSTAT will be valid.

  4. #4
    Join Date
    Nov 2003
    Posts
    98


    Did you find this post helpful? Yes | No

    Default Re: SMBus, SBS, I2CWrite, I2CRead

    great stuff H & T thanks for the info
    i need to learn more about handling the MSSP hardware directly as you are showing

  5. #5
    Join Date
    Jun 2015
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: SMBus, SBS, I2CWrite, I2CRead

    T- I tried waiting for the SSP1IF interrupt, but it never happened! The pic spec indicates that you clear it after the start condition is complete (SEN = 1) and you have written to SSP1BUF (PIC18F87K90 Family figure 21-23), but maybe I have to clear it before writing to the buffer.

    D - I prefer to talk directly to the MSSP module because I2CWRITE wouldn't let me send just an address and look for a NACK.

  6. #6
    Join Date
    Aug 2011
    Posts
    461


    Did you find this post helpful? Yes | No

    Default Re: SMBus, SBS, I2CWrite, I2CRead

    I tried waiting for the SSP1IF interrupt, but it never happened!
    Hmm. After you initiate the START (SEN=1) and then wait for SEN to go low (SEN=0) you should be able to clear SSPIF before you write to the SSPBUF.

    If you look at that figure once you write to the SSPBUF you'll see BF being asserted on the 8th clock, but SSPIF isn't asserted until the 9th after the ACK.

Similar Threads

  1. i2cRead i2cwrite very frustrating
    By bradb in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th September 2011, 20:48
  2. I2cwrite - I2cread
    By savnik in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 5th July 2006, 01:12
  3. I2Cwrite and I2CRead speed!
    By Najim in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd November 2005, 10:54
  4. I2Cwrite and I2CRead speed!
    By Najim in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd November 2005, 10:50
  5. I2CWRITE and I2CREAD
    By Tomas in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd April 2004, 02:30

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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