This is the quick start guide for the TWI Driver, with step-by-step instructions on how to configure and use the driver for specific use cases.
The section described below can be compiled into e.g. the main application loop or any other function that might use the TWI functionality.
In our basic use case, the TWI driver is used to set up internal communication between TWI modules on the two MEGARF STK600 boards, On one STK600 megarf board TWI is set up in master mode, and on another STK600 megarf board TWI is set up in slave mode, and these are connected together on the board by placing a connection between SDA/SCL.
The System Clock Management module is required to enable the clock to the TWI modules.
When the System Clock Management module has been included, it must be initialized:
We first create some definitions. TWI slave, speed, and addresses:
We create two variables, one which contains data that will be transmitted, and one which will contain the received data:
Options for the TWI module initialization procedure are given below:
Set up the interrupt handler:
We create a packet for the data that we will be sent to the slave TWI:
We enable the clock to the master module, and initialize it with the options we described before:
We do the same for the slave on another board, using the slave portion of the driver, passing through the twi_slave_init function, its address,
And enable interrupts:
Finally, we write our packet through the master TWI module:
We wait for the slave to finish receiving:
We read back the sent data and check whether slave received properly