-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Discussed in https://github.com/orgs/stm32duino/discussions/2279
Originally posted by gopalreddylakki February 19, 2024
//slave
void requestEvent()
{
Wire.write("hello\n"); // respond with message of 6 bytes
// as expected by master
}form the Arduino required 15 bytes, in the salve only having 6 bytes. in slave (stm32f103) after sending 6 bytes it's not the end transaction, it's in freezing.
but I check with another board manager stm32duino . it's working fine.
can check it and give me the solution
Slave program (STM32F103)
#include <Wire.h>
#define I2C_ADDR 0x09
void setup()
{
Wire.begin(I2C_ADDR); // join i2c bus with address #4
Wire.onRequest(requestEvent); // register event
Wire.onReceive(receiveEvent); // register event
Serial.begin(115200); // start serial for output
pinMode(PC13,OUTPUT);
}
void loop()
{
//empty loop
digitalWrite(PC13,HIGH);
delay(200);
digitalWrite(PC13,LOW);
delay(200);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
// int x = Wire.read(); // receive byte as an integer
//Serial.println(x); // print the integer
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
Wire.write("hello\n"); // respond with message of 6 bytes
// as expected by master
}
master program (ardunio nano )
#include "Wire.h"
#define bl03_address 0x09
void setup()
{
Wire.begin();
Serial.begin(115200);
}
void loop()
{
//getvoltage();
//gettemperature();
Wire.beginTransmission(bl03_address);
Wire.write(0x20);
Wire.endTransmission();
Wire.requestFrom(bl03_address,15,true);
char registerValue = Wire.read();
char registerValue1 = Wire.read();
Wire.endTransmission();
Serial.println(registerValue,HEX);
Serial.println(registerValue1,HEX);
delay(500);
}
Metadata
Metadata
Assignees
Labels
No labels