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]]. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{| | {| | ||
Line 154: | Line 80: | ||
| | | | ||
− | + | [[File:TS-8100-DIO.png|400px]] | |
− | + | ||
− | |||
− | |||
− | |||
− | | | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|} | |} | ||
− | | | + | 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> | ||
+ | /* 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> | ||
+ | |||
+ | If you receive a "socket error", see the [[#tsctl|tsctl]] chapter for information on setting up and running the tsctl server. |
Revision as of 09:30, 5 June 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.
Pinout | Header | |||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
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.