• AVR Freaks

PIC16F18313 I2C Slave Operation, Cannot Transmit to Master

Author
teranz
Starting Member
  • Total Posts : 36
  • Reward points : 0
  • Joined: 2019/03/06 21:45:25
  • Location: 0
  • Status: offline
2019/06/11 21:59:03 (permalink)
0

PIC16F18313 I2C Slave Operation, Cannot Transmit to Master

Hi:
I have been able to use the PIC16F18313 and similar mpu`s in I2C Master mode, but this is my first attempt using it as a slave.  For some reason I cannot get the transmission of data to the master to work... The following is info from the data sheet:
 
Following the ACK, slave hardware clears the CKP bit and the SCL pin is held low (see Section 30.5.6 “Clock Stretching” for more detail). By stretching the clock, the master will be unable to assert another clock pulse until the slave is done preparing the transmit data. The transmit data must be loaded into the SSP1BUF register which also loads the SSP1SR register. Then the SCL pin should be released by setting the CKP bit of the SSP1CON1 register. The eight data bits are shifted out on the falling edge of the SCL input. This ensures that the SDA signal is valid during the SCL high time.
 
I receive my slave address with the R/W bit = 1, and at this time the SCL line is held low as expected.  I load the SSP1BUF with my LSB value and set the CKP = 1.  The SCL line goes high but the transmission appears to never happen, there are no SCL clock pulses.  Here is the "rough" code I am using in the ISR just to get things going:

 
// ********************************************
// Look for our slave address and READ bit set...

while(!i2c1_driver_isBufferFull());     // Wait while address receive in progress

data[2] = SSP1BUF;                        // Read the slave address with the R/W = 1.

// ********************************************
// Send data to Host (Master) 75 degrees F = 0x0129 degrees K
// Send LSB...
 
This is where it stops working.  Using the PicKit4 and the latest MPLAB IDE v5.15 I am monitoring SSP1BUF.  When I load the value 0x29 into SSP1BUF it never shows in the IDE variable list with this value.  Using a scope on the SCL and SDA lines there is no activity when I set the CKP = 1, the line just stays high.   Shouldn`t this allow the master to clock the data to itself?

SSP1BUF = 0x29;                       // Send LSB
SSP1CON1bits.CKP = 1;              // Enable clock
while(i2c1_driver_isBufferFull()); // Wait while data transmit in progress
while(i2c1_driver_isNACK());      // Wait for ACK from Master.
 
// Now Send the MSB...
 
Any help appreciated...
Tom
#1

4 Replies Related Threads

    ric
    Super Member
    • Total Posts : 22310
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16F18313 I2C Slave Operation, Cannot Transmit to Master 2019/06/11 22:33:39 (permalink)
    +1 (1)
    What is acting as the Master?
    Not all Masters observe clock stretching, so if you've held the signal low for an excessive time, it may have just proceeded without you.
     

    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!
    #2
    teranz
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2019/03/06 21:45:25
    • Location: 0
    • Status: offline
    Re: PIC16F18313 I2C Slave Operation, Cannot Transmit to Master 2019/06/12 06:16:56 (permalink)
    0
    My project is creating my own "Laptop Smart Battery"... a learning project.  The host computer is an HP dv6-2150US.  I can operate as a I2C master and communicate with the battery just fine.  The specs for the SMBus indicate the players (Smart Charger, Smart System Manager, Smart Battery) should all follow the I2C standard closely except the signal levels can be a little different.  There should be no reason I need to use clock stretching at this point but I will experiment with the potential delays more.  I am using the CKP line with receiving the command and address (one for write, one for read) without issue, just an issue sending data to the master.
     
    UPDATE: By setting AHEN=0 and DHEN=0 in SSP1CON3 the data writing to the master is now working.
    post edited by teranz - 2019/06/12 07:41:37
    #3
    ric
    Super Member
    • Total Posts : 22310
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16F18313 I2C Slave Operation, Cannot Transmit to Master 2019/06/12 06:51:04 (permalink)
    +1 (1)
    You should have mentioned this is SMBUS to start with.
    There are more differences than just voltage levels. SMBUS has speed and time liimits that normal I2C does not.
    https://en.wikipedia.org/wiki/System_Management_Bus
     

    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!
    #4
    teranz
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2019/03/06 21:45:25
    • Location: 0
    • Status: offline
    Re: PIC16F18313 I2C Slave Operation, Cannot Transmit to Master 2019/06/12 08:53:26 (permalink)
    0
    Thanks, I will look into the differences...
    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5