Hi Very Happy
I'm relatively new to assembler but my goal is to send a message from a ti-83 plus to an arduino and then some data back. The sending from the calculator works without any problems with the _SendAByte bcall. But when I try to get bytes using the _RecAByteIO bcall something strange happens.

Code:
.NOLIST
#define   EQU   .equ
#define   equ   .equ
#define   END   .end
#define   end   .end
#include "ti83plus.inc"
.LIST
   .org 9D93h
   .db $BB,$6D
   
   ld hl,$86EC
   ld (hl),1

   errhandon(err)
   B_CALL(_RecAByteIO)
   errhandoff()
   ld hl,$86EC
   ld (hl),a
   ret
err:
   ret
end

If I don't plug in the cable the address 86EC holds the expected 1. But when I plug it in, the address holds 157 regardless of the byte I send from the arduino.
To send and receive on the arduino I use the sendByte and getByte function of the ArTICL library. I tested the library using the typewriter example and it works perfect, so there shouldn't be a problem on the arduino side.
Could it be, that the bcall itself isn't working and if yes is there another way to receive single bytes?
I hope somebody has an idea of where the problem lies and can help me Smile
Does it look like your ASM program on the calculator correctly waits until the Arduino sends a byte, or does the program complete even if the Arduino doesn't send a byte? I strongly recommend using the following to check the value of ($86EC) before the program ends:
Code:
ld a,($86EC)
ld l,a
ld h,0
bcall(_disphl)
bcall(_getkey) ; Like Pause
In addition, please add a string + _Puts between the err: label and the ret so that you know if the error condition has been hit.
I tried the changes you suggested:
If I dont plug in the cable it waits approximatly 1.1 seconds like specified in the manual and then the error condition is hit. If I do plug in the cable it doesn't hit the error condition and displays 157 before waiting for key presses. After I press any key the programm ends normally.
Okay, let's try this the other way around, then. What does your Arduino code look like?

Code:
#include "TICL.h"

TICL* ticl;
int lineTip = DEFAULT_TIP;
int lineRing = DEFAULT_RING;

void setup() {
  Serial.begin(9600);
  ticl = new TICL(lineTip, lineRing);
  ticl->resetLines();
  //ticl->setVerbosity(true, &Serial);
}

void loop() {
  ticl->sendByte(255);
  delay(500);
}


And sendByte :


Code:
int TICL::sendByte(uint8_t byte) {
   unsigned long previousMicros;
   if (serial_) {
      serial_->print("Sending byte ");
      serial_->println(byte);
   }

   // Send all of the bits in this byte
   for(int bit = 0; bit < 8; bit++) {
      
      // Wait for both lines to be high before sending the bit
      previousMicros = micros();
      while (digitalRead(ring_) == LOW || digitalRead(tip_) == LOW) {
         if (micros() - previousMicros > TIMEOUT) {
            resetLines();
            return ERR_WRITE_TIMEOUT;
         }
      }
      
      // Pull one line low to indicate a new bit is going out
      bool bitval = (byte & 1);
      int line = (bitval)?ring_:tip_;
      pinMode(line, OUTPUT);
      digitalWrite(line, LOW);
      
      // Wait for peer to acknowledge by pulling opposite line low
      line = (bitval)?tip_:ring_;
      previousMicros = micros();
      while (digitalRead(line) == HIGH) {
         if (micros() - previousMicros > TIMEOUT) {
            resetLines();
            return ERR_WRITE_TIMEOUT;
         }
      }

      // Wait for peer to indicate readiness by releasing that line
      resetLines();
      previousMicros = micros();
      while (digitalRead(line) == LOW) {
         if (micros() - previousMicros > TIMEOUT) {
            resetLines();
            return ERR_WRITE_TIMEOUT;
         }
      }
      resetLines();
      
      // Rotate the next bit to send into the low bit of the byte
      byte >>= 1;
   }

   return 0;
}
Your Arduino code looks correct to me. If you comment in the setVerbosity line and watch your serial console, does it appear that ArTICL is successfully sending the 255 byte?
I just found the problem Smile

Code:
errhandon(err)
B_CALL(_RecAByteIO)
errhandoff()
ld hl,$86EC
ld (hl),a


According to the ti83plus.inc file the "errhandoff()" gets replaced with "call 5Ch". It appears that the code at 5Ch is modifying register A, which should hold the received byte. So when I change the code to

Code:
errhandon(err)
B_CALL(_RecAByteIO)
ld hl,$86EC
ld (hl),a
errhandoff()

it works without any problems.
Thank you for your quick responses, it's good to now that there's a place on the internet where I can ask my questions, even if they are very specific and still get good and quick answers. Very Happy
Ahhh, of course. That was a silly oversight on my part. Nice catch! And I'm glad you experience us as prompt and helpful; we aim to please. If you're just getting started with z80 ASM, Arduino programming, and/or electronics, we're more than happy to help. While you're at it, please Introduce Yourself in our topic for that purpose if you get a chance.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement