//! enable and initialize the software uart void uartswInit(void) { // initialize the buffers uartswInitBuffers(); // initialize the ports sbi(UARTSW_TX_DDR, UARTSW_TX_PIN); cbi(UARTSW_RX_DDR, UARTSW_RX_PIN); cbi(UARTSW_RX_PORT, UARTSW_RX_PIN); // initialize baud rate uartswSetBaudRate(9600); // setup the transmitter UartswTxBusy = FALSE; // disable OC2 interrupt cbi(TIMSK, OCIE2); // attach TxBit service routine to OC2 timerAttach(TIMER2OUTCOMPARE_INT, uartswTxBitService); // setup the receiver UartswRxBusy = FALSE; // disable OC0 interrupt cbi(TIMSK, OCIE0); // attach RxBit service routine to OC0 timerAttach(TIMER0OUTCOMPARE_INT, uartswRxBitService); // INT2 trigger on rising edge sbi(EICRA, ISC20); // enable INT2 interrupt sbi(EIMSK, INT2); // turn on interrupts sei(); }
//! enable and initialize the software uart void uartswInit(void) { // initialize the buffers uartswInitBuffers(); // initialize the ports sbi(UARTSW_TX_DDR, UARTSW_TX_PIN); cbi(UARTSW_RX_DDR, UARTSW_RX_PIN); cbi(UARTSW_RX_PORT, UARTSW_RX_PIN); // initialize baud rate uartswSetBaudRate(9600); // setup the transmitter UartswTxBusy = FALSE; // disable OC1A interrupt cbi(TIMSK, OCIE1A); // attach TxBit service routine to OC1A timerAttach(TIMER1OUTCOMPAREA_INT, uartswTxBitService); // setup the receiver UartswRxBusy = FALSE; // disable OC1B interrupt cbi(TIMSK, OCIE1B); // attach RxBit service routine to OC1B timerAttach(TIMER1OUTCOMPAREB_INT, uartswRxBitService); // attach RxBit service routine to ICP timerAttach(TIMER1INPUTCAPTURE_INT, uartswRxBitService); // trigger on rising edge sbi(TCCR1B, ICES1); // enable ICP interrupt sbi(TIMSK, TICIE1); // turn on interrupts sei(); }
// functions void radioInit(void) { // Initialize radio interface // Since this radio creates a special serial interface, // we initialize it here. uartswInit(); // set baud rate of comm uartswSetBaudRate(4800); // initialize stxetx to use the software UART for sending data stxetxInit(uartswSendByte); }
// enable and initialize the software uart void uartswInit(void) { // initialize the buffers uartswInitBuffers(); // initialize the ports sbi(UARTSW_TX_DDR, UARTSW_TX_PIN); #ifdef UARTSW_INVERT cbi(UARTSW_TX_PORT, UARTSW_TX_PIN); #else sbi(UARTSW_TX_PORT, UARTSW_TX_PIN); #endif cbi(UARTSW_RX_DDR, UARTSW_RX_PIN); #ifdef UARTSW_INVERT cbi(UARTSW_RX_PORT, UARTSW_RX_PIN); #else sbi(UARTSW_RX_PORT, UARTSW_RX_PIN); #endif // initialize baud rate uartswSetBaudRate(9600); // setup the transmitter UartswTxBusy = FALSE; // disable OC0A interrupt cbi(TIMSK0, OCIE0A); // attach TxBit service routine to OC0A timerAttach(TIMER0OUTCOMPAREA_INT, uartswTxBitService); // setup the receiver UartswRxBusy = FALSE; // disable 0C0B interrupt cbi(TIMSK0, OCIE0B); // attach RxBit service routine to OC0B timerAttach(TIMER0OUTCOMPAREB_INT, uartswRxBitService); // INT1 trigger on rising/falling edge #ifdef UARTSW_INVERT sbi(EICRA, ISC11); sbi(EICRA, ISC10); #else sbi(EICRA, ISC11); cbi(EICRA, ISC10); #endif // enable INT1 interrupt sbi(EIMSK, INT1); // turn on interrupts sei(); }
//! enable and initialize the software uart void uartswInit(void) { // initialize the buffers uartswInitBuffers(); // initialize the ports sbi(UARTSW_TX_DDR, UARTSW_TX_PIN); #ifdef UARTSW_INVERT cbi(UARTSW_TX_PORT, UARTSW_TX_PIN); #else sbi(UARTSW_TX_PORT, UARTSW_TX_PIN); #endif cbi(UARTSW_RX_DDR, UARTSW_RX_PIN); cbi(UARTSW_RX_PORT, UARTSW_RX_PIN); // initialize baud rate uartswSetBaudRate(9600); // setup the transmitter UartswTxBusy = FALSE; // disable OC2 interrupt cbi(TIMSK0, OCIE2A); // attach TxBit service routine to OC2 timerAttach(TIMER2OUTCOMPARE_INT, uartswTxBitService); // setup the receiver UartswRxBusy = FALSE; // disable OC0 interrupt cbi(TIMSK0, OCIE0A); // attach RxBit service routine to OC0 timerAttach(OCIE0A, uartswRxBitService); // INT2 trigger on rising/falling edge #ifdef UARTSW_INVERT sbi(MCUCR, ISC11); // rising edge #else cbi(MCUCR, ISC11); // falling edge #endif // enable INT2 interrupt sbi(PCMSK0, PCINT2); // turn on interrupts sei(); }
int main(void) { // initialize our libraries // initialize the UART (serial port) uartswInit(); // set the baud rate of the UART for our debug/reporing output uartswSetBaudRate(9600); int serialChar; //serialChar='0'; // should be transmit the first byte after power recycle. // Otherwise, you should lost the first received byte. // serialChar = '0'; // loop_until_bit_is_set(UCSR0A, UDRE0); // UDR0 = (uint8_t)serialChar; while (1) { while ((serialChar = uartswGetByte()) == -1); uartswSendByte((uint8_t)serialChar); //_delay_ms(1000); } return 0; }