- Arduino to TI Calculator Linking Routines
- 04 Aug 2010 01:42:14 pm
- Last edited by KermMartian on 30 Oct 2014 10:30:38 pm; edited 1 time in total
Important:
This project is outdated. See ArTICL: Arduino TI Calculator Linking Library for the new, better, more understandable library.
I wrote these a few months ago for my Arduino to TI-84+ linking project; I thought they might be useful to others. You basically call resetLines() at the beginning of the program, then par_put and par_get as necessary. Note that these of course use the TI-OS protocol, so you can use them for remote control, program injection, screenshot fetching, and all that fun stuff.
Code:
This project is outdated. See ArTICL: Arduino TI Calculator Linking Library for the new, better, more understandable library.
I wrote these a few months ago for my Arduino to TI-84+ linking project; I thought they might be useful to others. You basically call resetLines() at the beginning of the program, then par_put and par_get as necessary. Note that these of course use the TI-OS protocol, so you can use them for remote control, program injection, screenshot fetching, and all that fun stuff.
Code:
void resetLines();
static int par_put(uint8_t *data, uint32_t len);
static int par_get(uint8_t *data, uint32_t len);
#define TIwhite TIring
#define TIred TItip
#define ERR_READ_TIMEOUT 1000
#define ERR_WRITE_TIMEOUT 2000
#define TIMEOUT 4000
#define GET_ENTER_TIMEOUT 30000
void resetLines() {
pinMode(TIring, INPUT); // set pin to input
digitalWrite(TIring, HIGH); // turn on pullup resistors
pinMode(TItip, INPUT); // set pin to input
digitalWrite(TItip, HIGH); // turn on pullup resistors
}
static int par_put(uint8_t *data, uint32_t len) {
int bit;
int i, j;
long previousMillis = 0;
uint8_t byte;
for(j=0;j<len;j++) {
byte = data[j];
for (bit = 0; bit < 8; bit++) {
previousMillis = 0;
while ((digitalRead(TIring)<<1 | digitalRead(TItip)) != 0x03) {
if (previousMillis++ > TIMEOUT)
return ERR_WRITE_TIMEOUT+j+100*bit;
};
if (byte & 1) {
pinMode(TIring,OUTPUT);
digitalWrite(TIring,LOW);
previousMillis = 0;
while (digitalRead(TItip) == HIGH) {
if (previousMillis++ > TIMEOUT)
return ERR_WRITE_TIMEOUT+10+j+100*bit;
};
resetLines();
previousMillis = 0;
while (digitalRead(TItip) == LOW) {
if (previousMillis++ > TIMEOUT)
return ERR_WRITE_TIMEOUT+20+j+100*bit;
};
} else {
pinMode(TItip,OUTPUT);
digitalWrite(TItip,LOW); //should already be set because of the pullup resistor register
previousMillis = 0;
while (digitalRead(TIring) == HIGH) {
if (previousMillis++ > TIMEOUT)
return ERR_WRITE_TIMEOUT+30+j+100*bit;
};
resetLines();
previousMillis = 0;
while (digitalRead(TIring) == LOW) {
if (previousMillis++ > TIMEOUT)
return ERR_WRITE_TIMEOUT+40+j+100*bit;
};
}
byte >>= 1;
}
//delayMicroseconds(6);
}
return 0;
}
static int par_get(uint8_t *data, uint32_t len) {
int bit;
int i, j;
long previousMillis = 0;
for(j = 0; j < len; j++) {
uint8_t v, byteout = 0;
for (bit = 0; bit < 8; bit++) {
previousMillis = 0;
while ((v = (digitalRead(TIring)<<1 | digitalRead(TItip))) == 0x03) {
if (previousMillis++ > GET_ENTER_TIMEOUT)
return ERR_READ_TIMEOUT+j+100*bit;
}
if (v == 0x01) {
byteout = (byteout >> 1) | 0x80;
pinMode(TItip,OUTPUT);
digitalWrite(TItip,LOW); //should already be set because of the pullup resistor register
previousMillis = 0;
while (digitalRead(TIring) == LOW) { //wait for the other one to go low
if (previousMillis++ > TIMEOUT)
return ERR_READ_TIMEOUT+10+j+100*bit;
}
//pinMode(TIring,OUTPUT);
digitalWrite(TIring,HIGH);
} else {
byteout = (byteout >> 1) & 0x7F;
pinMode(TIring,OUTPUT);
digitalWrite(TIring,LOW); //should already be set because of the pullup resistor register
previousMillis = 0;
while (digitalRead(TItip) == LOW) {
if (previousMillis++ > TIMEOUT)
return ERR_READ_TIMEOUT+20+j+100*bit;
}
//pinMode(TItip,OUTPUT);
digitalWrite(TItip,HIGH);
}
pinMode(TIring, INPUT); // set pin to input
digitalWrite(TIring, HIGH); // turn on pullup resistors
pinMode(TItip, INPUT); // set pin to input
digitalWrite(TItip, HIGH); // turn on pullup resistors
}
data[j] = byteout;
//delayMicroseconds(6);
}
return 0;
}