/*! \brief Example application. * * Example application. This example configures USARTE0 for with the parameters: * - 8 bit character size * - No parity * - 1 stop bit * - 9600 Baud * * This function then sends three bytes and tests if the received data is * equal to the sent data. The code can be tested by connecting PC3 to PC2. If * the variable 'success' is true at the end of the function, the three bytes * have been successfully sent and received. */ int main(void) { /* counter variable. */ uint8_t i; ConfigClockSystem(); ConfigUart(); /* Enable global interrupts. */ sei(); /* Fetch received data as it is received. */ i = 0; while (i != '@') { if (USART_RXBufferData_Available(&USART_data)) { i = USART_RXBuffer_GetByte(&USART_data); USART_TXBuffer_PutByte(&USART_data, i); } } /* Disable both RX and TX. */ USART_Rx_Disable(&USART); USART_Tx_Disable(&USART); return 0; }
void USART_TransmitMode(USART * serial, bool doTx) { /*if (serial->use_rs485) { if (doTx) PORTE.OUTSET = PIN1_bm; else PORTE.OUTCLR = PIN1_bm; if (serial->use_rs485) PORTF.OUTSET = PIN7_bm; }*/ /*if (serial->port_num==4) { if (serial->use_rs485) { if (doTx) { serial->port.gpio_port->OUTSET = serial->port.txen_pin_bm; } else serial->port.gpio_port->OUTCLR = serial->port.txen_pin_bm; } }*/ if (serial->use_rs485) { if (doTx) { USART_Rx_Disable(serial->port.usart_port); serial->port.gpio_port->OUTSET = serial->port.txen_pin_bm; //PORTE.OUTSET = PIN1_bm; } else { serial->port.gpio_port->OUTCLR = serial->port.txen_pin_bm; USART_Rx_Enable(serial->port.usart_port); } } }
void USART_TransmitMode(USART * serial, bool doTx) { if (serial->use_rs485) { if (doTx) { USART_Rx_Disable(serial->port); *(serial->port.GPIO) |= serial->port.txen_pin_bm; } else { // going into RX mode *(serial->port.GPIO) &= ~(serial->port.txen_pin_bm); USART_Rx_Enable(serial->port); } } }