Arduino-For-Keil: [Help wanted] I2C problem
Hello FASTSHIFT.
I am a hobbyist of Arduino and recently discovered your job and I have been playing with it for 2 or 3 days, I blinked a LED, fade in and out and printed to serial using your examples, so far, so good.
I bought some months ago a board with STM32F030F4P6 (SSOP-20 package), really cheap and I have been working to move some of attiny84 projects to this MCU, not luck with it, code was too big until I found your project.
Now I am trying to Port some of the Arduino libraries for my sensors and screens, many of them are I2C (BMP085, BME280, OLED SSD1306…) So first I tried to use the I2C scanner code from the Arduino community but seems it hangs up the whole thing and don’t even get serial Port outputs.
I will be very happy if you can help me on it.
This is the code:
/I2C Scanner
//#define pinSDA PA1
//#define pinSCL PA2
#define SDA_Pin PA1
#define SCL_Pin PA2
#include <Wire.h>
//TwoWire Wire(pinSCL, pinSDA, SOFT_FAST);
void Serial_EventHandler()
{
togglePin(LED_Pin);
}
void setup()
{
Wire.begin();
Serial.begin(9600);
//Serial.setTimeout(10);
//Serial.attachInterrupt(Serial_EventHandler);
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.printf("I2C device found at address 0x");
if (address<16)
Serial.printf("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.printf("Unknow error at address 0x");
if (address<16)
Serial.printf("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
int main(void)
{
Delay_Init();
setup();
for(;;)loop();
}
This is my board: By the way, the code use the internal oscillator or external?


About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (7 by maintainers)
@namkihop Software I2C.