Issues with the I2C bus on STM32F103C

snorman
Wed Jul 11, 2018 5:20 pm
Hello,

I am having a couple of issues using the I2C bus (MP3115A2 – Pressure Sensor) on the STM32F103C.

I can seem to find the device using: –

Wire.beginTransmission(0x60);
result = Wire.endTransmission();


stevestrong
Wed Jul 11, 2018 5:50 pm
What voltage do you supply to your sensor?
Do you have pull up resistors? To 5V or to 3.3V?
Blue pill works only with 3.3V.

snorman
Thu Jul 12, 2018 6:50 am
Thanks for your reply.

The MP3115A2 runs on 3.3v and I have tried connecting two pull up 4.7k resisters on the i2c bus to 3.3v. But still the same result.


zmemw16
Thu Jul 12, 2018 9:13 am
try 3k3’s
srp

snorman
Thu Jul 12, 2018 9:43 am
Thanks for you’re reply – Have tried that too – Unfortunately the same result.

I think I might need to look at this with a scope or maybe try with some other i2c devices.


snorman
Thu Jul 12, 2018 10:55 am
Could it be something to do with the repeat start?

There is an interesting post here: –

viewtopic.php?t=934

I will test and update my results


snorman
Thu Jul 12, 2018 1:11 pm
So I have found a work around using SoftWire.h instead of Wire.h

#include <SoftWire.h>
SoftWire SoftWire1;

void setup(){
SoftWire1.begin();
SoftWire1.beginTransmission(0x60);
SoftWire1.write(0x0C);
// Adding a false will add a "repeated start".
SoftWire1.endTransmission(false);
SoftWire1.requestFrom(0x60, 1);
// result will return 196 the correct value
result = SoftWire1.read();


stevestrong
Thu Jul 12, 2018 1:16 pm
Are you sure you are using the latest repo version from Roger?
Because lately an issue was fixed relating to I2C: https://github.com/rogerclarkmelbourne/ … 2/pull/508

snorman
Thu Jul 12, 2018 1:25 pm
Yes – I exported from master branch yesterday.

Best Regards,


stevestrong
Thu Jul 12, 2018 2:00 pm
It would be nice to have scope plots of both HW (not working) and SW I2C (working) signals on your chip in order to be able to solve the issue in the HW I2C module.
Can you please provide those scope plots?

snorman
Fri Jul 13, 2018 10:28 am
Thanks for your help.

Yes good idea – once I get my scope back I will take take some screenshots and update this thread.

Best Regards,


doctek
Wed Jul 25, 2018 4:00 am
I make no claims to expertise here, but I’ve gotten the following code to work with both the default and the alternate I2C ports of an L053 Discovery and an L031 Discovery.
#include <Wire.h>

void setup()
{
Wire.setSCL(1); // try alternate i2c pins - Worked!
Wire.setSDA(0);
Wire.begin(); // join i2c bus (address optional for master)
}
int got[6];
void loop()
{
Wire.beginTransmission(0x19); // transmit to device #0x19
Wire.write(byte(0x20)); // sets register pointer to echo CR1
Wire.endTransmission(); // stop transmitting
// read back
Wire.requestFrom(0x19, 1); // request 2 bytes from slave device #112
// receive reading
if (Wire.available() >= 1) { // if byte received
got[0] = Wire.read(); // receive
}
// Write new data
Wire.beginTransmission(0x19); // transmit to device 0x19
Wire.write(byte(0x20)); // sets register pointer to the command register 1 (0x20)
Wire.write(byte(0x57)); // Send arbitrary, acceptable, and recognizable data
Wire.endTransmission(); // stop transmitting

Wire.beginTransmission(0x19); // transmit to device #0x19
Wire.write(byte(0x20)); // sets register pointer to echo CR1
Wire.endTransmission(); // stop transmitting

Wire.requestFrom(0x19, 1);
if (Wire.available() >= 1) { // if byte received
got[1] = Wire.read(); // receive high byte (overwrites previous reading)
// NOTE: 0x57 reads back as 87 (decimal). !!
}
}


Leave a Reply

Your email address will not be published. Required fields are marked *