diff --git a/.travis.yml b/.travis.yml index 251a6212b..bb9db5bed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -209,7 +209,7 @@ script: # - restore_configs - opt_enable_adv BEZIER_CURVE_SUPPORT EXPERIMENTAL_I2CBUS - - opt_set_adv I2C_SLAVE_ADDRESS 1 + - opt_set_adv I2C_SLAVE_ADDRESS 63 - build_marlin # # Enable COREXY diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 2def9b386..528d1f37e 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -795,6 +795,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 0866a08dd..0a385622b 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -5294,7 +5294,7 @@ inline void gcode_M121() { endstops.enable_globally(false); } } } -#endif //EXPERIMENTAL_I2CBUS +#endif // EXPERIMENTAL_I2CBUS /** * M200: Set filament diameter and set E axis units to cubic units diff --git a/Marlin/SanityCheck.h b/Marlin/SanityCheck.h index cc8625e8f..fc866b121 100644 --- a/Marlin/SanityCheck.h +++ b/Marlin/SanityCheck.h @@ -747,3 +747,14 @@ #if ENABLED(EMERGENCY_PARSER) && defined(USBCON) #error "EMERGENCY_PARSER does not work on boards with AT90USB processors (USBCON)." #endif + +/** + * I2C bus + */ +#if ENABLED(EXPERIMENTAL_I2CBUS) && I2C_SLAVE_ADDRESS > 0 + #if I2C_SLAVE_ADDRESS < 8 + #error "I2C_SLAVE_ADDRESS can't be less than 8. (Addresses 0 - 7 are reserved.)" + #elif I2C_SLAVE_ADDRESS > 127 + #error "I2C_SLAVE_ADDRESS can't be over 127. (Only 7 bits allowed.)" + #endif +#endif diff --git a/Marlin/example_configurations/Cartesio/Configuration_adv.h b/Marlin/example_configurations/Cartesio/Configuration_adv.h index 444fc7b2d..3f1287e11 100644 --- a/Marlin/example_configurations/Cartesio/Configuration_adv.h +++ b/Marlin/example_configurations/Cartesio/Configuration_adv.h @@ -795,6 +795,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/Felix/Configuration_adv.h b/Marlin/example_configurations/Felix/Configuration_adv.h index 6f4d1139c..d87f8a39e 100644 --- a/Marlin/example_configurations/Felix/Configuration_adv.h +++ b/Marlin/example_configurations/Felix/Configuration_adv.h @@ -795,6 +795,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/Hephestos/Configuration_adv.h b/Marlin/example_configurations/Hephestos/Configuration_adv.h index d26e2207b..452f5da81 100644 --- a/Marlin/example_configurations/Hephestos/Configuration_adv.h +++ b/Marlin/example_configurations/Hephestos/Configuration_adv.h @@ -795,6 +795,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/Hephestos_2/Configuration_adv.h b/Marlin/example_configurations/Hephestos_2/Configuration_adv.h index 4b771d5d5..9ee0941d5 100644 --- a/Marlin/example_configurations/Hephestos_2/Configuration_adv.h +++ b/Marlin/example_configurations/Hephestos_2/Configuration_adv.h @@ -795,6 +795,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/K8200/Configuration_adv.h b/Marlin/example_configurations/K8200/Configuration_adv.h index 92a81b22c..bf764d0f9 100644 --- a/Marlin/example_configurations/K8200/Configuration_adv.h +++ b/Marlin/example_configurations/K8200/Configuration_adv.h @@ -801,6 +801,6 @@ const unsigned int dropsegments = 2; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/K8400/Configuration_adv.h b/Marlin/example_configurations/K8400/Configuration_adv.h index dde4547f4..b5933588f 100644 --- a/Marlin/example_configurations/K8400/Configuration_adv.h +++ b/Marlin/example_configurations/K8400/Configuration_adv.h @@ -795,6 +795,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/RigidBot/Configuration_adv.h b/Marlin/example_configurations/RigidBot/Configuration_adv.h index d077ae28e..f8c8008df 100644 --- a/Marlin/example_configurations/RigidBot/Configuration_adv.h +++ b/Marlin/example_configurations/RigidBot/Configuration_adv.h @@ -795,6 +795,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/SCARA/Configuration_adv.h b/Marlin/example_configurations/SCARA/Configuration_adv.h index bf4d32351..3da8d5658 100644 --- a/Marlin/example_configurations/SCARA/Configuration_adv.h +++ b/Marlin/example_configurations/SCARA/Configuration_adv.h @@ -795,6 +795,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/TAZ4/Configuration_adv.h b/Marlin/example_configurations/TAZ4/Configuration_adv.h index 1417c803d..224de6415 100644 --- a/Marlin/example_configurations/TAZ4/Configuration_adv.h +++ b/Marlin/example_configurations/TAZ4/Configuration_adv.h @@ -803,6 +803,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/WITBOX/Configuration_adv.h b/Marlin/example_configurations/WITBOX/Configuration_adv.h index d26e2207b..452f5da81 100644 --- a/Marlin/example_configurations/WITBOX/Configuration_adv.h +++ b/Marlin/example_configurations/WITBOX/Configuration_adv.h @@ -795,6 +795,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h b/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h index 828391a3f..61a4a3f2f 100644 --- a/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h +++ b/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h @@ -797,6 +797,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/delta/generic/Configuration_adv.h b/Marlin/example_configurations/delta/generic/Configuration_adv.h index 967a3e6b5..bbf712aab 100644 --- a/Marlin/example_configurations/delta/generic/Configuration_adv.h +++ b/Marlin/example_configurations/delta/generic/Configuration_adv.h @@ -797,6 +797,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h index 64ea68fcd..cc51dc087 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h @@ -796,6 +796,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h index 99fbcf08f..263245cac 100644 --- a/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h @@ -801,6 +801,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h index 0af7481f9..a4b6743f4 100644 --- a/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h @@ -797,6 +797,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/makibox/Configuration_adv.h b/Marlin/example_configurations/makibox/Configuration_adv.h index 7715b71a3..2d5e62523 100644 --- a/Marlin/example_configurations/makibox/Configuration_adv.h +++ b/Marlin/example_configurations/makibox/Configuration_adv.h @@ -795,6 +795,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h b/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h index 3cfe5860b..b3ee0a405 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h @@ -795,6 +795,6 @@ const unsigned int dropsegments = 5; //everything with less than this number of // @section i2cbus //#define EXPERIMENTAL_I2CBUS -#define I2C_SLAVE_ADDRESS 0 // Set non-zero to act as a slave +#define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave #endif // CONFIGURATION_ADV_H diff --git a/Marlin/twibus.cpp b/Marlin/twibus.cpp index bf17db3c2..11f205713 100644 --- a/Marlin/twibus.cpp +++ b/Marlin/twibus.cpp @@ -43,6 +43,11 @@ void TWIBus::reset() { } void TWIBus::address(const uint8_t adr) { + if (adr < 8 || adr > 127) { + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("Bad I2C address (8-127)"); + } + this->addr = adr; #if ENABLED(DEBUG_TWIBUS)