I am new in this forum and I hope you can help me, solving my problem with the Arduino Leonardo and the Serial1.end() and Serial1.begin() command. The code is following, until now it's just quick and dirty programmed, to see if my ideas are working:
#include <HardwareSerial.h> #define BAUDRATE 9600
int Break = 1;
void setup() { //Serial1.begin(BAUDRATE, SERIAL_8N1);
pinMode(Break, OUTPUT); // sets the digital pin as output
}
int start(void){
Serial1.end();
digitalWrite(Break, LOW);
delayMicroseconds(13*1e6/BAUDRATE);
return 0;
}
The problem is, that the first break (LOW for a specific time) is ok, followed by sending bytes on TX line 1. The second part, again starting with a break doesn't work and right now I don't know why. The behaviour right now is, that neither the programmed delay of 1msec nor the following LOW phase will be executed, it runs directly with sending the 0x55 .... ignoring the code in between totally.
I already searched the internet for a reason, but didn't get any solution until now. I think normally it should be possible to close the serial line and use it as a digital OUTPUT and then start the serial line again.
Do you have any solutions for solving this issue or do you know any other possiblities to handle it?
I need a specific time LOW before sending the SYNC, that means the serial line has to be LOW 13 bit, if I would send DATA with 0x00, I would have a HIGH after the 8th bit, because there is the stop bit, LOW -> HIGH transition. Or do you have a solution for sending 13 bit low? This is the reason, or my solution why I change from serial to DIGITAL OUTPUT.
Regarding your second question, I can also delete the "return 0", as I said, it's just quick&dirty programmed.
Norbie:
I need a specific time LOW before sending the SYNC,
PaulS:
That does not require stopping and starting the serial interface.
Serial idles HIGH so just doing nothing does not meet the stated requirement. It would seem to be necessary to terminate Serial and write the pin LOW.
However ....
In view of the fact that Serial idles HIGH the stated requirement is very strange.
WHY is the LOW period required?
I have heard of Serial comms with inverted signal levels - maybe that is the problem. If that is the problem the solution that immediately occurs to me is to put an inverting buffer between the Arduino and the other device. I suspect using END and BEGIN as a workaround will eventually let you down.
Holding the serial line LOW for a certain length of time is a break! The Arduino
HardwareSerial driver doesn't support using a break, you'll have to program the hardware
directly, probably just:
Serial1.end () ;
pinMode (1, OUTPUT) ; // I think this is the write TX pin for Serial1 on Leonardo, but check
digitalWrite (1, LOW) ;
delay(2) ;
Serial1.begin (...) ;
MarkT:
Holding the serial line LOW for a certain length of time is a break! The Arduino
HardwareSerial driver doesn't support using a break, you'll have to program the hardware
directly, probably just:
Serial1.end () ;
pinMode (1, OUTPUT) ; // I think this is the write TX pin for Serial1 on Leonardo, but check
digitalWrite (1, LOW) ;
delay(2) ;
Serial1.begin (...) ;
Otherwise the UART is overriding the pin and preventing digitalWrite and pinMode
from having any effect - it also disables interrupts. However it shuts down both RX and
TX together, which isn't ideal.
I know this because I looked at the code - its open source you know