diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index c81f3d39f..87b4d309b 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -5259,15 +5259,13 @@ inline void gcode_M121() { endstops.enable_globally(false); } */ inline void gcode_M155() { // Set the target address - if (code_seen('A')) - i2c.address(code_value_byte()); + if (code_seen('A')) i2c.address(code_value_byte()); // Add a new byte to the buffer - else if (code_seen('B')) - i2c.addbyte(code_value_int()); + if (code_seen('B')) i2c.addbyte(code_value_byte()); // Flush the buffer to the bus - else if (code_seen('S')) i2c.send(); + if (code_seen('S')) i2c.send(); // Reset and rewind the buffer else if (code_seen('R')) i2c.reset(); @@ -5279,11 +5277,11 @@ inline void gcode_M121() { endstops.enable_globally(false); } * Usage: M156 A B */ inline void gcode_M156() { - uint8_t addr = code_seen('A') ? code_value_byte() : 0; - int bytes = code_seen('B') ? code_value_int() : 1; + if (code_seen('A')) i2c.address(code_value_byte()); - if (addr && bytes > 0 && bytes <= 32) { - i2c.address(addr); + uint8_t bytes = code_seen('B') ? code_value_byte() : 1; + + if (i2c.addr > 0 && bytes > 0 && bytes <= 32) { i2c.reqbytes(bytes); } else { diff --git a/Marlin/twibus.h b/Marlin/twibus.h index 5901aec53..d78e646e5 100644 --- a/Marlin/twibus.h +++ b/Marlin/twibus.h @@ -59,13 +59,6 @@ class TWIBus { */ const int timeout = 5; - /** - * @brief Target device address - * @description The target device address. Persists until changed. - * - */ - uint8_t addr = 0; - /** * @brief Number of bytes on buffer * @description Number of bytes in the buffer waiting to be flushed to the bus. @@ -76,10 +69,16 @@ class TWIBus { * @brief Internal buffer * @details A fixed buffer. TWI commands can be no longer than this. */ - char buffer[30]; + char buffer[32]; public: + /** + * @brief Target device address + * @description The target device address. Persists until changed. + */ + uint8_t addr = 0; + /** * @brief Class constructor * @details Initialize the TWI bus and clear the buffer