From c4bb389c8b96e7f96097e192e0057f14b2c92962 Mon Sep 17 00:00:00 2001 From: anders Date: Sun, 30 Dec 2018 13:15:34 +0100 Subject: [PATCH 1/6] setStartAddress --- src/DMXSerial.cpp | 8 ++++++++ src/DMXSerial.h | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/DMXSerial.cpp b/src/DMXSerial.cpp index ee9a8e9..23f5454 100644 --- a/src/DMXSerial.cpp +++ b/src/DMXSerial.cpp @@ -173,9 +173,11 @@ typedef enum { DMXMode _dmxMode; // Mode of Operation int _dmxModePin; // pin used for I/O direction. +int _dmxStartAddress = 1; //first Channel the reciver will listen to. Default is 1. uint8_t _dmxRecvState; // Current State of receiving DMX Bytes int _dmxChannel; // the next channel byte to be sent. +uint16_t _dmxRecvPos; //Next received Channel in one data Frame volatile unsigned int _dmxMaxChannel = 32; // the last channel used for sending (1..32). volatile unsigned long _dmxLastPacket = 0; // the last time (using the millis function) a packet was received. @@ -373,6 +375,12 @@ void DMXSerialClass::term(void) UCSRnB = 0; } // term() +//sets the first Channel the reciver will listen to +void DMXSerialClass::setStartAddress(int channel){ + if (channel < 1) channel = 1; + if channel > 512) channel = 512; + _dmxStartAddress = channel; +} // ----- internal functions and interrupt implementations ----- diff --git a/src/DMXSerial.h b/src/DMXSerial.h index 6ddebe1..3d0afd6 100644 --- a/src/DMXSerial.h +++ b/src/DMXSerial.h @@ -28,6 +28,7 @@ // _DMXStartSending and _DMXStartReceiving functions. // 27.08.2017 DMXProbe mode finished. // 29.10.2017 documentation. +// 30.12.2018 included DMX start address on reciving data. // - - - - - #ifndef DmxSerial_h @@ -164,7 +165,12 @@ class DMXSerialClass * @brief Terminate the current operation mode. */ void term(); - + + /** + * @brief sets the first channel the reciver is listening and storing to. + */ + void setStartAddress(int channel); + private: // Not used. // all private information is in the global _dmxXXX variables for speed and code size optimization. From ad0274df7e57ab735953c17836ec9a338304ebcc Mon Sep 17 00:00:00 2001 From: anders Date: Sun, 30 Dec 2018 13:23:40 +0100 Subject: [PATCH 2/6] StartAddress --- src/DMXSerial.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/DMXSerial.cpp b/src/DMXSerial.cpp index 23f5454..cd9adfa 100644 --- a/src/DMXSerial.cpp +++ b/src/DMXSerial.cpp @@ -458,7 +458,8 @@ ISR(USARTn_RX_vect) // break condition detected. _dmxRecvState = BREAK; _dmxDataPtr = _dmxData; - + _dmxRecvPos = 0; + } else if (DmxState == BREAK) { // first byte after a break was read. if (DmxByte == 0) { @@ -466,6 +467,7 @@ ISR(USARTn_RX_vect) _dmxRecvState = DATA; _dmxLastPacket = millis(); // remember current (relative) time in msecs. _dmxDataPtr++; // start saving data with channel # 1 + _dmxRecvPos ++; } else { // This might be a RDM or customer DMX command -> not implemented so wait for next BREAK ! @@ -473,14 +475,17 @@ ISR(USARTn_RX_vect) } // if } else if (DmxState == DATA) { - // check for new data - if (*_dmxDataPtr != DmxByte) { - _dmxUpdated = true; - // store received data into dmx data buffer. - *_dmxDataPtr = DmxByte; - } // if - _dmxDataPtr++; - + if (_dmxRecvPos >= _dmxStartAddress){ + // check for new data + if (*_dmxDataPtr != DmxByte) { + _dmxUpdated = true; + // store received data into dmx data buffer. + *_dmxDataPtr = DmxByte; + } // if + _dmxDataPtr++; + } + _dmxRecvPos++; + if (_dmxDataPtr > _dmxDataLastPtr) { // all channels received. _dmxRecvState = DONE; From 99e1811503f3cf44a0e613ca71eda3c87d0988c9 Mon Sep 17 00:00:00 2001 From: Anders <43926857+AnderBHC@users.noreply.github.com> Date: Sun, 30 Dec 2018 14:03:53 +0100 Subject: [PATCH 3/6] Update DMXSerial.cpp --- src/DMXSerial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DMXSerial.cpp b/src/DMXSerial.cpp index cd9adfa..95325ec 100644 --- a/src/DMXSerial.cpp +++ b/src/DMXSerial.cpp @@ -378,7 +378,7 @@ void DMXSerialClass::term(void) //sets the first Channel the reciver will listen to void DMXSerialClass::setStartAddress(int channel){ if (channel < 1) channel = 1; - if channel > 512) channel = 512; + if (channel > 512) channel = 512; _dmxStartAddress = channel; } From d2317230d73b73441d1ff0a44ca9935d126667c8 Mon Sep 17 00:00:00 2001 From: anders Date: Sun, 30 Dec 2018 17:44:48 +0100 Subject: [PATCH 4/6] buffer emptied on RX interrupt --- src/DMXSerial.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/DMXSerial.cpp b/src/DMXSerial.cpp index cd9adfa..4632993 100644 --- a/src/DMXSerial.cpp +++ b/src/DMXSerial.cpp @@ -443,7 +443,9 @@ inline void _DMXSerialWriteByte(uint8_t data) // In DMXController mode this interrupt is disabled and will not occur. // In DMXReceiver mode when a byte was received it is stored to the dmxData buffer. ISR(USARTn_RX_vect) -{ + { + while(UCSRnA & (1 << RXCn)){ //while ther is data in the USART buffer + uint8_t USARTstate = UCSRnA; // get state before data! uint8_t DmxByte = UDRn; // get data uint8_t DmxState = _dmxRecvState; //just load once from SRAM to increase speed @@ -499,14 +501,14 @@ ISR(USARTn_RX_vect) // continue listening without interrupts _DMXSerialInit(Calcprescale(DMXSPEED), (1 << RXENn), DMXFORMAT); //UCSRnB = (1 << RXENn); - - + + } else { // continue on DMXReceiver mode. _dmxRecvState = IDLE; // wait for next break } } // if - +} // while } // ISR(USARTn_RX_vect) From 911a605d3a668c99718fe47f57b244b5c080903c Mon Sep 17 00:00:00 2001 From: anders Date: Sun, 30 Dec 2018 17:50:47 +0100 Subject: [PATCH 5/6] changelog --- src/DMXSerial.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DMXSerial.h b/src/DMXSerial.h index 3d0afd6..58707c2 100644 --- a/src/DMXSerial.h +++ b/src/DMXSerial.h @@ -29,6 +29,8 @@ // 27.08.2017 DMXProbe mode finished. // 29.10.2017 documentation. // 30.12.2018 included DMX start address on reciving data. +// 30.12.2018 the buffer is now completly read when the RX interrupt occurs. +// This allows the usage of multiple ws8212 LEDs. // - - - - - #ifndef DmxSerial_h From 258e4167d8804f7d3ab0dd8240823889ea248572 Mon Sep 17 00:00:00 2001 From: Anders <43926857+AnderBHC@users.noreply.github.com> Date: Sun, 10 Mar 2019 20:33:26 +0100 Subject: [PATCH 6/6] Update README.adoc --- README.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.adoc b/README.adoc index f66b14b..2754ae3 100644 --- a/README.adoc +++ b/README.adoc @@ -1,5 +1,7 @@ = DMX Library for Arduino = +Improved to enable the usage of Neopixels and reduce Memory usage. + This is a library for sending and receiving DMX codes using the Arduino plattform or a ATmega (ATmega168, ATmega328 or similar) processor with a clock speed of 16 MHz.