STM32F091RC I2C not working

STM32F103 Nucleo boards e.g. STM Nucleo F103RB
Post Reply
GianniDPC
Posts: 16
Joined: Thu Jun 22, 2017 10:09 am

STM32F091RC I2C not working

Post by GianniDPC » Thu Jun 22, 2017 10:16 am

Hello,

I'm using an Arduino sketch to read a TC74 temperature sensor, But the outcome is not as expected it does not detect the sensor that is connected to PB8 (SCL) en PB9 (SDA).

I tried other arduino sketches that simple make use of the GPIO pins and such and those work fine. But I can't seem to get I2C working. I looked into the source code that I linked below and it is indeed using PB8 and PB9 for I2C.

How can I solve this? Or is this a known bug or something.

My sketch:

Code: Select all

#include <Wire.h>

// TC74A0
#define address B1001000
#define baudrate 9600

byte val = 0;
void setup()
{
    Wire.begin();
    Serial.begin(baudrate);
}

void loop()
  {
    Serial.print("temperature in Celsius: ");

    int temperature;

    Wire.beginTransmission(address);

    Wire.write(val);

    Wire.requestFrom(address, 1);
      if (Wire.available()) {
      temperature = Wire.read();
      Serial.println(temperature);
      }

      else {
      Serial.println("---");
      }
    delay(2000);
}
https://github.com/stm32duino/Arduino_C ... 32f0/twi.c

GianniDPC
Posts: 16
Joined: Thu Jun 22, 2017 10:09 am

Re: STM32F091RC I2C not working

Post by GianniDPC » Thu Jun 22, 2017 2:05 pm

Nvm. I fixed it.

By anyone wondering how, I used 2 4K7 pull-up resistors as in the image below. I didn't need them when I wrote a similair program in STM32Cube though, I guess STM32duino doesn't use the internal pull-ups.

Image

stevestrong
Posts: 1831
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: STM32F091RC I2C not working

Post by stevestrong » Thu Jun 22, 2017 2:11 pm

The STM32 internal pull-up resistors are very weak (30..50k), so a working I2c always need extra pull-ups.

Post Reply