Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 16000000UL
- // (I have also tried disabling the 16 MHz clock and fall back
- // to the 8 MHz clock, setting OCR1A to 0x03EF, with no success)
- void uart1_init() {
- uint16_t baudrate = UART_BAUD_SELECT(BAUD485, F_CPU));
- UBRR1H = (uint8_t)(baudrate>>8);
- UBRR1L = (uint8_t) baudrate;
- // Clear USART Transmit complete flag, normal USART transmission speed
- UCSR1A = (1 << TXC1) | (0 << U2X1);
- // Enable receiver, transmitter and receive interrupt
- UCSR1B = (1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1);
- // Asynchronous mode, no parity, 1 stop bit, character size = 8-bit
- UCSR1C = (1 << UCSZ11) | (1 << UCSZ10) | (0 << UCPOL1);
- }
- // somewhere later: sei();
- volatile uint32_t time = 0;
- void timer_init(void) {
- // This code sets up Timer1 for a 1ms @ 16Mhz Clock (mode 4)
- OCR1A = 0x07CF;
- // Mode 4, CTC on OCR1A
- TCCR1B |= (1 << WGM12);
- // Set interrupt on output compare match
- TIMSK1 |= (1 << OCIE1A);
- // Set prescaler to 8 and start the timer
- TCCR1B |= (1 << CS11) ;
- }
- ISR(TIMER1_COMPA_vect) {
- // Action to be done every 1 ms
- // Problem also occurs with empty interrupt
- // What I should have here: time++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement