Go Down

Topic: serial communication with pic (Read 489 times) previous topic - next topic

Joaquin

hi! i got completely lost on how to do this, since the strategy i thought would work, didn't. I hav an attiny that writtes a byte to a cable on button press. now i need to read that byte with the arduino. i made a while loopwith a digital read function that supposedly recollected and joined again the byte, adding a delay to sync the 8mhz tiny's clock with the arduino uno's clock. the thing is that i got just nonesense bytes, seems that the reading loop goes slower than the tiny's writing.
then, how can i read a supposed 8mhz clock's serial with the arduino?
this is the attiny's code; supposedly writes his "me" byte at 8mhz (see the part with many****).
Code: [Select]
//                 reset -1     8- VCC+
// (analog input 3) pin3 -2     7- pin2 (Analog input 1, SCK)
// (analog input 2) pin4 -3     6- pin1 (PWM, MISO)
//                   GND -4     5- Pin0 (PWM, AREF, MOSI)
//este incremental fue realizado fuera de contaxto para probar al día 10/10/12
int ledPin = 0;
int triggeri=4;
int triggero= 2;
int colectorpin = 3;
int debugpin=1;


int previoustriggerinput=0;

int trigando=0;
int indispuesto=0;

byte me=10101011;

int repeatplease = 2;
int statePin = LOW;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(triggeri, INPUT);
  pinMode(triggero, OUTPUT);
  pinMode(colectorpin, INPUT);
  pinMode(debugpin, OUTPUT);

}

void loop() {
  if (digitalRead(triggeri)>previoustriggerinput){//trigger
    trigando=1000;

    pinMode(colectorpin, INPUT);
    if(digitalRead(colectorpin)){//if it reads something in its output, wait 8
      indispuesto=9;
    }
   
    pinMode(colectorpin, OUTPUT);
    if(indispuesto<1){
      indispuesto--;
      int B=0;
      while(repeatplease>B) //here the byte is written*************************************************
      {
        int C=0;
        while(C<9){
          digitalWrite(colectorpin,bitRead(me,C));
          C++;
        }
        //triggering=triggertime*2;
        B++;
      }
    }
   
  }


  if(statePin==HIGH){
    statePin=LOW;
  }
  else{
    statePin=HIGH;
  }
  digitalWrite(debugpin, statePin);

  if(trigando>5000){
    digitalWrite(triggero, LOW);//over  300, off
    digitalWrite(ledPin, HIGH);
    trigando-=1;
  }
  else if(trigando>5){
    digitalWrite(triggero, HIGH);//between 300 and 1, on
    trigando-=1;
  }
  else{
    digitalWrite(triggero, LOW);//at0, off
    digitalWrite(ledPin, LOW);
  }

  previoustriggerinput=analogRead(triggeri);

}

does anyone has experience with something like this? how could this be done? why do i get nonesense readings?
thanks!

Dyslexicbloke

Your timing is going to be too critical to make bit banging, which is what you are attempting to do, likely to work with just a loop.
Have you looked at the SoftSerial liburary.

Having said that I think both chips have UART's that is Universal Asynchronous Recieve and Tansmit hardware.
you should be able to set them up at the same board rate and just read and right to the buffers.

If you look at the data-sheets to find the functionality and then search for how to implement it in your IDE you should find what you need.
I am pretty sure the Arduino IDE will do most of the work for you, at least at one end.
If I knew where the box was I would probably still want to think outside it!

Feel free to be blunt ... Its how I learn.

Joaquin

thank you very much. i was also trying the infrared communication protocol. when i try your idea, i tell you but it looks that it will take me a lot of time! anyway, i still accept any reference

Go Up