Pages: [1]   Go Down
Author Topic: ArduinoISP / readbytes() / design question  (Read 812 times)
0 Members and 1 Guest are viewing this topic.
Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

-Arne

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

-Arne

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hm

i followed the control flow a little bit:

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

in avrisp():
Code:
...
  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
Logged

-Arne

Pages: [1]   Go Up
Jump to: