Author Topic: How to use the link port  (Read 10607 times)

0 Members and 1 Guest are viewing this topic.

Offline Torio

  • LV3 Member (Next: 100)
  • ***
  • Posts: 83
  • Rating: +22/-0
    • View Profile
Re: How to use the link port
« Reply #30 on: February 22, 2012, 11:05:43 am »
Exactly. Sometimes 255, sometimes 65535.
Sorry about my mistakes, I'm French.

Projects :  Pokemon TI-89 | Ti-Tank

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4687
  • Rating: +718/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: How to use the link port
« Reply #31 on: February 22, 2012, 11:16:12 am »
I looked at the Axe stuff and in 1.1.1 it seems to only be able to return 255 if it detects that the receiver is ready (and the receiver sends 255). So I am curious, what calculators were you using?

Offline Torio

  • LV3 Member (Next: 100)
  • ***
  • Posts: 83
  • Rating: +22/-0
    • View Profile
Re: How to use the link port
« Reply #32 on: February 22, 2012, 11:22:59 am »
Sender and Reciever : TI-83+ (fr).
I can't test right now because I don't have 2 calculators, but when I tested it, I added an Output to see why the byte recieved was wrong, and it was 255.
Sorry about my mistakes, I'm French.

Projects :  Pokemon TI-89 | Ti-Tank

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: How to use the link port
« Reply #33 on: February 25, 2012, 04:45:12 am »
Sorry if this is difficult to follow, I didn't really know how to structure the diagram (if you want to call it a diagram). If you have any questions, just ask. Otherwise, I hope this helps!

Code: [Select]
SENDER RECEIVER
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Pull ring low

Repeat up to [ARG 2]*8μs If ring is not low, abort
 | If tip is low, break from loop Pull tip low
If tip is not low, abort

Release tip
Received byte = 0

LOOP 8 TIMES LOOP 8 TIMES
 | Release ring, pull tip low |
 | Wait ~21μs | Wait until tip == ring
 | Rotate byte to send left |
   | If 0 rotated out, pull ring low |
   | If 1 rotated out, release tip |
 | Wait ~12μs | If tip is low, rotate 0 left into byte
 | | If tip is high, rotate 1 left into byte

Release tip and ring
D: It's not quite clear to me when I have to add delays. This is what I understood:
Code: [Select]
Function get:
If ring is low
 Pull down tip
 Delay
 Release tip
 Set byte to 0 by default
 Loop 8 times
  Wait until tip and ring are equal
   If tip is low
    bit received is 0
  otherwise
    bit received is 1
  Delay 12μs
 End of loop
otherwise
Return -1
End
Return received byte
Added some delays. Otherwise the receiver would just receive a lot of the same (1 or 0)


Code: [Select]
Function send:
Pull ring low
Loop until time runs out
 If tip is low, break from loop
End loop
If time ran out
 Return -1;
Loop 8 times
 Release ring
 pull down tip
 Delay 21μs
 If the bit is 1
  pull ring low
 otherwise
  release tip
 Wait 12μs
End of loop
Release tip and ring

Code: [Select]
void setup(){
 pinMode(2,INPUT);
 pinMode(3,OUTPUT);
 digitalWrite(2,HIGH);//ring release
 digitalWrite(3,HIGH);//tip release
 Serial.begin(9600);
}
int Get(){
 if (digitalRead(2)==LOW) {
  digitalWrite(3,LOW);//pull tip down
  delayMicroseconds(12);
  digitalWrite(3,HIGH);//release tip
  int recvbyte=0;
  for(int i=7; i>=0; i--){
   while (digitalRead(2)!=digital
 Read(3)){}//wait until tip==ring
   if (digitalRead(2)==HIGH){
    bitSet(recvbyte,i);
   }
   while (digitalRead(2)==digitalRead(3)){}
  }
  return recvbyte;
 }
 else {
   
   return 0;
 }
 
}
void loop(){
  Serial.println(Get());
  delay(1000);
}
I ported it to arduino. Lemme tell ya: It doesn't work at all :| Do I have to count cycles???
« Last Edit: February 25, 2012, 05:17:18 am by Keoni29 »
If you like my work: why not give me an internet?








Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: How to use the link port
« Reply #34 on: February 25, 2012, 06:59:38 pm »
The problem with Torio's code is that its not checking if send was successful.  Also, the wait time is dangerously low as the Get could easily miss it, probably resulting in the byte 255 being received during the next iteration of the loop.  Your pause time should be at least 1000.  I recommend over 5000 to be absolutely safe.  I notice in your code, you receive a byte in between sending.  I'm guessing this is because you want to make sure the first byte sent, but this is definitely the WRONG way to do it.  Here is some example code to send 2 bytes:

:Lbl SEND
:Repeat Send({or1},5000)
:  If getkey(15)
:    Return 0
:  End
:End
:Return Send({or1+1},20000)


This has the same IO as the 1 byte Send command as well as the feature that it will continue to try until it is successful or the clear key is pressed.  The Receive command would be:

:Lbl GET
:!If Get→r1+1
:  Return -1
:End
:Pause 2
:!If Get→r2+1
:  Return -1
:End
:Return r2*256+r1


Again, same IO as regular Get.
« Last Edit: February 25, 2012, 07:04:40 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: How to use the link port
« Reply #35 on: March 01, 2012, 03:26:19 pm »
I still wonder why my code doesn't work. Do I have to count cycles??
If you like my work: why not give me an internet?








Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: How to use the link port
« Reply #36 on: March 04, 2012, 07:33:28 am »
Can someone please help me with my code D:
If you like my work: why not give me an internet?








Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: How to use the link port
« Reply #37 on: February 04, 2013, 10:40:54 am »
Heavy bump,

I don't know if you're still on this (I doubt), but since I am (:P), I answer to that.

I think there is a simpler way to receive a byte from the calc with Arduino :

int ring = 2, tip = 3; // let's say that the ring is port 2 and the tip port 3
int gotByte, byteCounter;

void setup(void)
{
  Serial.begin(9600);
}

int getByte(void)
{
  if (digitalRead(ring) == LOW)
  {
    digitalWrite(tip, LOW);
    delayMicroseconds(12);
    digitalWrite(tip, HIGH);
    gotByte = (byteCounter = 0); // yeah, I'm lazy

    while(byteCounter < 8 )
    {
      if(digitalRead(tip) == digitalRead(ring))
      {
        if(digitalRead(tip) == HIGH) gotByte |= 0x80; // sets the 7th bit
        gotByte >>= 1; // shift the whole byte right
        byteCounter++;
      }
    }
  }
  return gotByte;
}

void loop(void)
{
  Serial.println(getByte());
}

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: How to use the link port
« Reply #38 on: February 12, 2013, 09:15:37 am »
Oh I already figured out how to pull it off. I just use a two wire interface with one clock and one data line. The clock line should be controlled by the host device. When the host would like to send something it just does that. When the device wants to send something to the host it has to wait for the host to poll the device. It's not the most efficient, but it is stable and reliable.
If you like my work: why not give me an internet?