clean up defines
This commit is contained in:
@@ -74,18 +74,12 @@ void modbusSetAddress(unsigned char newadr)
|
|||||||
#if PHYSICAL_TYPE == 485
|
#if PHYSICAL_TYPE == 485
|
||||||
void transceiver_txen(void)
|
void transceiver_txen(void)
|
||||||
{
|
{
|
||||||
#if BOARD_TYPE == bType5chLedDim
|
|
||||||
PORTD|=(1<<7);
|
|
||||||
#endif
|
|
||||||
TRANSCEIVER_ENABLE_PORT|=(1<<TRANSCEIVER_ENABLE_PIN);
|
TRANSCEIVER_ENABLE_PORT|=(1<<TRANSCEIVER_ENABLE_PIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void transceiver_rxen(void)
|
void transceiver_rxen(void)
|
||||||
{
|
{
|
||||||
TRANSCEIVER_ENABLE_PORT&=~(1<<TRANSCEIVER_ENABLE_PIN);
|
TRANSCEIVER_ENABLE_PORT&=~(1<<TRANSCEIVER_ENABLE_PIN);
|
||||||
#if BOARD_TYPE == bType5chLedDim
|
|
||||||
PORTD&=~(1<<7);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -209,8 +203,8 @@ ISR(UART_TRANSMIT_INTERRUPT)
|
|||||||
#ifndef __AVR_ATxmega32A4__
|
#ifndef __AVR_ATxmega32A4__
|
||||||
UART_CONTROL&=~(1<<UART_UDRIE);
|
UART_CONTROL&=~(1<<UART_UDRIE);
|
||||||
#else
|
#else
|
||||||
USARTD0_CTRLA &= ~(USART_DREINTLVL_gm);
|
UART.CTRLA &= ~(USART_DREINTLVL_gm);
|
||||||
#endif
|
#endif//__AVR_ATxmega32A4__
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,34 +230,32 @@ void modbusInit(void)
|
|||||||
UCSRC = (3<<UCSZ0); //Frame Size
|
UCSRC = (3<<UCSZ0); //Frame Size
|
||||||
#endif
|
#endif
|
||||||
UART_CONTROL = (1<<TXCIE)|(1<<RXCIE)|(1<<RXEN)|(1<<TXEN); // USART receiver and transmitter and receive complete interrupt
|
UART_CONTROL = (1<<TXCIE)|(1<<RXCIE)|(1<<RXEN)|(1<<TXEN); // USART receiver and transmitter and receive complete interrupt
|
||||||
|
#else//URSEL
|
||||||
|
UART.CTRLC = USART_CHSIZE_8BIT_gc;
|
||||||
|
|
||||||
|
// set baudrate
|
||||||
|
UART.BAUDCTRLA = UART_BSEL;
|
||||||
|
UART.BAUDCTRLB = 0 | (UART_BSEL >> 8) | (UART_BSCALE << USART_BSCALE0_bp);
|
||||||
|
|
||||||
|
UART.CTRLB = USART_TXEN_bm | USART_RXEN_bm;
|
||||||
|
|
||||||
|
//Interrupt enable (levels)
|
||||||
|
UART.CTRLA |= USART_RXCINTLVL_HI_gc;
|
||||||
|
UART.CTRLA |= USART_TXCINTLVL_HI_gc;
|
||||||
|
|
||||||
|
//PORTD_OUTSET = PIN3_bm;
|
||||||
|
PORTD_DIRSET = PIN3_bm;
|
||||||
|
//PORTD_OUTCLR = PIN2_bm;
|
||||||
|
//PORTD_DIRCLR = PIN2_bm;
|
||||||
|
|
||||||
|
#endif//__AVR_ATxmega32A4__
|
||||||
|
|
||||||
#if PHYSICAL_TYPE == 485
|
#if PHYSICAL_TYPE == 485
|
||||||
TRANSCEIVER_ENABLE_PORT_DDR|=(1<<TRANSCEIVER_ENABLE_PIN);
|
TRANSCEIVER_ENABLE_PORT_DDR|=(1<<TRANSCEIVER_ENABLE_PIN);
|
||||||
transceiver_rxen();
|
transceiver_rxen();
|
||||||
#endif
|
#endif
|
||||||
BusState=(1<<TimerActive);
|
|
||||||
#else
|
|
||||||
//8bit
|
|
||||||
USARTD0.CTRLC = USART_CHSIZE0_bm | USART_CHSIZE1_bm;
|
|
||||||
|
|
||||||
//38400
|
|
||||||
USARTD0.BAUDCTRLA = bsel;
|
|
||||||
USARTD0.BAUDCTRLB = 0 | (bsel >> 8) | (bscale << USART_BSCALE0_bp);
|
|
||||||
|
|
||||||
USARTD0.CTRLB = USART_TXEN_bm | USART_RXEN_bm;
|
|
||||||
|
|
||||||
//Interrupt enable (levels)
|
|
||||||
USARTD0.CTRLA |= USART_RXCINTLVL_HI_gc;
|
|
||||||
USARTD0.CTRLA |= USART_TXCINTLVL_HI_gc;
|
|
||||||
|
|
||||||
PORTD_OUTSET = PIN3_bm;
|
|
||||||
PORTD_DIRSET = PIN3_bm;
|
|
||||||
PORTD_OUTCLR = PIN2_bm;
|
|
||||||
PORTD_DIRCLR = PIN2_bm;
|
|
||||||
|
|
||||||
//TODO Physical type 485
|
|
||||||
|
|
||||||
BusState=(1<<TimerActive);
|
BusState=(1<<TimerActive);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @brief: Sends a response.
|
/* @brief: Sends a response.
|
||||||
@@ -284,8 +276,7 @@ void modbusSendMessage(unsigned char packtop)
|
|||||||
#ifndef __AVR_ATxmega32A4__
|
#ifndef __AVR_ATxmega32A4__
|
||||||
UART_CONTROL|=(1<<UART_UDRIE);
|
UART_CONTROL|=(1<<UART_UDRIE);
|
||||||
#else
|
#else
|
||||||
//TODO use define for usartd
|
UART.CTRLA |= USART_DREINTLVL_HI_gc;
|
||||||
USARTD0_CTRLA |= USART_DREINTLVL_HI_gc;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BusState&=~(1<<ReceiveCompleted);
|
BusState&=~(1<<ReceiveCompleted);
|
||||||
|
|||||||
@@ -57,15 +57,11 @@ THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
/*
|
/*
|
||||||
* Definitions for transceiver enable pin.
|
* Definitions for transceiver enable pin.
|
||||||
*/
|
*/
|
||||||
#if BOARD_TYPE == bType5chLedDim
|
|
||||||
#define TRANSCEIVER_ENABLE_PORT PORTD
|
#define TRANSCEIVER_ENABLE_PORT PORTD_OUT
|
||||||
#define TRANSCEIVER_ENABLE_PIN 5
|
#define TRANSCEIVER_ENABLE_PIN 4
|
||||||
#define TRANSCEIVER_ENABLE_PORT_DDR DDRD
|
#define TRANSCEIVER_ENABLE_PORT_DDR PORTD_DIR
|
||||||
#else
|
|
||||||
#define TRANSCEIVER_ENABLE_PORT PORTD
|
|
||||||
#define TRANSCEIVER_ENABLE_PIN 2
|
|
||||||
#define TRANSCEIVER_ENABLE_PORT_DDR DDRD
|
|
||||||
#endif
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* At the moment the user has to set the value for Baudrate and
|
* 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
|
#define UART_UDRIE UDRIE
|
||||||
|
|
||||||
#elif defined(__AVR_ATxmega32A4__)
|
#elif defined(__AVR_ATxmega32A4__)
|
||||||
|
#define UART USARTD0
|
||||||
#define UART_TRANSMIT_COMPLETE_INTERRUPT USARTD0_TXC_vect
|
#define UART_TRANSMIT_COMPLETE_INTERRUPT USARTD0_TXC_vect
|
||||||
#define UART_RECEIVE_INTERRUPT USARTD0_RXC_vect
|
#define UART_RECEIVE_INTERRUPT USARTD0_RXC_vect
|
||||||
#define UART_TRANSMIT_INTERRUPT USARTD0_DRE_vect
|
#define UART_TRANSMIT_INTERRUPT USARTD0_DRE_vect
|
||||||
#define UART_DATA USARTD0.DATA
|
#define UART_DATA USARTD0.DATA
|
||||||
|
|
||||||
|
//9600 Baud at 32MHz system clock
|
||||||
|
#define UART_BSEL 208
|
||||||
|
#define UART_BSCALE 0
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error "no definition available"
|
#error "no definition available"
|
||||||
@@ -219,7 +220,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
* Use 485 or 232, default: 485
|
* Use 485 or 232, default: 485
|
||||||
* Use 232 for testing purposes or very simple applications that do not require RS485 and bus topology.
|
* 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
|
#define modbusBaudrate 38400
|
||||||
|
|||||||
Reference in New Issue
Block a user