-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsend_break.cpp
44 lines (38 loc) · 1.22 KB
/
send_break.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Send a break to restart the ouptut for DMX512
*/
#include "send_break.h"
#include "c_types.h"
#include "eagle_soc.h"
#include "uart_register.h"
#include "Arduino.h"
// More detailled information on the DMX protocol can be found on
// http://www.erwinrol.com/dmx512/
// https://erg.abdn.ac.uk/users/gorry/eg3576/DMX-frame.html
// there are two different implementations, both should work
#define USE_SERIAL_BREAK
/* UART for DMX output */
#define SEROUT_UART 1
/* DMX minimum timings per E1.11 */
#define DMX_BREAK 92
#define DMX_MAB 12
void sendBreak() {
#ifdef USE_SERIAL_BREAK
// switch to another baud rate, see https://forum.arduino.cc/index.php?topic=382040.0
Serial1.flush();
Serial1.begin(90000, SERIAL_8N2);
while(Serial1.available()) Serial1.read();
// send the break as a "slow" byte
Serial1.write(0);
// switch back to the original baud rate
Serial1.flush();
Serial1.begin(250000, SERIAL_8N2);
while(Serial1.available()) Serial1.read();
#else
// send break using low-level code
SET_PERI_REG_MASK(UART_CONF0(SEROUT_UART), UART_TXD_BRK);
delayMicroseconds(DMX_BREAK);
CLEAR_PERI_REG_MASK(UART_CONF0(SEROUT_UART), UART_TXD_BRK);
delayMicroseconds(DMX_MAB);
#endif
}