clean up defines

master
Eggert Jung 5 years ago
parent 2a8e794741
commit 4d77cd47fd

@ -74,18 +74,12 @@ void modbusSetAddress(unsigned char newadr)
#if PHYSICAL_TYPE == 485
void transceiver_txen(void)
{
#if BOARD_TYPE == bType5chLedDim
PORTD|=(1<<7);
#endif
TRANSCEIVER_ENABLE_PORT|=(1<<TRANSCEIVER_ENABLE_PIN);
}
void transceiver_rxen(void)
void transceiver_rxen(void)
{
TRANSCEIVER_ENABLE_PORT&=~(1<<TRANSCEIVER_ENABLE_PIN);
#if BOARD_TYPE == bType5chLedDim
PORTD&=~(1<<7);
#endif
}
#endif
@ -209,8 +203,8 @@ ISR(UART_TRANSMIT_INTERRUPT)
#ifndef __AVR_ATxmega32A4__
UART_CONTROL&=~(1<<UART_UDRIE);
#else
USARTD0_CTRLA &= ~(USART_DREINTLVL_gm);
#endif
UART.CTRLA &= ~(USART_DREINTLVL_gm);
#endif//__AVR_ATxmega32A4__
}
}
@ -236,34 +230,32 @@ void modbusInit(void)
UCSRC = (3<<UCSZ0); //Frame Size
#endif
UART_CONTROL = (1<<TXCIE)|(1<<RXCIE)|(1<<RXEN)|(1<<TXEN); // USART receiver and transmitter and receive complete interrupt
#if PHYSICAL_TYPE == 485
TRANSCEIVER_ENABLE_PORT_DDR|=(1<<TRANSCEIVER_ENABLE_PIN);
transceiver_rxen();
#endif
BusState=(1<<TimerActive);
#else
//8bit
USARTD0.CTRLC = USART_CHSIZE0_bm | USART_CHSIZE1_bm;
#else//URSEL
UART.CTRLC = USART_CHSIZE_8BIT_gc;
//38400
USARTD0.BAUDCTRLA = bsel;
USARTD0.BAUDCTRLB = 0 | (bsel >> 8) | (bscale << USART_BSCALE0_bp);
// set baudrate
UART.BAUDCTRLA = UART_BSEL;
UART.BAUDCTRLB = 0 | (UART_BSEL >> 8) | (UART_BSCALE << USART_BSCALE0_bp);
USARTD0.CTRLB = USART_TXEN_bm | USART_RXEN_bm;
UART.CTRLB = USART_TXEN_bm | USART_RXEN_bm;
//Interrupt enable (levels)
USARTD0.CTRLA |= USART_RXCINTLVL_HI_gc;
USARTD0.CTRLA |= USART_TXCINTLVL_HI_gc;
UART.CTRLA |= USART_RXCINTLVL_HI_gc;
UART.CTRLA |= USART_TXCINTLVL_HI_gc;
PORTD_OUTSET = PIN3_bm;
//PORTD_OUTSET = PIN3_bm;
PORTD_DIRSET = PIN3_bm;
PORTD_OUTCLR = PIN2_bm;
PORTD_DIRCLR = PIN2_bm;
//PORTD_OUTCLR = PIN2_bm;
//PORTD_DIRCLR = PIN2_bm;
//TODO Physical type 485
#endif//__AVR_ATxmega32A4__
#if PHYSICAL_TYPE == 485
TRANSCEIVER_ENABLE_PORT_DDR|=(1<<TRANSCEIVER_ENABLE_PIN);
transceiver_rxen();
#endif
BusState=(1<<TimerActive);
#endif
}
/* @brief: Sends a response.
@ -284,8 +276,7 @@ void modbusSendMessage(unsigned char packtop)
#ifndef __AVR_ATxmega32A4__
UART_CONTROL|=(1<<UART_UDRIE);
#else
//TODO use define for usartd
USARTD0_CTRLA |= USART_DREINTLVL_HI_gc;
UART.CTRLA |= USART_DREINTLVL_HI_gc;
#endif
BusState&=~(1<<ReceiveCompleted);

@ -57,15 +57,11 @@ THE POSSIBILITY OF SUCH DAMAGE.
/*
* Definitions for transceiver enable pin.
*/
#if BOARD_TYPE == bType5chLedDim
#define TRANSCEIVER_ENABLE_PORT PORTD
#define TRANSCEIVER_ENABLE_PIN 5
#define TRANSCEIVER_ENABLE_PORT_DDR DDRD
#else
#define TRANSCEIVER_ENABLE_PORT PORTD
#define TRANSCEIVER_ENABLE_PIN 2
#define TRANSCEIVER_ENABLE_PORT_DDR DDRD
#endif
#define TRANSCEIVER_ENABLE_PORT PORTD_OUT
#define TRANSCEIVER_ENABLE_PIN 4
#define TRANSCEIVER_ENABLE_PORT_DDR PORTD_DIR
/**
* @brief
* At the moment the user has to set the value for Baudrate and
@ -188,11 +184,16 @@ THE POSSIBILITY OF SUCH DAMAGE.
#define UART_UDRIE UDRIE
#elif defined(__AVR_ATxmega32A4__)
#define UART USARTD0
#define UART_TRANSMIT_COMPLETE_INTERRUPT USARTD0_TXC_vect
#define UART_RECEIVE_INTERRUPT USARTD0_RXC_vect
#define UART_TRANSMIT_INTERRUPT USARTD0_DRE_vect
#define UART_DATA USARTD0.DATA
//9600 Baud at 32MHz system clock
#define UART_BSEL 208
#define UART_BSCALE 0
#else
#error "no definition available"
@ -219,7 +220,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
* Use 485 or 232, default: 485
* Use 232 for testing purposes or very simple applications that do not require RS485 and bus topology.
*/
#define PHYSICAL_TYPE 232//485 //possible values: 485, 232
#define PHYSICAL_TYPE 485 //possible values: 485, 232
/*
#define modbusBaudrate 38400

Loading…
Cancel
Save