Go Down

Topic: ArduinoISP / readbytes() / design question (Read 895 times) previous topic - next topic

RIDDICK

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?
Code: [Select]
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
-Arne

PaulS

Quote
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.

Quote
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.


RIDDICK

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

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
-Arne

deSilva

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

Paul said:
Quote
If readbytes() is called with the value returned by Serial.available() ...

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

RIDDICK

hm

i followed the control flow a little bit:

in loop():
Code: [Select]
...
if (Serial.available()) avrisp();
...


in avrisp():
Code: [Select]
...
 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... :-)

-arne
-Arne

Go Up