help pls!!

hi guys,
i have a problem.
I have programmed an frequency gene. and it all works well, but now i thought i would be nice to let the pc communicate with arduino board to change the frequencys without uploading a new software at the board.

Here the Code
Code:

int fr1=640,fr2=533,fr3=457,fr4=400,fr5=355;
int fr1d=40;
int tim=0,tim2=0,tim3=0,tim4=0,tim5=0;

int funktionsaufruf=0;
int count=0;
int val1[15];
int param[7];
int mult=1;
int mult_cur=0;
int freq_cur=0;
int c=0;
char command[20];

void setup()
{
TCCR1A = ( (1 << COM1A0) | (1 << COM1B0));
//TCCR1B = ( (1 << CS11) | (1 << CS10) );
TCCR1B = ( (1 << CS10) );
TIMSK1 = (1 << OCIE1A);
sei();
OCR1A = 250;
DDRB |= ( (1 << PB1) | (1 << PB2) | (1 << 0) );
DDRD |= ( (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) );
Serial.begin(9600);
}

void loop()
{

if((Serial.available() > 0) && (count < 15) ){

val1[count] = Serial.read();
Serial.flush();
count++;
}

if((Serial.available() == 0) && count >= 15)
{
Serial.flush();
for(int i=0;i<15;i++)
Serial.print(val1*,BYTE);*

count =0;
}

}
ISR(TIMER1_COMPA_vect) {

  • OCR1A = OCR1A + 250;*

tim=tim+1;
tim2=tim2+1;
tim3 += 1;
tim4 += 1;
tim5 += 1;
if(fr1 == tim){

  • PORTD ^= (1 << 6);*

  • tim =0;*

  • }*

if(fr2 == tim2){

  • PORTD ^= (1 << 5);*

  • tim2 =0;*

  • }*

  • if(fr3 == tim3){*

  • PORTD ^= (1 << 4);*

  • tim3 =0;*

  • }*

  • if(fr4 == tim4){*

  • PORTD ^= (1 << 3);*

  • tim4 =0;*

  • }*

  • if(fr5 == tim5){*

  • PORTD ^= (1 << 2);*

  • tim5 =0;*

  • }*

}
So the Program should readsomething and give it back.
the problem is that after an reboot, by pushing the button on the board or opening and closing the Serial Monitor in the arduino software (i have read it does also reboot the board), the program doesn't work , only after uploading the software again it does work, so what can it be
(my english isn't perfect, so if something isn't clear just ask)
so thanks.

have forgot to tell that only the sending back to the pc doesn't work after roboot.

How about removing the check for Serial.available after you get 15 chars as per the fragment below:

if(count >= 15) {
if(count >15){
Serial.print(“logic error, count > 15”); // this should not happen!
}
else{
for(int i=0;i<count;i++)
Serial.print(val1*,BYTE);*

  • }*
  • count =0;*
    }

no that's not the problem.

probably someone knows what happend when you upload an software in the arduino, because after the upload it does work but after an reboot it doesnt work anymore.
probably there is set something ?

So it works once, immediately after the upload. And then never works again after you reset. Does it work when you power off then on?

Doesn't make sense to me but an approach you can take to debug problems like this is to simplify the code so you can isolate the problem.

Try removing the Timer configuration code in setup, if that fixes it you can focus on that code.

i have already take everything off, only the Serial code.
it does work the whole time after an upload but after an reboot (power on/off, SerialMonitor on/off or Reboot button on the board) it doesnt work anymore.

i think only the serial.print don't work but i'm not sure the Serial.read probably also, i can't test it .

Try it with just the serial code and a line or two of code that flashes the LED on pin 13 every time through the loop. That will tell you if the code is still running. If its not flashing, post the sketch.