Olá, boa noite
Tenho uma livraria de DMX512(RS485) que funciona via RX e TX do Due(meu caso)
Quero fazer um projeto em que o arduino se comunica com o PC e com o dispositivo DMX ao mesmo tempo.
Isso não é possivel no Due por ser dois tipos de sinal diferente DMX(RS485),PC(RS232) e o micro só ter um par de portas RX e TX
Por isso comprei o mega que tem todas as 4 seriais para comunicação, porem a livraria DMX é configurada para o RX1 e TX1 os que ja sao usados pelo
C.I do USB .
Gostaria de saber como poderia alterar o codigo da livraria para ela usar o Serial2 do mega , assim teria o Serial1 no PC e o Serial2 no DMX
Parte do código da livraria:
#include "Arduino.h"
#include "DMXSerial.h"
#include <avr/interrupt.h>
// ----- Debugging -----
// to debug on an oscilloscope, enable this
#undef SCOPEDEBUG
#ifdef SCOPEDEBUG
#define DmxTriggerPin 4 // low spike at beginning of start byte
#define DmxISRPin 3 // low during interrupt service routines
#endif
// ----- Constants -----
// Define port & bit values for Hardware Serial Port.
// These definitions are done for not hardcoding port 0 in this library.
// If you want to use this library with another hardware port on a more advanced chip,
// you can change the 0 (zero) to 1, 2, 3... in these constant definitions.
#define UCSRnA UCSR0A // Control and Status Register A
#define UCSRnB UCSR0B // USART Control and Status Register B
#define RXCIEn RXCIE0 // Enable Receive Complete Interrupt
#define TXCIEn TXCIE0 // Enable Transmission Complete Interrupt
#define UDRIEn UDRIE0 // Enable Data Register Empty Interrupt
#define RXENn RXEN0 // Enable Receiving
#define TXENn TXEN0 // Enable Sending
#define UCSRnC UCSR0C // Control and Status Register C
#define USBSn USBS0 // Stop bit select 0=1bit, 1=2bits
#define UCSZn0 UCSZ00 // Character size 00=5, 01=6, 10=7, 11=8 bits
#define UPMn0 UPM00 // Parity setting 00=N, 10=E, 11=O
#define UBRRnH UBRR0H // USART Baud Rate Register High
#define UBRRnL UBRR0L // USART Baud Rate Register Low
#define UDRn UDR0 // USART Data Register
#define UDREn UDRE0 // USART Data Ready
#define FEn FE0 // Frame Error
// formats for serial transmission
#define SERIAL_8N1 ((0<<USBSn) | (0<<UPMn0) | (3<<UCSZn0))
#define SERIAL_8N2 ((1<<USBSn) | (0<<UPMn0) | (3<<UCSZn0))
#define SERIAL_8E1 ((0<<USBSn) | (2<<UPMn0) | (3<<UCSZn0))
#define SERIAL_8E2 ((1<<USBSn) | (2<<UPMn0) | (3<<UCSZn0))
// the break timing is 10 bits (start + 8 data + parity) of this speed
// the mark-after-break is 1 bit of this speed plus approx 6 usec
// 100000 bit/sec is good: gives 100 usec break and 16 usec MAB
// 1990 spec says transmitter must send >= 92 usec break and >= 12 usec MAB
// receiver must accept 88 us break and 8 us MAB
#define BREAKSPEED 100000
#define DMXSPEED 250000
#define BREAKFORMAT SERIAL_8E1
#define DMXFORMAT SERIAL_8N2
// ----- Enumerations -----
// State of receiving DMX Bytes
typedef enum {
IDLE, BREAK, DATA
} DMXReceivingState;
"Acho" que a parte de definição esta no começo onde ele é definido :
#define RXENn RXEN0 // Enable Receiving
#define TXENn TXEN0 // Enable Sending
Daria para alterar no caso para :
#define RX2ENn RX2EN0 // Enable Receiving
#define TX2ENn TX2EN0 // Enable Sending
Desde já agradeço.
Obg. A todos exelente forum!