matherp Registered User

Joined: 31 May 2011 Posts: 31 Location: Cambridge
|
Posted: Sun Jun 19, 2011 12:00 pm Post subject: I2C bus locked up - my solution |
|
|
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
|
|
|