I2C read problems

it gives me an error if i used your code in the compliler

is it gone work if i change the

#define BUFFER_LENGTH 32

from the wire.h?

and the TWI_BUFFER_LENGTH 32

from twi.h

?

What error? What code? I was just pointing out the 5 places it is used.

is it gone work if i change the

#define BUFFER_LENGTH 32

from the wire.h?

and the TWI_BUFFER_LENGTH 32

from twi.h

Yes, that was what I was suggesting. Although "work" may be a loose term. If you run out of memory it won't work. I don't know if there is some hardware limit, I don't think there is.

You will of course need to change both ends, the sending end and the receiving end.

#include <Wire.h>

#define I2C_Address 2
#define UartBaudRate 57600

int Position;

byte OS4000Data [128];

char command;

void setup()
{
  Serial.begin(UartBaudRate);  
  Wire.begin(I2C_Address);  
  Wire.onRequest(requestEvent); 
  Wire.onReceive(ReceiveCommand);
}

void loop()
{
  if(command == 'C')
  {
    Capture_OS4000();
    command = 'N';
  }
}


void ReceiveCommand(int howMany)
{
  while(!Wire.available());
  command = Wire.receive();
}

void requestEvent()
{
    Wire.send ("kffkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkdd");
    //Wire.send (OS4000Data, 127);
}

void  Capture_OS4000()
{
  Serial.flush();
  while ( Serial.read () != '
#include <Wire.h>
#define requestdelay 25


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

void loop(){

  Wire.beginTransmission(2);
  Wire.send('C');
  Wire.endTransmission();
delay(200);

Wire.beginTransmission(2);
  
  Wire.requestFrom(2,40);
  for ( int i=0; i<40; i++ ) Serial.print(Wire.receive());
  Serial.println();
}

not working with the above code

i am reading kffkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
and not kffkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkdd );
 Serial.flush();
 while( Serial.available() < 127 );
 OS4000Data[Position] = Serial.read();
}


§DISCOURSE_HOISTED_CODE_1§


not working with the above code

i am reading kffkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
and not kffkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkdd

Well I can't reproduce your problem. I changed the two defines I mentioned, and then amended your code slightly. This is the slave:

#include <Wire.h>

#define I2C_Address 2

char command;

char buf [131] = "";

void setup()
{
  Wire.begin(I2C_Address);  
  Wire.onRequest(requestEvent); 
  Wire.onReceive(ReceiveCommand);
  
  for (int i = 0; i < 13; i++)
    strcat (buf, "0123456789");
    
}

void loop()
{
  if(command == 'C')
  {
    command = 'N';
  }
}


void ReceiveCommand(int howMany)
{
  command = Wire.receive();
}


void requestEvent()
{
    Wire.send ((uint8_t*) buf, 128);
}

And this is the master:

#include <Wire.h>

#define I2C_Address 2
#define AMOUNT 128

void setup(){
  Wire.begin();
  Serial.begin(115200);
}

void loop(){

  Wire.beginTransmission(I2C_Address);
  Wire.send('C');
  Wire.endTransmission();

  delay(200);

 
  Wire.requestFrom(I2C_Address, AMOUNT);
  if (Wire.available () == AMOUNT)
    {
    for ( int i=0; i<AMOUNT; i++ ) 
      Serial.print(Wire.receive(), BYTE);
    }
  else
    Serial.println (Wire.available (), DEC);
  Serial.println();
}

And this is the debug output:

01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567

As you can see, 128 bytes of the correct data.

From your code:

void loop(){

Wire.beginTransmission(2);
  Wire.send('C');
  Wire.endTransmission();
delay(200);

Wire.beginTransmission(2);
 
  Wire.requestFrom(2,40);
  for ( int i=0; i<40; i++ ) Serial.print(Wire.receive());
  Serial.println();
}

The second Wire.beginTransmission is not correct - you don't do another beginTransmission before a requestFrom.

Make sure you upload both sender and receiver. The slave does not send the extra data if you try to send more than the maximum in the define.

thanks it worked

for some reason the buffer size into the wire.h was 32 and not 128

hallo again
i also tried to change the values in anrduino 1.0

but it didn't worked

???

What files did you change exactly?

wire.h and twi.h into the library folder

herctrap:
but it didn't worked

Can you be a bit more specific? What didn't work? Under version 1.0 you would have had to change other things too.

The master

asks for data

void Read_Data()
{
  Wire.beginTransmission(2);
  Wire.write('H');
  Wire.endTransmission();

  delay(200);

  Wire.beginTransmission(2);
  Wire.requestFrom(2,127);
  Wire.endTransmission();
  for ( int i=0; i<128; i++ ) Serial.write(Wire.read());
  Serial.println("");
}

and on the slave

  Wire.begin(I2C_Address);  
  Wire.onRequest(requestEvent); 
  Wire.onReceive(ReceiveCommand);
void ReceiveCommand(int howMany)
{
  command = Wire.read();
}
void loop()
{
  if (command == 'H')
  {
    Capture_OS4000();
    command = 'N';
  }
}
void  Capture_OS4000()
{
  //Serial.println("mpika capture"); // debug
  //Serial.flush();
  while ( Serial.read () != '
void requestEvent()
{
  //Wire.write (OS4000Data, 127);
   Wire.write ("AbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789000987654321");
}

but i am receiving

AbcdefghijklmnopqrstuvwxyzABCDEFÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

thanks

);
 //Serial.flush();
 while( Serial.available() < 127 );
 OS4000Data[0] = '


§DISCOURSE_HOISTED_CODE_5§


but i am receiving 

AbcdefghijklmnopqrstuvwxyzABCDEFÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

thanks 

;
  for(Position=1; Position<128; Position++){
    buf = Serial.read();
    if ( buf == '*' ) EOL = Position + 2;
    if ( Position <= EOL ) OS4000Data[Position] = buf; 
    else OS4000Data[Position] = B0;
  }
}
§_DISCOURSE_HOISTED_CODE_5_§

but i am receiving

AbcdefghijklmnopqrstuvwxyzABCDEFÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

thanks

herctrap:
wire.h and twi.h into the library folder

In my copy they are in the Wire and Wire/utility folder.

yes in these folders

if you make it work can you send me the files please
because I edit it with wordpad

thanks a lot

I'm not going to make it work and send it to you. Edit two files and change 2 numbers. At least show here what changes you made.

as before i changed the

#define BUFFER_LENGTH 128

into wire.h

and

#define TWI_BUFFER_LENGTH 128

into twi.h

from 32 to 128

I changed both of those, and ran this sketch:

#include <Wire.h>

void setup () 
  { 
  Wire.begin ();
  }

void loop ()  
  {
  Wire.beginTransmission (25);
  Wire.write ("AbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789000987654321");
  Wire.endTransmission ();
  delay (1000);
  }

All the bytes were sent (I could see with the logic analyzer). I also had to recompile and re-upload the receiving Arduino as well.

give me 4minutes

also the slave is a custom board
and i am using Arduino Pro at 8Mhz because Atmega328 on a breadboard isnt working any more on Arduino 1.0

and after a while