Comments (11)
Here's an implementation that works with 0016 and 0017:
//--------------HardwareSerial.h
void end(void);
//--------------HardwareSerial.cpp
void HardwareSerial::end(void)
{
//disable interrupts
uint8_t oldSREG = SREG;
cli();
// disable rx and tx
cbi(*_ucsrb, _rxen);
cbi(*_ucsrb, _txen);
// disable interrupt on complete reception of a byte
cbi(*_ucsrb, _rxcie);
//flush serial read buffer so no data is available if beginSerial is recalled
flush();
//reset sreg to original state (re-enable interrupts)
SREG = oldSREG;
}
//--------- Usage
Serial.end()
Original comment by [email protected]
on 18 Aug 2009 at 10:43
from arduino.
I see stuff like this in the Arduino libraries a lot:
cbi(*_ucsrb, _rxen);
cbi(*_ucsrb, _txen);
cbi(*_ucsrb, _rxcie);
Which is a waste of resources and uses the deprecated sbi and cbi calls... The
more
modern and efficient way is:
*_ucsrb |= _BV(_rxen) | _BV(_txen) | _BV(_rxcie);
_ucsrb is volatile, and volatile assignments are guaranteed to not be
optimized, so
there is no way for a compiler to ever fix this.
Anyhoo, cbi and sbi are deprecated and shouldn't be used anymore.
http://www.nongnu.org/avr-libc/user-manual/group__avr__sfr.html
Original comment by [email protected]
on 18 Aug 2009 at 11:08
from arduino.
oops, I realized as I was hitting submit that I was setting instead of
clearing...
*_ucsrb &= ~( _BV(_rxen) | _BV(_txen) | _BV(_rxcie) );
Original comment by [email protected]
on 18 Aug 2009 at 11:15
from arduino.
Thanks Gabe, Yes that is clearly better. I was modeling my code after the
code that
already exists in the library.
Original comment by [email protected]
on 18 Aug 2009 at 11:28
from arduino.
I need end functions in all libraries that take over pins. I need to
dynamically reassigns pins and start various
libraries on them according to messages from USB. Not everyone buys into the
setup, while(1) loop idea that
makes people lazy about providing and end().
Original comment by [email protected]
on 26 Aug 2009 at 4:23
from arduino.
I believe "while(1) loop();" is a vestigial safety mechanism. It would be
dangerous for a program to continue
executing the byte code directly after a program, so you need an infinite loop.
The ".fini0" section now takes
care that problem. http://www.nongnu.org/avr-libc/user-manual/mem_sections.html
Even if serial setup() isn't run, the USART pins will likely be in USART mode
because of the Arduino bootloader.
Swapping functionality of pins on the fly isn't likely going to be put very
high on the priority list because it would
require sweeping changes.
Original comment by [email protected]
on 26 Aug 2009 at 4:45
from arduino.
"Swapping functionality of pins on the fly isn't likely going to be put very
high on the priority list because it
would require sweeping changes."
Sweeping changes? Yes, a pin registry would be nice but I am asking for
something simpler: a function in
each library that ends that use of the pin, interrupts and specialized hardware
module. A quick review of most
of the libraries shows that nobody does it. I should probably file a separate
case for this.
It is not that much work for each developer - I know because we already do this
in the uOSC library for pic
which can dynamically assign functions to pins and configure them with OSC
messages.
Original comment by [email protected]
on 26 Aug 2009 at 4:04
from arduino.
Original comment by [email protected]
on 24 Oct 2009 at 3:31
- Added labels: Component-Core, Milestone-0018
from arduino.
Original comment by [email protected]
on 23 Dec 2009 at 12:01
- Changed state: Fixed
from arduino.
@ dmellis, Thank you very much, your time and effort are most appreciated.
Original comment by [email protected]
on 23 Dec 2009 at 9:36
from arduino.
not sure this is the correct place to post this, so please delete if not.
0018 test, windows xp, Diecimila
# Serial.end() - _ends serial communication and frees digital pins 0 and 1 for
normal input and output._
* test a: after a call to Serial.end(), can pins 0 and 1 be used for normal input
and output?
YES
* test b: after a call to Serial.end(), will Serial.begin() re-enable serial
communication?
YES
i recomplied all my previous programs that used endSerial(), all which have
worked
with Serial.end() without any problems.
Original comment by [email protected]
on 25 Jan 2010 at 10:23
from arduino.
Related Issues (20)
- Arduino test suites not working on arduino-1.0-beta2 HOT 2
- Arduino IDE 1.0 beta Release Candidate does not support Mega ADK HOT 2
- Split avrdude and avrdude.conf out from massive tools .zip file.
- Stream parseInt() and parseFloat() functions swallow the initial trailing (non-numeric) character. HOT 3
- HardwareSerial is always linked, even if it's not used. HOT 1
- serialEvent easier-to-understand model HOT 3
- Add print(int8_t) and println(int8_t) to format ASCII digits as with uint8_t. HOT 3
- RX and TX defines for specifying which pins are used for Serial / communication with computer. HOT 2
- PIN13 in conflict: SPI SCLK vs. LED HOT 1
- Stream parseInt() and parseFloat() functions should have an option to not search ahead. HOT 1
- Merge PWMServo library (hardware servo control on pins 9 and 10) into Servo library.
- Use hardware PWM if generating a single tone() on the right pin for the timer.
- Please sync Firmata (r82), hopefully for 1.0-beta4 HOT 3
- Rename .pde files to .ino on save, not open. HOT 4
- Incorporate latest changes to the Ethernet library. HOT 1
- Sketch .c, .cpp, and .h files not searched for library includes. HOT 4
- HardwareSerial overflow of input detection
- Compile faster - only recompile files that have changed HOT 18
- Read-only sketch files are renamed from .pde to .ino when saving a copy of the sketch. HOT 2
- SoftwareSerial keywords.txt still says NewSoftSerial
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino.