From f6972a43581b24281b322a6f8d2bf02dafbe4433 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 16 Aug 2018 12:58:24 +0200 Subject: configurable i2c bitrate on arduino nano --- src/arch/arduino-nano/Makefile.inc | 4 ++++ src/arch/arduino-nano/driver/i2c.cc | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src/arch') diff --git a/src/arch/arduino-nano/Makefile.inc b/src/arch/arduino-nano/Makefile.inc index d481fa2..18a6563 100644 --- a/src/arch/arduino-nano/Makefile.inc +++ b/src/arch/arduino-nano/Makefile.inc @@ -32,6 +32,10 @@ ifneq ($(findstring stdin,${arch_drivers}), ) TARGETS += src/arch/arduino-nano/driver/stdin.cc endif +ifneq (${i2c_freq}, ) + COMMON_FLAGS += -DF_I2C=${i2c_freq} +endif + OBJECTS = ${TARGETS:.cc=.o} .cc.o: diff --git a/src/arch/arduino-nano/driver/i2c.cc b/src/arch/arduino-nano/driver/i2c.cc index cfbea59..0a2f595 100644 --- a/src/arch/arduino-nano/driver/i2c.cc +++ b/src/arch/arduino-nano/driver/i2c.cc @@ -3,6 +3,10 @@ #include #include +#ifndef F_I2C +#define F_I2C 100000UL +#endif + inline void await_twint(unsigned char twcr_values) { TWCR = twcr_values | _BV(TWINT) | _BV(TWIE); @@ -99,7 +103,7 @@ static signed char i2c_receive(uint8_t len, uint8_t *data) signed char I2C::setup() { TWSR = 0; - TWBR = ((F_CPU / 100000UL) - 16) / 2; + TWBR = ((F_CPU / F_I2C) - 16) / 2; return 0; } -- cgit v1.2.3