xnorit:public:dependencies:start
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| xnorit:public:dependencies:start [2021/03/07 14:50] – created timdv91 | xnorit:public:dependencies:start [2024/10/09 15:45] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== XnorBus I2C Communication Library: ====== | + | Nothing to see here! Go back one page using the menu above... |
| - | ===== I2C Slave devices library ===== | ||
| - | ==== Instantiate ' | ||
| - | - Include the library globally. | ||
| - | - Instantiate byte array variable. This is used as a shared memory on the I2C bus. Size of array is free to choose. | ||
| - | - Instantiate XnorBusSlave object, passing an I2C ID byte followed by the previously instantiated byte array. | ||
| - | |||
| - | <code c> | ||
| - | #include " | ||
| - | byte bus_memory[4]; | ||
| - | XnorBusSlave xbus(8, bus_memory); | ||
| - | </ | ||
| - | |||
| - | //Example code above creates an bus_memory byte array that is 4 bytes long. Next the slave is given ID number 8, and the bus_memory array is passed to the XnorBusSlave object. All data stored inside this array is (read/ | ||
| - | |||
| - | // | ||
| - | ==== Bugs: ==== | ||
| - | <WRAP center round important 80%> | ||
| - | **Static void bug!** | ||
| - | Line 31 and 47 should not be declared as static! | ||
| - | This causes no issue on attinycore, but returns an error in the minicore stack. | ||
| - | </ | ||
| - | |||
| - | |||
| - | ==== Downloads ==== | ||
| - | * Download full slaves library code + example: {{ : | ||
| - | * {{ : | ||
| - | * {{ : | ||
| - | |||
| - | \\ | ||
| - | |||
| - | ===== I2C Master device(s) library usage: ===== | ||
| - | |||
| - | ==== Instantiate ' | ||
| - | - Include the library globally. | ||
| - | - Instantiate XnorBusMaster object, passing an I2C ID byte. | ||
| - | |||
| - | <code c> | ||
| - | #include " | ||
| - | XnorBusMaster xbus(8); // Init slave device object with ID 8, named xbus. | ||
| - | </ | ||
| - | |||
| - | <WRAP center round tip 90%> | ||
| - | Configure multiple slaves as multiple XnorBusMaster objects for ease of use! | ||
| - | </ | ||
| - | |||
| - | \\ | ||
| - | ==== Set bus request configuration: | ||
| - | Before reading/ | ||
| - | \\ This can be done using the following code: | ||
| - | <code c> | ||
| - | xbus.SetBusRequest(0, | ||
| - | </ | ||
| - | |||
| - | In the above example, the master is configured to read the shared slaves memory byte array starting from index 0, and read a total of 4 bytes. In this example (based on the previous explained slave) this would be the whole array. | ||
| - | |||
| - | * If for performance reasons the user want's to lower the amount of data transfer over the I2C bus, it is possible to change the configuration to read less bytes. | ||
| - | * If for expansion reasons the user want's to increase the amount of bytes transferred, | ||
| - | |||
| - | <WRAP center round important 90%> | ||
| - | Note that the slaves shared bus memory has to be configured with the correct size before the master can request data of this shared memory. | ||
| - | </ | ||
| - | |||
| - | |||
| - | |||
| - | === Examples: === | ||
| - | <code c> | ||
| - | xbus.SetBusRequest(0, | ||
| - | xbus.SetBusRequest(0, | ||
| - | xbus.SetBusRequest(3, | ||
| - | xbus.SetBusRequest(2, | ||
| - | xbus.SetBusRequest(1, | ||
| - | </ | ||
| - | |||
| - | <WRAP center round info 90%> | ||
| - | The SetBusRequest function does not transmit data over the I2C bus. Changes are kept locally in the masters memory and only transmitted to the slave when required. (on Read or Write). | ||
| - | </ | ||
| - | |||
| - | ==== Write bytes to slave: ==== | ||
| - | After using the ' | ||
| - | - First, create a byte array that contains the data to write. \\This byte array has to be of the same size that was configured using the ' | ||
| - | - Second, use the ' | ||
| - | |||
| - | <code c> | ||
| - | byte b[] = {100, | ||
| - | xbus.Write(b); | ||
| - | </ | ||
| - | |||
| - | Combined with the ' | ||
| - | <code c> | ||
| - | xbus.SetBusRequest(0, | ||
| - | byte b[] = {100, | ||
| - | xbus.Write(b); | ||
| - | </ | ||
| - | |||
| - | === Examples: === | ||
| - | |||
| - | <code c> | ||
| - | // If a user only needs to write 1 byte to the third index of the slave this can be done as followed: | ||
| - | xbus.SetBusRequest(2, | ||
| - | byte b[] = {102}; // Init byte array containing data to write. | ||
| - | xbus.Write(b); | ||
| - | |||
| - | // If a user needs to write 2 bytes, starting on the second index: | ||
| - | xbus.SetBusRequest(1, | ||
| - | byte b[] = {101,102}; // Init byte array containing data to write. | ||
| - | xbus.Write(b); | ||
| - | |||
| - | // If data is written in a loop, the ' | ||
| - | xbus.SetBusRequest(1, | ||
| - | while(true) | ||
| - | { | ||
| - | byte b[] = {101,102}; // Init byte array containing data to write. | ||
| - | xbus.Write(b); | ||
| - | delay(10); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | <WRAP center round info 90%> | ||
| - | The Write function will always write the ' | ||
| - | </ | ||
| - | |||
| - | ==== Read bytes from slave: ==== | ||
| - | To read bytes from a slave, first the ' | ||
| - | |||
| - | <code c> | ||
| - | byte q[2]; // init byte array of size 2 | ||
| - | xbus.Read(q); | ||
| - | </ | ||
| - | |||
| - | Combined with the ' | ||
| - | <code c> | ||
| - | xbus.SetBusRequest(1, | ||
| - | byte q[2]; // init byte array of size 2 | ||
| - | xbus.Read(q); | ||
| - | </ | ||
| - | |||
| - | === Examples: === | ||
| - | <code c> | ||
| - | // If data from a slave is requested in a loop, the ' | ||
| - | xbus.SetBusRequest(0, | ||
| - | byte q[4]; // init byte array of size 2 | ||
| - | while(true) | ||
| - | { | ||
| - | xbus.Read(q); | ||
| - | delay(10); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | <WRAP center round info 90%> | ||
| - | The Read function will only write the ' | ||
| - | </ | ||
| - | |||
| - | <WRAP center round important 90%> | ||
| - | Due to not rewriting the ' | ||
| - | |||
| - | If multiple masters are on the same I2C bus, there could be issues where the ' | ||
| - | |||
| - | This can be fixed by using the ' | ||
| - | </ | ||
| - | |||
| - | ==== Downloads ==== | ||
| - | * Download full masters library code + example:{{ : | ||
| - | * {{ : | ||
| - | * {{ : | ||
xnorit/public/dependencies/start.1615128634.txt.gz · Last modified: (external edit)
