//methods /// <summary> /// Sets up the UART, causes the functions of the pins PD2/PD3 to be overridden by the UART /// </summary> /// <param name="rate">Baudrate to be used</param> /// <param name="stopbits">Number of stop bits to be used (1 or 2)</param> public void UART_setup(UART_baudRate rate, UART_stopBits stopbits) { UART_enabled = true; byte UCSR1A = 0x02; //double speed mode enabled (always better accuracy at 8MHz) byte UCSR1B = 0xD8; //Set interrupts to enabled, enable transmitter and reciever (data reg empty interrupt disabled) byte UCSR1C = (byte)(0x06 + (byte)stopbits); //async operation, parity disabled, 8bit frames, settable stopbits byte UCSR1D = 0x00; //CTS/RTS disabled //double speed baudrate calc UInt16 BR = (UInt16)(clockSpeed_Hz / (8 * (int)rate) - 1); byte[] b = BitConverter.GetBytes(BR); //data expected: UCSR1A UCSR1B UCSR1C UCSR1D UBRR1H UBRR1L byte[] data = { UCSR1A, UCSR1B, UCSR1C, UCSR1D, b[0], b[1] }; msgSend(section.UART, (byte)UART_Instr.setRegisters, data); }