ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Вторник
3 декабря
1166072
Tpoeшник (18.01.2022 23:12, просмотров: 1129)
ATMega32U2. Изменение скорости UART "на ходу". 

Настроен UART на 115200. Нужно передать в процессе работы ПО пару байт на скорости 9600 бит в сек. Кварц 8МГц. Частота не точная получается, но мне подходит.

...
    UBRR1H = 0x00;                                                       // Set baud rate hi
    UBRR1L = 0x08;                                                       // Set baud rate  lo
    UCSR1B = (1<<RXEN1)|(1<<TXEN1)|(1<<UDRIE1)|(1<<RXCIE1);    	         // Enable receiver and transmitter 
    UCSR1C = (1<<UCSZ10)|(1<<UCSZ11)|(1<<USBS1);  
    UCSR1A = (1<<U2X1);  

...				

                                asm("cli");							
				UBRR1H = 0x00;                                                       // Set baud rate 
				UBRR1L = 103;      
				asm("sei");

				UARTTransmitByte (0x55);
				UARTTransmitByte (1);
				UARTTransmitByte (8);

				asm("cli");
				UBRR1H = 0x00;                                                       // Set baud rate 
				UBRR1L = 0x08; 
				asm("sei"); 

Не меняет гадкая американщина скорость(


"The USART has to be initialized before any communication can take place. The initialization process normally consists of setting the baud rate, setting frame format and enabling the Transmitter or the Receiver depending on the usage. For interrupt driven USART operation, the Global Interrupt Flag should be cleared (and interrupts globally disabled) when doing the initialization. Before doing a re-initialization with changed baud rate or frame format, be sure that there are no ongoing transmissions during the period the registers are changed. The TXCn Flag can be used to check that the Transmitter has completed all transfers, and the RXC Flag can be used to check that there are no unread data in the receive buffer. Note that the TXCn Flag must be cleared before each transmission (before UDRn is written) if it is used for this purpose."