Hello,
I have a store and forward application where I want to use point to multi-point radios, connected to the Rx and Tx lines of my ATmega. If data is received, I want to shut down Rx, so the port won't listen to it's own transmission, and rebroadcast the received data. I have read as much as I can on the subject, so this post is to confirm or correct my understanding. I think the way to shut down only Rx is to clear RXEN0 in UCSR0B.
Be careful what lurks in the shadows!
I use my own USART drivers to get out from under the heavy overhead of the Serial class. If you invoke Serial and the corresponding libraries are attached to your code, you also give up control of the USART. While in principle what you detailed above works (an option is to disable/enable the interrupt), I'm not certain that Serial or HardwardSerial doesn't keep a check in the background to ensure both pins are enabled. If you are using the USART strictly for communications, you'd be far better off taking control of it yourself.
The code is in the datasheet. Tx on page 232, Rx on page 234. The only thing I've done is attach a FIFO buffer to each and place it inside their respective interrupts - USART_UDRE and USART_RX. That way they both operate independent of the rest of my code. Receive tests characters for \n while adding to the buffer. When \n in detected, a flag is set. Transmit takes characters off the buffer each time the transmit empty interrupt fires after checking to see the the FIFO is not empty. Transmit needs to be enabled/disabled otherwise the buffer empty interrupt will continuously fire.
DKWatson:
The code is in the datasheet. Tx on page 232, Rx on page 234. The only thing I've done is attach a FIFO buffer to each and place it inside their respective interrupts - USART_UDRE and USART_RX. That way they both operate independent of the rest of my code. Receive tests characters for \n while adding to the buffer. When \n in detected, a flag is set. Transmit takes characters off the buffer each time the transmit empty interrupt fires after checking to see the the FIFO is not empty. Transmit needs to be enabled/disabled otherwise the buffer empty interrupt will continuously fire.
Thank you. I've been meaning to eliminate Serial for a while, mainly for it's use of Strings.
The HardwareSerial class doesn't use any reference to the String class but it's super class (Stream) does implement several methods that handle Strings.
You don't have to use these methods and the linker will not include the String class into your code.