Change I2C bitrate on LPC21

This commit is contained in:
Christophe De Wagter
2011-11-25 14:59:11 +01:00
parent 3eae92fa9e
commit fcf199be5e
+38 -1
View File
@@ -342,6 +342,43 @@ bool_t i2c_submit(struct i2c_periph* p, struct i2c_transaction* t) {
}
void i2c_event(void) { }
void i2c2_setbitrate(int bitrate __attribute__ ((unused))) { }
void i2c_setbitrate(struct i2c_periph* p, int bitrate)
{
int period = 15000000 / 2 / bitrate;
// Max 400kpbs
if (period < 19)
period = 19;
// Min 5kbps
if (period > 1500)
period = 1500;
/* default clock speed 37.5KHz with our 15MHz PCLK
I2C1_CLOCK = PCLK / (I2C1_SCLL + I2C1_SCLH) */
#if (PCLK == 30000000)
period *= 2;
#endif
#if (PCLK == 60000000)
period *= 4;
#endif
#ifdef USE_I2C0
if (p == &i2c0)
{
/* set bitrate */
I2C0SCLL = period;
I2C0SCLH = period;
}
#endif
#ifdef USE_I2C1
if (p == &i2c1)
{
/* set bitrate */
I2C1SCLL = period;
I2C1SCLH = period;
}
#endif
}