How to ardiuno code convert stm32f4XX? help me

#include <Wire.h>
 void setup() { 
 Wire.onReceive(receiveEvent); 
Serial.begin(9600); 
 } 
int i=0; 
void loop() { 
delay(100);
 for(i=0;i<255;i++)
 { 
Wire.begin(i); 
delay(1000); 
 } 
} 
setup() 
void receiveEvent(int howMany) {
 while(1 < Wire.available()) 
{ 
char c = Wire.read();
 Serial.print(i); 
Serial.print(c); 
 } 

}

More of an explanation of what you want to do will help a lot. What type of code do you want to convert?

Shouldn't you start with code that will actually compile?

The code I'm trying to convert is:

#include <Wire.h>
 void setup() { 
 Wire.onReceive(receiveEvent); 
Serial.begin(9600); 
 } 
int i=0; 
void loop() { 
delay(100);
 for(i=0;i<255;i++)
 { 
Wire.begin(i); 
delay(1000); 
 } 
} 
setup() 
void receiveEvent(int howMany) {
 while(1 < Wire.available()) 
{ 
char c = Wire.read();
 Serial.print(i); 
Serial.print(c); 
 } 

}

Topics merged

Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to [url=https://forum.arduino.cc/index.php?topic=710766.0]Learn How To Use The Forum[/url].

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

It won't compile, not much point in trying to convert it until it does. Don't you agree?

The line that says "setup()" should not be in your sketch. Remove it or comment it out and your sketch will compile.

The sketch doesn't make much sense... it changes the I2C slave address about once per second and displays any bytes received. An oscilloscope or logic analyzer would be much more effective for determining what slave addresses are being sent data.

#include <Wire.h>

void setup()
{
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);
}

int i = 0;

void loop()
{
  delay(100);
  for (i = 0; i < 255; i++)
  {
    Wire.begin(i);
    delay(1000);
  }
}

// setup()

void receiveEvent(int howMany)
{
  while (1 < Wire.available())
  {
    char c = Wire.read();
    Serial.print(i);
    Serial.print(c);
  }
}

Why is 255 excluded?
Also, is there some reason for waiting for two bytes available from Wire, in 'receiveEvent()'? Shouldn't one byte be enough?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.