Arduino_STM32
Arduino_STM32 copied to clipboard
i2c freeze MCU
Hi, i'm using the Wire scan example. if my i2s peripheric is connected the code run well, but when i disconnect the peripheric, MCU freeze and restarted by IWDG
could someone help me? there is an alternative library to use?
Here the code.. thks
`#include <Wire.h> #include <libmaple/iwdg.h>
TwoWire WIRE2 (2,I2C_FAST_MODE); #define Wire WIRE2
#define TXPIN PA8
int cycle;
void setup() { iwdg_init(IWDG_PRE_32, 8000); iwdg_feed();
pinMode(TXPIN, OUTPUT); digitalWrite(TXPIN,HIGH);
Serial1.begin(9600); Wire.begin(); Serial1.println("\nI2C Scanner"); }
void loop() { iwdg_feed(); byte error, address; int nDevices;
Serial1.print(cycle); Serial1.println(". Scan ***** ");
nDevices = 0; for(address = 1; address < 127; address++) {
Wire.beginTransmission(address);
error = Wire.endTransmission()
if (error == 0) {
Serial1.print("I2C device found at address 0x");
if (address < 16)
Serial1.print("0");
Serial1.println(address);
nDevices++;
}
else if (error == 4) {
Serial1.print("Unknown error at address 0x");
if (address < 16)
Serial1.print("0");
Serial1.println(address, HEX);
}
} if (nDevices == 0) Serial1.println("No I2C devices found"); else Serial1.println("done");
delay(1000); // wait 5 seconds for next scan cycle++;
}`
Without external pull-ups (like the ones likely in your device) I2C will stall because the lines won't raise up. Add fixed external pull-ups and you shouldn't see a problem.
Closed due to inactivity from OP