Skip to main content

SPI, I2C and UART

The AT1000 device supports SPI, I2C, and UART communication protocols, allowing for flexible integration with various peripherals and systems. This is internally implemented using an FT2232H chip, which provides a versatile interface for communication.

As you will see in this section, it's possible to set the voltage level of the communication interface, allowing you to connect to devices with different voltage levels (from 1.6V to 5.0V).

Only master mode

Please note that the AT1000 device only supports master mode for SPI and I2C communication. This means that it can initiate communication with slave devices, but it cannot act as a slave itself.

Multiplexing Considerations​

Some interfaces share the same GPIO pins, so only one can be used at a time. To help you choose the right configuration for your project, check out the multiplexing tables in the introduction. The diagrams below also give you a clear view of how the communication interfaces are mapped to the AT1000’s GPIO pins.

User friendly multiplexing!

In order to avoid any confusion, we recommend following this standard procedure when using an industrial communication port:

  1. Start by enabling the communication
  2. Disable to port when done using it.

If there are any conflicts (e.g. enabling an interface before disabling another one that uses the same resources), an error will be raised during the enable() phase, allowing you to easily detect and correct any conflicts.

SPI BUS usage​

The example code below shows how to enable the SPI bus, set the baud rate, and transmit/receive data.

Note about CS lines

CS lines are handled as regular I/Os. This means that you can use any free GPIO pin as a CS line. However, you need to manually control the CS line before and after the SPI transaction, as shown in the examples below.

const at1000 = require("at1000");
let devices = at1000.find_devices(5); // Find devices with a 5s timeout
let tester = devices[0]; // Target the first detected device
let spi = tester.spi(0); // Select the first SPI bus
var cs_pin = tester.digital_io(5, 0); // GPIO 5 on master device
cs_pin.config_output(3.3, 0, true); // VIH = 3.3V, VIL = 0V, set to high level

// Enable SPI bus with a target VCC of 3.3V
// Effectively connecting the SPI pins the dedicated IO pins
spi.enable(3.3));

spi.set_baud(1000000); // Set baud rate to 1MHz

// Do an SPI transaction
cs_pin.write(0); // Set CS line to low
let rx_data = spi.trx([0xDE, 0xAD, 0xBE, 0xEF]); // Send and receive 4 data bytes
cs_pin.write(1); // Set CS line to high

// Disable SPI bus on AT1000 master
spi.disable();

I2C BUS usage​

The example code below shows how to enable the I2C bus, set the baud rate, and transmit/receive data.

const at1000 = require("at1000");
let devices = at1000.find_devices(5); // Find devices with a 5s timeout
let tester = devices[0]; // Target the first detected device
let i2c = tester.i2c(0); // Select the first I2C bus

i2c.enable(3.3); //Enable I2C bus with a target VCC of 3.3V
i2c.set_baud(100000); // Set baud rate to 100KHz

// Define an I2C transaction

let i2c_transaction = {
address: 0x50, // I2C address of the slave device
start: true, // Start condition
stop: true, // Stop condition
nack_last_byte: false, // NACK the last byte
};

// Write request to the slave device 0x50, registers 0x10 and 0x20
i2c.tx(0x50, [0x10, 0x20], i2c_transaction);

i2c_transaction.nack_last_byte = true;
// Read 4 bytes from the slave device 0x50
let data = i2c.rx(0x50, 4, i2c_transaction);
// Disable I2C bus on AT1000 master
i2c.disable();

UART Bus usage​

The example code below shows how to enable the UART bus, set the baud rate, and transmit/receive data.

const at1000 = require("at1000");
let devices = at1000.find_devices(5); // Find devices with a 5s timeout
let tester = devices[0]; // Target the first detected device
let uart = tester.uart(0); // Select the first UART bus

uart.enable(5.0); //Enable UART bus with a target VCC of 5.0V);
uart.set_baud(115200); // Set baud rate to 115200

// Start receiving and buffering UART messages
//This will also reset the RX buffer
uart.start_rx();

// Transmit a message over UART
uart.tx("Hello AT1000");

// Receive data (returns a string)
let data_rx = uart.rx();

uart.stop_rx(); // Stop receiving UART messages

// Print received message
console.log("RS232 Data Received:", data_rx);

// Disable RS232_1 bus
tester.rs232(1, 0).disable();

Summary​

The AT1000 provides SPI buses, I2C buses and UART buses with advanced control features.

These interfaces allow flexible testing of communication ports.