コード例 #1
0
        /// <summary>
        /// Sets the baudrate to be used by the UART block
        /// </summary>
        /// <param name="rate">Baudrate - enumerated type</param>
        public void UART_setBaudRate(UART_baudRate rate)    //uses double speed operation(UCSR1A = 0x02)
        {
            UInt16 BR = (UInt16)(clockSpeed_Hz / (8 * (int)rate) - 1);

            byte[] b = BitConverter.GetBytes(BR);
            msgSend(section.UART, (byte)UART_Instr.setBaud, b);
        }
コード例 #2
0
        //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);
        }
コード例 #3
0
ファイル: Sections.cs プロジェクト: seankenny/NikNak
        //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);
        }
コード例 #4
0
ファイル: Sections.cs プロジェクト: seankenny/NikNak
 //uses double speed operation(UCSR1A = 0x02)
 /// <summary>
 /// Sets the baudrate to be used by the UART block
 /// </summary>
 /// <param name="rate">Baudrate - enumerated type</param>
 public void UART_setBaudRate(UART_baudRate rate)
 {
     UInt16 BR = (UInt16)(clockSpeed_Hz / (8 * (int)rate) - 1);
     byte[] b = BitConverter.GetBytes(BR);
     msgSend(section.UART, (byte)UART_Instr.setBaud, b);
 }