Git Product home page Git Product logo

Comments (11)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 15, 2024
"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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 15, 2024

Original comment by [email protected] on 24 Oct 2009 at 3:31

  • Added labels: Component-Core, Milestone-0018

from arduino.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 15, 2024

Original comment by [email protected] on 23 Dec 2009 at 12:01

  • Changed state: Fixed

from arduino.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 15, 2024
@ 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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 15, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.