| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
TWI Transaction Manager Example

The TWI Transaction Manager Example shows how to use the TWI transaction manager library to schedule transactions.

The application communicates over two-wire interface (TWI) with two devices that are present in the mbed Application Shield: the MMA7660 triple axis accelerometer and the LM75B temperature sensor.

The example uses the RTC peripheral to generate regular tick events (32 per second). The interrupt handler, executed in reaction to each tick event, schedules data transfers to read the current values from the devices. The obtained values are averaged and printed every 500 milliseconds or when the tilting status reported by the accelerometer changes. Additionally, the user can generate asynchronous data transfer requests (reading all registers available in the devices) by pressing Button 1 or Button 4. Such additional transfer requests show that the TWI transaction manager library can schedule transfer requests from different contexts and realize them in the order they were scheduled.

You can find the source code and the project file of the example in the following folder: `<InstallFolder>\examples\peripheral\twi_master_using_app_twi`

# Testing

Test the TWI Transaction Manager Example application by performing the following steps:

1. Compile and program the application.
2. Start a terminal emulator like PuTTY and connect to the used COM port with the following UART settings:
   - Baud rate: 115.200
   - 8 data bits
   - 1 stop bit
   - No parity
   - HW flow control: RTS/CTS
3. Observe that a message similar to the following one is printed every 500 milliseconds or when the tilting status changes:

       Temp:  25.6 | X:   0, Y:   1, Z:  21 | UP

   The first segment of the message contains the temperature value. The second segment contains acceleration values for all three axes. The third segment contains the tilting status (UP, DOWN, LEFT, or RIGHT) and shake detection information (SHAKE) when the device is shaken.