Adding a flush and delay makes this program work as expected now. A byte is written on the TX pin every 100 ms.
Code: Select all
#include <HardwareSerial.h>
uint8_t a= 10;
HardwareSerial MySerial(1);
void setup() {
pinMode(10, OUTPUT);
}
void loop() {
MySerial.begin(250000, SERIAL_8N1, 9, 10);
MySerial.write(a);
MySerial.flush();
delay(1);
MySerial.end();
delay(100);
}
The problem now is that I want to have TX pin be a digital output after MySerial.end(). If I try to do that then the output stays HIGH until the loop() starts again and the serial commands are run. There is no difference in the output of the TX pin in the bottom code vs the top code.
Code: Select all
#include <HardwareSerial.h>
uint8_t a= 10;
HardwareSerial MySerial(1);
void setup() {
pinMode(10, OUTPUT);
}
void loop() {
MySerial.begin(250000, SERIAL_8N1, 9, 10);
MySerial.write(a);
MySerial.flush();
delay(1);
MySerial.end();
//MAKE PIN 10 GENERAL IO AND DO SOMETHING WITH digitalWrite(10,LOW) or digitalWrite(10,HIGH) HERE
pinMode(10, OUTPUT);
digitalWrite(10, LOW);
delay(1);
digitalWrite(10, HIGH);
delay(1);
digitalWrite(10, LOW);
delay(1);
digitalWrite(10, HIGH);
delay(1);
delay(100);
}
end() calls uartDetachRx(uart) and uartDetachTx(uart). Is it possible the detach is not working?