Skip to content

examples & Arduino 1.0 #2

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

Merged
merged 4 commits into from
Dec 26, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions EasyTransferI2C/EasyTransferI2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,28 @@ _serial = theSerial;
void EasyTransferI2C::sendData(uint8_t i2c_address){
uint8_t CS = size;
_serial->beginTransmission(i2c_address);
#if ARDUINO >= 100
_serial->write(0x06);
_serial->write(0x85);
_serial->write(size);
#else
_serial->send(0x06);
_serial->send(0x85);
_serial->send(size);
#endif
for(int i = 0; i<size; i++){
CS^=*(address+i);
#if ARDUINO >= 100
_serial->write(*(address+i));
#else
_serial->send(*(address+i));
#endif
}
#if ARDUINO >= 100
_serial->write(CS);
#else
_serial->send(CS);
#endif
_serial->endTransmission();
}

Expand All @@ -32,15 +46,24 @@ boolean EasyTransferI2C::receiveData(){
//this size check may be redundant due to the size check below, but for now I'll leave it the way it is.
if(_serial->available() >= 3){
//this will block until a 0x06 is found or buffer size becomes less then 3.
#if ARDUINO >= 100
while(_serial->read() != 0x06) {
#else
while(_serial->receive() != 0x06) {
#endif
//This will trash any preamble junk in the serial buffer
//but we need to make sure there is enough in the buffer to process while we trash the rest
//if the buffer becomes too empty, we will escape and try again on the next call
if(_serial->available() < 3)
return false;
}
#if ARDUINO >= 100
if (_serial->read() == 0x85){
rx_len = _serial->read();
#else
if (_serial->receive() == 0x85){
rx_len = _serial->receive();
#endif
//make sure the binary structs on both Arduinos are the same size.
if(rx_len != size){
rx_len = 0;
Expand All @@ -53,7 +76,11 @@ boolean EasyTransferI2C::receiveData(){
//we get here if we already found the header bytes, the struct size matched what we know, and now we are byte aligned.
if(rx_len != 0){
while(_serial->available() && rx_array_inx <= rx_len){
#if ARDUINO >= 100
rx_array[rx_array_inx++] = _serial->read();
#else
rx_array[rx_array_inx++] = _serial->receive();
#endif
}

if(rx_len == (rx_array_inx-1)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ void setup(){

}

void loop() {}

void receive(int numBytes){
void loop() {
//check and see if a data packet has come in.
if(ET.receiveData()){
//this is how you access the variables. [name of the group].[variable name]
Expand All @@ -43,3 +41,5 @@ void receive(int numBytes){
}
}
}

void receive(int numBytes) {}
Binary file added I2C_Wiring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UARTS_Wiring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.