{ Notes }


using and configuring GPIO on Connect Tech Cogwell carrier with Jetson TX2

Posted on | Gpio


The Connect Tech Cogwell carrier board for Nvidia Jetson Tx1/Tx2 provides GPIO ports, these GPIO pins are available in two ways, pins sourced directly through Nvidia Jetson these can be used directly using Linux sysfs utility. Additionally there are GPIO pins sourced directly through I2C GPIO Expanders, these pins can only be used through I2C interface on Linux, on Cogswell board these pins are connected throught P7 GPIO port using external I2C expanders from Exar XRA1200. The instructions provided on connecttech support page are a bit confusing, in this article I will try to explain by configuring and testing GPIO pins on Cogswell board with XRA1200 expanders.

Exar XRA 1200

The XRA 1200 expanders used on Cogswell board is an 8-bit expander with a I2c interface through which GPIO pins can be configured with register address information for further use, additional information on GPIO pins layout of the GPIO pin module and details on physical and logical structure on Cogwell is described in the article GPIO layout on Connect Tech Cogswell Board.

The instructions for configuring GPIO pins on Cogswell are specifically for Exar XRA1200, perhaps it may not work on other expanders.
The I2C expanders register address on XRA1200 is 0x20

GPIO pins on XRA1200 expanders has special purpose register addressing which can be used to obtain and configure GPIO pin information, these register addresses also called as command bytes used to read and write data to registers.

Command Byte Description
GSR (GPIO State Register) - 0x00 The register address is readonly and can be used to get status information of all 7 pins from P7 - P0 on XRA 1200.
GSR (GPIO State Register) - 0x00 Use this address to write out to each of the 7 pins on expander.
GCR (GPIO Configuration Register) - 0x03 This address is used to configure pins to output or input on expander - 0x00 for output and 0x01 for input.

Simple experiment demonstrating GPIO configurations

I will try to explain GPIO pin configuration with a simple I2C configuration and testing experiment. The experiment is based on GPIO pin module on Cogswell at location p7. I will configure pin #2 as output (emitting 3.3v) and remaining pins 1,2,4 as input (no voltage), subsequently to test the configuration and input current on pins is being received, I will redirect the 3.3v outputted from pin #2 to other input pins one at a time. Just to give you an idea of the process:
1. Set all GPIO pins to output 3.3v
2. Set pin #2 as output
3. Set the OCR to specify pin #2 as output
4. Test the values

Ideally to check current on pins a multimeter can be used, engrossingly I created a simple circuit with 4 led's connected to each GPIO pin to module on cogswell board, as a result LEDs will light up when pins outputs 3.3v. Initially are configured as input by the expander therefore LED's are not turned on in the picture below.

A simple circuit with 4 leds powered using GPIO pin module on cogwell
Fig1: Simple circuit with 4 led's powered by GPIO pin module on Cogwell

1. Set all GPIO pins to output 3.3v

The I2C address for XRA 1200 expander is 0x20, all GPIO pins are inputs on startup or reset, firstly lets set them to output by default using configuration address 0x03, the result of i2cdump is shown also LED's lighten up when pins are configured to output 3.3v see picture Fig2.

i2cset -f -y 0x0 0x20 0x03 0x00  
#below is the i2cdump to check result of recent command  
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f 
00: ff ff 00 00 00 00 00 00 00 00 ff ff ff ff ff ff
All LED powered on with all GPIO pins set to output
Fig2: All led's powered on using GPIO pins set to output 3.3v.

2. Set pin #2 only output

To set pin #2 only output and remaining pins as input, the bits in binary needs to be 0111 with hex value 0x07.

i2cset -f -y 0x0 0x20 0x03 0x07  
#I2cdump  
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: f8 ff 00 07 00 00 00 00 00 00 ff ff ff ff ff ff    
One LED powered on
Fig3: Single led on pin #2 powered on rest turned off.

3. Set the OCR (Output Control Register) on pin #2

Now we are using the command byte or OCR 0x01 to set output control on pin #2,

i2cset -f -y 0x0 0x20 0x01 0x08  
# i2cdump  
0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 08 08 00 07 00 00 00 00 00 00 ff ff ff ff ff ff
why do we need to set value 0x08 on OCR?

Because initially we set all pins as output and then we only set pin #2 as ouput now we need to inform Output Control Register that pin #2 is our OCR and also GSR must know about this change. The value hex value 0x08 (binary 1000) which is a address to set pin #2 only as output.

4. Test the values

For testing the values, I am simply redirecting output from pin #2 to each input pin at time, the address from pins 1,3,4 are 0x02, 0x01, 0x04 respectively, so by adding address value 0x08 of pin #2 to each pin representation results in values 0x0a, 0x09, 0x0c respectively. Below is the dumps generated on redirecting output to input pins.

#pin 1 0x02
0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 0a 08 00 07 00 00 00 00 00 00 ff ff ff ff ff ff

#pin 3 0x01
0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 09 08 00 07 00 00 00 00 00 00 ff ff ff ff ff ff

#pin 4 0x04
0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 0c 08 00 07 00 00 00 00 00 00 ff ff ff ff ff ff

Special thanks to Jose Lopez for explaning me I2C mechanism.

References

  1. kdb342: Using GPIO on Connect Tech Jetson TX2/TX1 Carriers
  2. 8-bit GPIO expander XRA1200 documentation