Hi.
I am using Arduino Mega 2560 and STM32F767 boards. I use the STM32 board as the master and the Arduino board as the slave card. I compiled my codes, and there was no error, but I could not get the data. What could be the solution?
MASTER CODE (STM32F7)
''''
uint8_t gelen_data = 0;
uint8_t giden_data = 0;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_ETH_Init();
MX_USART3_UART_Init();
MX_USB_OTG_FS_PCD_Init();
MX_I2C1_Init();
while (1)
{
HAL_I2C_Master_Receive(&hi2c1, 0X37 <<1, &gelen_data, 1, 100); //Arduino kartından veri istedim
giden_data = (gelen_data * 255) / 99; // Gelen data 0-99 aadında ben bunu 0-255 arasına çektim
HAL_I2C_Master_Transmit(&hi2c1, 0x37 <<1, &giden_data, 1, 100); //Arduinoya gönderdim
}
/* USER CODE END 3 */
}
''''
SLAVE CODE(ARDUİNO MEGA 2560)
''''
#include <Wire.h>
uint8_t gelen_data = 0;
uint8_t giden_data = 0;
void setup()
{
Serial.begin(9600); //ekranan yazı yazdırmak için
Wire.begin(0x37); //slave olduğunu tanıttım
Wire.onRequest(istek_geldi); //veri geldiğinde istek geldi fonksiyonu çalışır
Wire.onReceive(veri_geldi);
}
void loop()
{
}
void veri_geldi (int data)
{
while( Wire.available()) //eğer bilgi gelirse bu döngüye girer
{
gelen_data = Wire.read();
analogWrite(5, gelen_data);
Serial.print("Gelen Data:");
Serial.println(gelen_data);
}
}
void istek_geldi(int data)
{
giden_data = map(analogRead(A0), 0, 1023, 0, 99); //veriyi 0-99 arasına çektim
Wire.write(giden_data);
Serial.print("Gönderilen Data: ");
Serial.println(giden_data); //datayı yazdırdım
}`