Go Down

Topic: wiring_serial.c - some suggestions for the Serial (Read 5 times) previous topic - next topic


Ok, here's the final optimized wiring_serial.c with output buffer that can be completely disabled by setting #define TX_BUFFER_SIZE 0

I had earlier pondered how this sort of #define trick could set the RX_BUFFER_SIZE also, since it's fairly large for most of the sketches that we see on the boards, but necessary for real workhorse applications that require constant serial attention.

The downside to this situation is that it actually depends on the LIBRARY to be rebuilt when the SKETCH uses it.  It's no longer a shared library implementation, and a makefile might not establish that relationship.  I would think you'd have to keep deleting the library .o files whenever you want to readjust the buffer size.

Am I wrong on this?


@mtz: just call
Code: [Select]
Serial.begin(1000000L); This version uses exactly the same functions as the original one. It's transparent for the programmer.

@halley: I'm not sure how the makefile is written, but in my case, whenever I change the wiring_serial.c file it is automatically recompiled. It'd be awesome if one could put the
Code: [Select]
#define RX_BUFFER_SIZE yourvalue
at the beginning of the sketch file so there's no need to edit the library. With a smart code in the library:
Code: [Select]

#define RX_BUFFER_SIZE 128


After this great size and speed improvement to the serial library, why not upgrade the Serial.begin() function as well?

How about

Code: [Select]

The buffer sizes could be optional and default to sensible values.
• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!


Thanks mekon83...

But I have another question: in the code you put, there is a "L" after the speed, is that right?


Yep, it tells the compiler that 1000000L is a long constant, not an int. Maybe 1000000UL, unsigned long, that's even better.

Go Up