Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire.h i2c slave not working, STM32F103 is freezing.. #2381

Closed
gopalreddylakki opened this issue May 28, 2024 Discussed in #2279 · 1 comment
Closed

Wire.h i2c slave not working, STM32F103 is freezing.. #2381

gopalreddylakki opened this issue May 28, 2024 Discussed in #2279 · 1 comment

Comments

@gopalreddylakki
Copy link

Discussed in https://github.com/orgs/stm32duino/discussions/2279

Originally posted by gopalreddylakki February 19, 2024
i2cs
Slave_STm32F103
Master_nano_read

//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);
}
@fpistm
Copy link
Member

fpistm commented May 28, 2024

Please do not duplicate entry.
Ii is already a discussion and as said I'm not able to reproduce.

@fpistm fpistm closed this as completed May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants