Go Down

Topic: Rolling my own software serial variant (Read 514 times) previous topic - next topic

BungaDunga

First off, I'm pretty much entirely a newbie at the Arduino, microcontrollers in general, and C in general. But I'm quite good at messing around and figuring things out.

Anyway, I've posted before on this topic, but since then I have been first very busy, then Windowsless, then computerless, then busy... and so on. Finally getting around to working a bit with it. Basically I want to get my TI83+ calculator to talk to my Arduino, and vice versa. I have managed to get it to work, but I want to package it into an interrupt-driven library so I can (for example) run bitlash over the link. What's the easiest way to do this, do you think?

Code: [Select]

void sendByte(byte toSend){
 byte b1 = 0;
 int pin0 = 6;
 int pin1 = 7;
 for ( b1 =0;b1<=7;b1++){
   if(toSend & 1){
     pinMode(pin0,OUTPUT);
     digitalWrite(pin0,LOW);
     while(digitalRead(pin1)==1) {}
     pinMode(pin1,INPUT);
     pinMode(pin0,INPUT);
     while(digitalRead(pin1)==0) {}
   }else{
     pinMode(pin1,OUTPUT);
     digitalWrite(pin1,LOW);
     while(digitalRead(pin0)==1) {}
     pinMode(pin1,INPUT);
     pinMode(pin0,INPUT);
     while(digitalRead(pin0)==0) {}
   }
   toSend = toSend>>1;
//    delayMicroseconds(188);
 }
}
byte getByte(void){
 byte out = 0;
 int bit;
 int pin0 = 6;
 int pin1 = 7;
 for(bit=0; bit<8; bit++) {
   while((digitalRead(pin0) == 1) && (digitalRead(pin1) == 1)){}
   if( digitalRead(pin0) == LOW ){
      pinMode(pin1,OUTPUT);
      digitalWrite(pin1,LOW);
      while( digitalRead(pin0) == LOW ) {}
      pinMode(pin1,INPUT);
      pinMode(pin0,INPUT);
      out = (out >> 1) | 0x80;
   }else{
     pinMode(pin0,OUTPUT);
     digitalWrite(pin0,LOW);
     while( digitalRead(pin1) == LOW ) {}
     pinMode(pin1,INPUT);
     pinMode(pin0,INPUT);
     out = out >> 1;
    }
 }
 return out;
}



Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy