Skip to content

Instantly share code, notes, and snippets.

@patrickelectric
Created November 13, 2014 15:40
Show Gist options
  • Save patrickelectric/bfa006d9bc68281d07e7 to your computer and use it in GitHub Desktop.
Save patrickelectric/bfa006d9bc68281d07e7 to your computer and use it in GitHub Desktop.
/*
* 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){
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;
for(i = 0; i < length; ++i){
twi_txBuffer[i] = data[i];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment