Difference between revisions of "TS-8100 DIO header"

From Technologic Systems Manuals
Line 1: Line 1:
The TS-8100 includes a 2x8 0.1" pitch header with 8 DIO, I2C, and SPI.  Most DIO on this header are rated for 3.3V and are not tolerant of 5V IO.  The only exception is SPI_MOSI which is 5V tolerant.  The DIO on this baseboard can be accessed by manipulating the [[#Baseboard Register Map|TS-8100 Register Map]], or using [[#tsctl|tsctl]].
The TS-8100 includes a 2x8 0.1" pitch header with 8 DIO, I2C, and SPI.  Most DIO on this header are rated for 3.3V and are not tolerant of 5V IO.  The only exception is SPI_MOSI which is 5V tolerant.  The DIO on this baseboard can be accessed by manipulating the [[#Baseboard Register Map|TS-8100 Register Map]], or using [[#tsctl|tsctl]]. This header is designed to connect to the [[KPAD]] accessory which uses the odd DIO on this header to scan a 4x4 keypad. 


This example scans the [[KPAD]] and prints out the pressed character.  This requires a running tsctl server, and a libtsctl source directory on the board to compile:
<source lang=c>
<source lang=c>
/* KPAD 4x4 keypad example code
*
* To compile, copy to the libtsctl directory and run:
* gcc kpad.c -Inet -Its -I . -o kpad        */


#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include "nettsctl.h"
int main()
{
int row, col, i, dio_blk[8];
tsctl *conn;
DIO *dio;
System *sys;
char *keys[4][4] = {
{ "1", "2", "3", "UP" },
{ "4", "5", "6", "DOWN" },
{ "7", "8", "9", "2ND" },
{ "CLEAR", "0", "HELP", "ENTER" }
};
conn = TsctlClient("127.0.0.1",NetModeBlocking);
if (!conn) {
perror("Couldn't connect to TSCTL server");
return 1;
}
dio = NetDIOInit(conn, 0);
sys = NetSystemInit(conn, 0);
if(sys->BaseBoardId(sys) != 0x8100) {
fprintf(stderr, "Wrong Baseboard.\n");
return 1;
}
// Lookup DIO (odds) 1-15 on the TS-8100
for(i = 0; i < 8; i++) {
char nm[13];
snprintf(nm, 12, "8100_DIO_%d", (i*2)+1);
dio_blk[i] = sys->MapLookup(sys, ASCIIZ(nm));
// Set first 4 as outputs, last 4 as inputs
if(i < 4)
dio->SetAsync(dio, dio_blk[i], HIGH);
else
dio->SetAsync(dio, dio_blk[i], INPUT);
}
while(1) {
for(row = 0; row < 4; row++) {
dio->SetAsync(dio, dio_blk[row], LOW);
usleep(1000);
for(col = 4; col < 8; col++) {
if(dio->GetAsync(dio, dio_blk[col]) == INPUT_LOW) {
usleep(80000);
if(dio->GetAsync(dio, dio_blk[col]) == INPUT_LOW) {
printf("%s ", keys[row][col - 4]);
fflush(stdout);
}
}
}
dio->SetAsync(dio, dio_blk[row], HIGH);
}
}
return 0;
}
</source>
</source>



Revision as of 06:59, 12 February 2013

The TS-8100 includes a 2x8 0.1" pitch header with 8 DIO, I2C, and SPI. Most DIO on this header are rated for 3.3V and are not tolerant of 5V IO. The only exception is SPI_MOSI which is 5V tolerant. The DIO on this baseboard can be accessed by manipulating the TS-8100 Register Map, or using tsctl. This header is designed to connect to the KPAD accessory which uses the odd DIO on this header to scan a 4x4 keypad.

This example scans the KPAD and prints out the pressed character. This requires a running tsctl server, and a libtsctl source directory on the board to compile:

/* KPAD 4x4 keypad example code
 *
 * To compile, copy to the libtsctl directory and run:
 * 	gcc kpad.c -Inet -Its -I . -o kpad        */

#include <stdio.h>
#include <stdint.h>
#include <unistd.h>

#include "nettsctl.h"

int main()
{
	int row, col, i, dio_blk[8];
	tsctl *conn;
	DIO *dio;
	System *sys;

	char *keys[4][4] = {
		{ "1", "2", "3", "UP" },
		{ "4", "5", "6", "DOWN" },
		{ "7", "8", "9", "2ND" },
		{ "CLEAR", "0", "HELP", "ENTER" }
	};

	conn = TsctlClient("127.0.0.1",NetModeBlocking);
	if (!conn) {
		perror("Couldn't connect to TSCTL server");
		return 1;
	}
	dio = NetDIOInit(conn, 0);
	sys = NetSystemInit(conn, 0);
	if(sys->BaseBoardId(sys) != 0x8100) {
		fprintf(stderr, "Wrong Baseboard.\n");
		return 1;
	}

	// Lookup DIO (odds) 1-15 on the TS-8100
	for(i = 0; i < 8; i++) {
		char nm[13];
		snprintf(nm, 12, "8100_DIO_%d", (i*2)+1);
		dio_blk[i] = sys->MapLookup(sys, ASCIIZ(nm));
		// Set first 4 as outputs, last 4 as inputs
		if(i < 4)
			dio->SetAsync(dio, dio_blk[i], HIGH);
		else
			dio->SetAsync(dio, dio_blk[i], INPUT);
	}

	while(1) {
		for(row = 0; row < 4; row++) {
			dio->SetAsync(dio, dio_blk[row], LOW);
			usleep(1000);
			for(col = 4; col < 8; col++) {
				if(dio->GetAsync(dio, dio_blk[col]) == INPUT_LOW) {
					usleep(80000);
					if(dio->GetAsync(dio, dio_blk[col]) == INPUT_LOW) {
						printf("%s ", keys[row][col - 4]);
						fflush(stdout);
					}
				}
			}
			dio->SetAsync(dio, dio_blk[row], HIGH);
		}
	}

	return 0;
}

If you receive a "socket error", see the tsctl chapter for information on setting up and running the tsctl server.

Pinout Header
Pin Name Notes
1 8100_DIO_1 Pulled high by R124
2 Ground
3 8100_DIO_3 Pulled high by R123
4 I2C_CLK
5 8100_DIO_5 Pulled high by R122
6 SPI_CS
7 8100_DIO_7 pulled high by R121
8 I2C_DAT
9 8100_DIO_9 Pulled high by R120
10 SPI_MISO
11 8100_DIO_11 Pulled high by R119
12 SPI_MOSI
13 8100_DIO_13 Pulled high by R118
14 SPI_CLK
15 8100_DIO_15 Pulled high by R117
16 CPU_3.3V
16 15
14 13
12 11
10 9
8 7
6 5
4 3
2 1