rogerclarkmelbourne / Arduino_STM32

Arduino STM32. Hardware files to support STM32 boards, on Arduino IDE 1.8.x including LeafLabs Maple and other generic STM32F103 boards
Other
2.53k stars 1.26k forks source link

i2c freeze MCU #880

Closed ciko2k closed 2 years ago

ciko2k commented 2 years ago

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

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++;

}`

GitMoDu commented 2 years ago

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.

rogerclarkmelbourne commented 2 years ago

Closed due to inactivity from OP