Defines | |
#define | I2C_BIT_RATE_DIVIDER 0x0C |
Set bit rate 12 = 100kbit/s (max speed setting is 10 for an 8 MHz clock). It is a divider, so the lower the number the faster the speed. | |
Functions | |
RING_BUFFER_NEW (i2c_buffer, 128, char, i2c_write_buff, i2c_addr_buff) | |
int | i2c_init (char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send) |
Initializes the i2c module. | |
int | i2c_send (char dest, char *data, size_t bytes) |
Sends a byte array over I2C as a master. | |
int | i2c_request (char dest) |
Send a master request to the destination. |
Initiates I2C functions on an ATMega128 which has a fully hardware Two Wire Interface (TWI) module. Any Atmel chip with this hardware should be able to use the software.
This code will operate in a multi-master enviornment and can be either a slave or a master at any time (as long as they are not one or the other at the moment. You can queue up multiple transmission modes in the buffer up to the buffer size. The buffer is implemented as a ring buffer.
It is implemented using callback functions. Whenever you want to send a packet you can call the built in send function (as a master) and it will send an array of bytes. Master recieve and slave send/receive are all handled by the call back functions. It is up to the end user to create functions that will handle the receiving of packets. Their functions will be called with every byte recieved so you must either buffer the inputs or handle each one separately.
On errors we will simply flush the entire buffer.
For information on how I2C operates, read the wikipedia article http://en.wikipedia.org/wiki/I2c for a good explanation of how it works.
|
Initializes the i2c module. Initializes the I2C module to start listening on the i2c lines. If the callback functions are not set to null they will be called when that transmission mode is called. The address is your address that you will listen to when you are not the master.
|
|
Send a master request to the destination. Sends a request of data from the target address and calls the callback function to handle data as it comes in. This function will not work if the slave has not informationt to send or has nothing implemented to send it.
|
|
Sends a byte array over I2C as a master. Will perform a send over I2C to the destination from data for the ammount of bytes that bytes is.
|