Skip to content

Commit

Permalink
Reduce I2C clock speed by factor 2 to workaround Broadcom 2853 I2C cl…
Browse files Browse the repository at this point in the history
…ock timing bug.
  • Loading branch information
nieklinnenbank committed Nov 2, 2015
1 parent 8400316 commit 2911c58
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/libi2c/BroadcomI2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ BroadcomI2C::Result BroadcomI2C::initialize()
// Set GPIO pins to ALT0 function for SDA, SCL pins
m_gpio.setAltFunction(2, BroadcomGPIO::Function0);
m_gpio.setAltFunction(3, BroadcomGPIO::Function0);

// Set a slow clock to attempt workaround the I2C bug in Broadcom 2835
setClockDivider(0x5dc * 2);
NOTICE("I2C GPIO pins set");
NOTICE("ClockDivider is " << m_io.read(ClockDivider));
NOTICE("Status is " << m_io.read(Status));
Expand All @@ -52,6 +55,12 @@ BroadcomI2C::Result BroadcomI2C::setAddress(Address addr)
return Success;
}

BroadcomI2C::Result BroadcomI2C::setClockDivider(Size divider)
{
m_io.write(ClockDivider, divider);
return Success;
}

BroadcomI2C::Result BroadcomI2C::write(u8 *buf, Size size)
{
if (size > FIFOSize)
Expand Down
11 changes: 11 additions & 0 deletions lib/libi2c/BroadcomI2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
*
* @see BCM2835 ARM Peripherals.pdf
* @see http://www.airspayce.com/mikem/bcm2835/
* @see https://github.com/raspberrypi/linux/issues/254
* @see https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=13771&start=25
* @see http://www.advamation.com/knowhow/raspberrypi/rpi-i2c-bug.html
*/
class BroadcomI2C : public I2C
{
Expand Down Expand Up @@ -103,6 +106,14 @@ class BroadcomI2C : public I2C
*/
virtual Result initialize();

/**
* Set clock divider.
*
* @param divider Clock divider to use.
* @return Result code.
*/
virtual Result setClockDivider(Size divider);

/**
* Set Slave address.
*
Expand Down

0 comments on commit 2911c58

Please sign in to comment.