Swordfish Forum Index Swordfish
Structured BASIC for PICŪ Microcontrollers
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  
modules, sample code and more...

I2C bus locked up - my solution

 
Post new topic   Reply to topic    Swordfish Forum Index -> Modules
View previous topic :: View next topic  
Author Message
matherp
Registered User
Registered User


Joined: 31 May 2011
Posts: 31
Location: Cambridge

PostPosted: Sun Jun 19, 2011 12:00 pm    Post subject: I2C bus locked up - my solution Reply with quote

When repeatedly programming a chip it is occasionally the case that an i2c peripheral is in the middle of a write when the re-programming takes place. If the peripheral chip is holding SDA low then the i2c start condition will not work to reset the peripheral and the program will probably not run properly until a power-off/power-on.

The following minor change to i2c.Initialize appears to solve this.

Code:

****************************************************************************
* Name    : Initialize                                                     *
* Purpose : Initialize SSP module for I2C bus                              *
****************************************************************************
}         
Public Sub Initialize(pBaudrate As Byte = I2C_100_KHZ, pSlew As Byte = I2C_SLEW_OFF)
  SSPAddress = pBaudrate     // set baudrate
  SSPStatus = pSlew          // POR state, optional slew
  SSPControl2 = $00          // POR state
  Input(SCL)                 // set SCL (clock pin) to input
  Input(SDA)                  // set SDA (data pin) to input
// clear locked up peripheral
  If SDA<>1 Then //there must be an i2c device holding SDA low
    Output(SCL)
    While SDA<>1 //clock in bits from the stuck peripheral until SDA is high
        Low(SCL)
        DelayUS(100)
        High(SCL)
        DelayUS(100)
    Wend
    Input(SCL)    // set SDA (data pin) to input
  EndIf
//
  SSPControl1 = $28          // master mode, enable synchronous serial port
End Sub
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Swordfish Forum Index -> Modules All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group