Go to the documentation of this file.
59 #ifndef USART_DRIVER_H
60 #define USART_DRIVER_H
67 #define USART_RX_BUFFER_SIZE 4
69 #define USART_TX_BUFFER_SIZE 4
71 #define USART_RX_BUFFER_MASK ( USART_RX_BUFFER_SIZE - 1 )
73 #define USART_TX_BUFFER_MASK ( USART_TX_BUFFER_SIZE - 1 )
76 #if ( USART_RX_BUFFER_SIZE & USART_RX_BUFFER_MASK )
77 #error RX buffer size is not a power of 2
79 #if ( USART_TX_BUFFER_SIZE & USART_TX_BUFFER_MASK )
80 #error TX buffer size is not a power of 2
94 #define USART_Format_Set(_usart, _charSize, _parityMode, _twoStopBits) \
95 (_usart)->CTRLC = (uint8_t) _charSize | _parityMode | \
96 (_twoStopBits ? USART_SBMODE_bm : 0)
121 #define USART_Baudrate_Set(_usart, _bselValue, _bScaleFactor) \
122 (_usart)->BAUDCTRLA =(uint8_t)_bselValue; \
123 (_usart)->BAUDCTRLB =(_bScaleFactor << USART_BSCALE0_bp)|(_bselValue >> 8)
130 #define USART_Rx_Enable(_usart) ((_usart)->CTRLB |= USART_RXEN_bm)
137 #define USART_Rx_Disable(_usart) ((_usart)->CTRLB &= ~USART_RXEN_bm)
144 #define USART_Tx_Enable(_usart) ((_usart)->CTRLB |= USART_TXEN_bm)
151 #define USART_Tx_Disable(_usart) ((_usart)->CTRLB &= ~USART_TXEN_bm)
162 #define USART_RxdInterruptLevel_Set(_usart, _rxdIntLevel) \
163 ((_usart)->CTRLA = ((_usart)->CTRLA & ~USART_RXCINTLVL_gm) | _rxdIntLevel)
174 #define USART_TxdInterruptLevel_Set(_usart, _txdIntLevel) \
175 (_usart)->CTRLA = ((_usart)->CTRLA & ~USART_TXCINTLVL_gm) | _txdIntLevel
187 #define USART_DreInterruptLevel_Set(_usart, _dreIntLevel) \
188 (_usart)->CTRLA = ((_usart)->CTRLA & ~USART_DREINTLVL_gm) | _dreIntLevel
204 #define USART_SetMode(_usart, _usartMode) \
205 ((_usart)->CTRLC = ((_usart)->CTRLC & (~USART_CMODE_gm)) | _usartMode)
213 #define USART_IsTXDataRegisterEmpty(_usart) (((_usart)->STATUS & USART_DREIF_bm) != 0)
225 #define USART_PutChar(_usart, _data) ((_usart)->DATA = _data)
235 #define USART_IsRXComplete(_usart) (((_usart)->STATUS & USART_RXCIF_bm) != 0)
249 #define USART_GetChar(_usart) ((_usart)->DATA)