Float I2c

Steveiboy:
I think I need to read up more, I've tried to add a second slave but it receives nothing from both salves
So I went back to basic with one salve
If I use this Wire.begin (SLAVE_ADDRESS_1); only with one slave it works

The other thing I'm struggling to understand is how to display the 4 floats are displayed via the serial terminal as there are only one fnum and foo to send.

Steveiboy,

The Wire library has a problem. When the onRequestevent() is triggered (inside ISR), the code only transmits the last Wire.write() data. if your onRequestEvent() is like this:

void onRequestEvent(){
   Wire.write(1);
   Wire.write(2);
   Wire.write(3);
   Wire.write(4);
   Wire.write(5);
   Wire.write(6);
   Wire.write(7);
}

and the Master's code was

Wire.requestFrom(slave,7);
  while(Wire.available()){
     Serial.print(Wire.read(),HEX);
     Serial.print(' ');
     }

the Monitor would print:

7 FF FF FF FF FF FF

Not what you expected right?

I changed the code in my library to fix this and another Issue.

C:\Program Files\Arduino\hardware\arduino\avr\libraries\Wire\utility\twi.c

/* 
 * Function twi_transmit
 * Desc     fills slave tx buffer with data
 *          must be called in slave tx event callback
 * Input    data: pointer to byte array
 *          length: number of bytes in array
 * Output   1 length too long for buffer
 *          2 not slave transmitter
 *          0 ok
 */
uint8_t twi_transmit(const uint8_t* data, uint8_t length)
{
  uint8_t i;

  // ensure data will fit into buffer
  //if(TWI_BUFFER_LENGTH < length){ // original
  if(TWI_BUFFER_LENGTH < (length+twi_txBufferLength)){ //chuck 15JUN2015
    return 1;
  }
  
  // ensure we are currently a slave transmitter
  if(TWI_STX != twi_state){
    return 2;
  }
  
  // set length and copy data into tx buffer
  //twi_txBufferLength = length; original
  for(i = 0; i < length; ++i){ 
  //  twi_txBuffer[i] = data[i]; original
    twi_txBuffer[twi_txBufferLength++] = data[i]; //chuck 15Jun2015
    }
   return 0;
}

Appended are my update twi.c and two test Sketches that work.

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.

twi.c (17.5 KB)

slave.ino (1.69 KB)

master.ino (3.01 KB)

I2C_anyThing.zip (547 Bytes)