| 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
TWIS Slave and TWI Master mode drivers Example
This information applies to the nRF52 Series only.

This example demonstrates how to use the following two drivers:

- TWIS driver (in asynchronous mode)
- TWIS driver (in synchronous mode)

# Master

EEPROM memory is simulated using the internal RAM of ATMEL's AT24C01C device which includes 128 bytes of memory. This RAM area is only accessed by the simulated EEPROM while the rest of the application must use hardware configured TWI commands to access RAM.

The selected memory chip has a 7-bit address constant. During a write operation, a word is selected to access the memory. The first byte sent is used as the current address pointer.

During a single access, the entire memory can be read and a maximum of an 8-byte page can be written.

The following are differences between the actual chip and the simulated chip:

1. The simulated chip has close to 0 ms of write time. This example does not poll the memory for readiness.
2. When the end of the memory is reached during a sequential read, zeros are sent. There is no support for roll-over.
3. A maximum of 8 bytes can be written in a single sequential write. But in the simulated EEPROM, the entire address pointer is incremented. In a chip, only the 3 lowest bits change during writing and would therefore roll-over in memory page.

# Master

The Master communicates with the EEPROM memory and additonally has read and write access. Simple UART commands can be used to check the memory.

Pins to short (see config.h file example directory):

- TWI_SCL_M - EEPROM_SIM_SCL_S
- TWI_SDA_M - EEPROM_SIM_SDA_S

Supported commands are listed in the welcome message.

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

# Testing

Test the TWIS slave and TWI master mode drivers example application by performing the following steps:

1. The pins should be shorted as described above.
2. Compile and program the application.
3. 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
4. Read the welcome message.
5. After each command below, check if the following warning appears:
   `WARNING: EEPROM transmission error detected.`
6. Send p command. Data read from the simulated EEPROM should contain values from 0x7f down to 0.
7. Send w command and write any string longer than 8 characters. Hit Enter.
8. Send p command again and look to see if your string is at the beginning of the memory.
9. Send c command to clear EEPROM.
10. Send p command again and see if all values are 0xff.