Master code:
Code: Select all
#include<Wire.h>
int z[16];
void setup()
{
Serial.begin(9600);
delay(50);
Wire.begin();
delay(50);
}
void loop()
{
Wire1.requestFrom(0x09, 16); //to receive 16-byte;
delay(50);
Serial.print("Slave data: ");
for (int i = 0; i < 16; i++)
{
z[i] = Wire.read();
delay(50);
Serial.print(z[i], DEC);
}
Serial.println();
delay(1000);
}
Code: Select all
#include<Wire.h>
const uint8_t a = 0x09;
int transferArray[16] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
bool flag1 = LOW;
void setup()
{
Serial.begin(9600);
delay(50);
Wire.begin(a);
delay(50);
Wire.onRequest(sendEvent);
delay(50);
}
void loop()
{
}
void sendEvent()
{
for (int i = 0; i < 16; i ++ )
{
Wire.write((transferArray[i]));
delay(50); //I2C is byte-oriened Bus
//Wire.write(lowByte(transferArray[i]));
}
}
I also use 2 pull-up resistors 4.7k for both SCL and SDA lines.
This code works on 2 Arduino Uno but I can not understand why it does not work on STM32.
Can somebody help me, please. Thank you very much!