From a6d594665b7b418b041d606ba7af74d8cf2e77ff Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 11 May 2016 15:28:05 -0700 Subject: [PATCH 1/2] Print an error on bad i2c request Reference: https://github.com/MarlinFirmware/Marlin/pull/3713#issuecomment-218333678 --- Marlin/Marlin_main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 45907f355..10d26ac98 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -5040,10 +5040,14 @@ inline void gcode_M121() { endstops.enable_globally(false); } uint8_t addr = code_seen('A') ? code_value_short() : 0; int bytes = code_seen('B') ? code_value_short() : 0; - if (addr && bytes) { + if (addr && bytes > 0 && bytes <= 32) { i2c.address(addr); i2c.reqbytes(bytes); } + else { + SERIAL_ERROR_START; + SERIAL_ERRORLN("Bad i2c request"); + } } #endif //EXPERIMENTAL_I2CBUS From aaeadf0cbd95b532d5d2cee482c53c238a8f5e12 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 11 May 2016 15:29:54 -0700 Subject: [PATCH 2/2] If no "B" parameter given, get 1 byte --- Marlin/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 10d26ac98..99786e617 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -5038,7 +5038,7 @@ inline void gcode_M121() { endstops.enable_globally(false); } */ inline void gcode_M156() { uint8_t addr = code_seen('A') ? code_value_short() : 0; - int bytes = code_seen('B') ? code_value_short() : 0; + int bytes = code_seen('B') ? code_value_short() : 1; if (addr && bytes > 0 && bytes <= 32) { i2c.address(addr);