Gast
#49680
void
txoff() {
// wait for bytes still to go
loop_until_bit_is_set(UCSRA, TXC);
PORTD &= ~_BV(PD2); // disable transmitter
UCSRB |= _BV(TXEN); /* rx enable */
PORTC |= _BV(PC3); // disable txled
}
Obige Funktion sollte eigendlich den Ausgangstreiber für eine
Halbduplex RS485 Anwendung abschalten, sobald das letzte Zeichen
verschickt wurde.
Allerdings kommt das Programm scheinbar nicht über die Warteschleife
hinweg.
Unten sind noch mal die wichtige Funktionen für die Ausgabe.
inline void
sio_putchar(uint8_t c)
{
loop_until_bit_is_set(UCSRA, UDRE);
UDR = c;
}
#define SYSCLK 7372800UL
#define BPS_RATE 9600UL
void
ioinit() {
/* setup UART */
UCSRB = _BV(TXEN) | _BV(RXEN); /* rx/tx enable */
UBRRL = (SYSCLK / (16 * BPS_RATE)) - 1; /* Bd */
PORTD &= ~_BV(PD2); // disable transmitter
DDRD |= _BV(PD2); // set txen as output
...
}
void
txon() {
PORTD |= _BV(PD2); // enable transmitter
UCSRB &= ~_BV(TXEN); /* rx disable */
PORTC &= ~_BV(PC3); // enable txled
}