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();
Do you have pull up resistors? To 5V or to 3.3V?
Blue pill works only with 3.3V.
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.
srp
I think I might need to look at this with a scope or maybe try with some other i2c devices.
There is an interesting post here: –
I will test and update my results
#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();
Because lately an issue was fixed relating to I2C: https://github.com/rogerclarkmelbourne/ … 2/pull/508
Best Regards,
Can you please provide those scope plots?
Yes good idea – once I get my scope back I will take take some screenshots and update this thread.
Best Regards,
#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). !!
}
}
