GPIO pin usage of Jetson TX2 NX

Jetson TX2 NX is a high-performance embedded AI computing platform, where the design and use of pins is very important for developers. In this article, we will introduce the pins of Jetson TX2 NX and explain its function and usage.

Official Documentation Official Documentation
insert image description here

Pin Overview

The Jetson TX2 NX has many different types of pins, including digital input/output (GPIO), serial peripheral interface (SPI), I²C, UART, and more. These pins help to communicate with other peripherals such as sensors, cameras, LCD displays, WiFi modules, etc.
insert image description here

40-pin GPIO pin

GPIO pins can be used as input or output ports, they provide a digital level to allow the user to control or read on external devices. The Jetson TX2 NX has a total of 198 GPIO pins grouped into three different pin groups: J1, J21, and J22. Each pin group has digital input/output and PWM functions.
Below is the pinout of the TX2 NX 40-pin GPIO expander:
insert image description here

SPI pin

SPI is a serial communication protocol that can be used to interface with several peripherals. The Jetson TX2 NX provides two SPI buses on the J1 and J21 pin groups. Each SPI bus has the following pins:

  • MOSI (Master Out, Slave In): master device data output, slave device data input.
  • MISO (Master In, Slave Out): master device data input, slave device data output.
  • SCK (Clock): clock signal.
  • CS (Chip Select): chip selection signal.

I²C pull leg

I²C is a serial communication protocol that can be used to interface several peripherals. The Jetson TX2 NX provides two I²C buses on the J1 and J21 pin sets. Each I²C bus has the following pins:

  • SDA (Serial Data): Serial data signal.
  • SCL (Serial Clock): Serial clock signal.

UART pin

UART is an asynchronous serial communication protocol that allows data to be transferred over pins at a certain rate. Jetson TX2 NX has a total of 6 UART pins on the J1 and J21 pin groups, and each UART pin has the following pins:

  • RXD (Receive Data): Receive data.
  • TXD (Transmit Data): Send data.
  • CTS (Clear to Send): Clear to send signal.
  • RTS (Ready to Send): Send signal ready.

How to use

To use Jetson TX2 NX pins, the corresponding device tree node must be enabled in the Linux system first. The device tree node is a data structure describing the hardware configuration, which defines the register address, interrupt number and other information related to the pin. The device tree can be found under the /boot directory with the name "tegra210-p3448-0000-pinmux.dtsi".

In the device tree, each pin has a unique name and number. To use a pin, refer to it by its name or number in the application. Many different programming languages ​​and toolkits can be used to control a pin, such as Python, C++, C, etc.

Below is a sample code for controlling GPIO pins using the Python GPIO library:

import Jetson.GPIO as GPIO

# 设置GPIO模式
GPIO.setmode(GPIO.BOARD)

# 配置GPIO为输出引脚
GPIO.setup(12, GPIO.OUT)

# 设置GPIO引脚电平为高电平
GPIO.output(12, GPIO.HIGH)

# 设置GPIO引脚电平为低电平
GPIO.output(12, GPIO.LOW)

# 清理GPIO设置
GPIO.cleanup()

This code demonstrates how to set a GPIO pin as an output and set its level high or low. Similar code can be used to control the Jetson TX2 NX's 40-pin GPIO expander pins. Let's explain the code in some detail:

import Jetson.GPIO as GPIO

First, we import the GPIO module using the Jetson.GPIO library.

GPIO.setmode(GPIO.BOARD)

Next, we set the GPIO mode to BOARD mode, which means we will use the pin number on the board to identify each pin.

GPIO.setup(12, GPIO.OUT)

We then configured pin 12 as an output and specified the output mode using the GPIO.OUT constant.

GPIO.output(12, GPIO.HIGH)

Next, we set the level of pin 12 to high level, which is 3.3V level.

GPIO.output(12, GPIO.LOW)

Then, we set the level of pin 12 to low level, which is 0V level.

GPIO.cleanup()

Finally, we call the GPIO.cleanup() function to clean up all GPIO settings and shut down the GPIO module.

It should be noted that the Jetson GPIO library has two modes: BOARD and BCM. BOARD mode uses physical pin numbering, while BCM mode uses Broadcom SOC Channel (SOC channel) numbering. During the development process, please pay attention to select the appropriate mode to match your hardware connection method.

Summarize

By using the Jetson GPIO library, we can easily control the pins on the Jetson TX2 NX's 40-pin GPIO expander. Using the Python language, we can quickly write code to read and control the status of external devices. The GPIO interface of Jetson TX2 NX is a very useful tool that can help us easily integrate the board with other devices to achieve various application scenarios.

Guess you like

Origin blog.csdn.net/qq_42076902/article/details/131264217