ArduinoISP / readbytes() / design question

Hi!

I plan to program an own brand new atmega168 chip...

Since i dont have an ISP, but a spare Duemilanova, i had a look at the ArduinoISP example...

Shouldnt it use getch() in readbytes() also?

uint8_t getch() {
  while(!Serial.available());
  return Serial.read();
}
void readbytes(int n) {
  for (int x = 0; x < n; x++) {
    buff[x] = Serial.read();
  }
}

I wonder what happens, when the UART buffer doesnt fill fast enough...

Thx.

Bye
Arne

I wonder what happens, when the UART buffer doesnt fill fast enough...

If readbytes() is called with the value returned by Serial.available(), there won't be a problem. Hard to say for certain with just these code snippets.

Shouldnt it use getch() in readbytes() also?

If readbytes() is called after Serial.available(), then no. Functions, like getch(), are great, but there is overhead involved with every function call. Too many functions slows things down, and consumes a lot pf memory. The key is to achieve a balance between modularity and speed.

oki - i will try both, when i got my fresh atmega chip... :slight_smile:

but: Serial.available() should be >= n... just not-zero is not enough...
but when n is bigger than the buffer, it will never be true...
so getch() is better...

timing shouldnt be a problem (the buffer is filled, before the EEPROM is written, i guess)...

if getch() isnt inlined (there is a loop in it), there should be no difference in a getch() call...

-arne

Serial.available() should be >= n... just not-zero is not enough.

Paul said:

If readbytes() is called with the value returned by Serial.available() ...

The buffer in HS is 128 bytes which is a lot...

hm

i followed the control flow a little bit:

in loop():

...
if (Serial.available()) avrisp();
...

in avrisp():

...
  uint8_t ch = getch();
  switch (ch) {
...
  case 'B':
    readbytes(20);
...

But maybe the FTDI driver always sends up to 32 byte packs and avoids sending 1B after another...

But OTOH on multitasking boxes (like my linux box) u never know... :slight_smile:

-arne