7/13/09

Using UDP with Arduino

Unfortunately, Arduino Ethernet library does not provide UDP support for sketches. This sad fact encouraged me to create an extended version quickly: it is a modified Client.c/.h files (named as ClientUDP.*), placed in the Ethernet library directory.

It is nothing special with this code, because UDP supported by sockets library, used in Arduino, but not not available for sketches directly.

You can download it here: ClientUDP_1.1.zip ( unpack to arduino-0016 \ hradware \ libraries ).

3/24/09

REPEATED START in Arduino

I2C support for Arduino based on Wire library.

But, when I try to work with a DS1307 RTC chip, I found that repeated start mode not covered by original Wire library:



Wire library can't send second START condition without STOPping the I2C bus. Some chips, like DS1307, reset internal address register after that.

So, what can we do?

1. Forget about Wire library and use another - one for example, from Peter Fleury.

2. Upgrade Wire library with new functionality (my way).

OK, new Wire function prototype is:

uint8_t TwoWire::transmitAndRequest(uint8_t quantity)

And it must be used instead of endTransmission():

Wire.beginTransmission(address)
Wire.send(data);
Wire.send(data);
...
Wire.transmitAndRequest(quantity);


This code provides transmission buffer sending, than running receiving after REPEATED START. Function returns read bytes count. The highest bit (0x80) is a error flag, so if we got a value > 127, it is an error code, same as for endTransmission() (without this bit, of course).

Download modified Wire library: Wire.zip (tested with Arduino IDE 0014).