реклама на сайте
подробности

 
 
> ATmega128, printf()
mjpronin
сообщение Feb 13 2010, 14:41
Сообщение #1


Участник
*

Группа: Участник
Сообщений: 50
Регистрация: 26-01-10
Пользователь №: 55 071



Всем доброе время суток.

Работаю с Atmega128 использую UART1 (т.е. второй из двух) использую putchar() & getchar() для UART1 (т.е. работаю с UDR1) без проблем.

Подскажите как работать с printf() через UART1, так как с UART1 эта функция не работает, а она очень удобна.

На других Atmega** с одним UART printf() работает.


1. Каким образом переопределить printf для работы с UART1
2. Будет ли printf работать с UART0
3. Не приведет ли использование UART0 на ATmega128 к проблемам, т.к. эти ноги у ATmega128 совпадают с ногами последовательного программирования. PDI PDO

Спасибо.
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
Savrik
сообщение Feb 14 2010, 11:30
Сообщение #2


наблюдаю..
***

Группа: Свой
Сообщений: 291
Регистрация: 11-12-06
Из: Украина
Пользователь №: 23 369



Вот цитата их хелпа CAVR:
Цитата
For devices with 2 UARTs, respectively 2 USARTs, there will be two tabs present: UART0 and UART1, respectively USART0 and USART1.
The functions of configuration check and list boxes will be the same as described above.


The UART0 (USART0) will use the normal putchar and getchar functions.
In case of interrupt driven buffered communication, UART0 (USART0) will use the following variables:
rx_buffer0, rx_wr_index0, rx_rd_index0, rx_counter0, rx_buffer_overflow0,
tx_buffer0, tx_wr_index0, tx_rd_index0, tx_counter0.


The UART1 (USART1) will use the putchar1 and getchar1 functions.
In case of interrupt driven buffered communication, UART1 (USART1) will use the following variables:
rx_buffer1, rx_wr_index1, rx_rd_index1, rx_counter1, rx_buffer_overflow1,
tx_buffer1, tx_wr_index1, tx_rd_index1, tx_counter1.

Цитата
If you intend to use other peripherals for Input/Output, you must modify accordingly the getchar and putchar functions like in the example below:
/* inform the compiler that an alternate version
of the putchar function will be used */
#define _ALTERNATE_PUTCHAR_


/* now define the new putchar function */
void putchar(char c) {
/* write your code here */

}

Цитата
For the ATxmega chips the getchar and putchar functions use by default the USARTC0.
If you wish to use another USART, you must define the _ATXMEGA_USART_ preprocessor macro prior to #include the stdio.h header file, like in the example below:


/* use the ATxmega128A1 USARTD0 for getchar and putchar functions */
#define _ATXMEGA_USART_ USARTD0


/* use the Standard C I/O functions */
#include <stdio.h>


The _ATXMEGA_USART_ macro needs to be defined only once in the whole program, as the compiler will treat it like it is globally defined

Цитата
void printf(char flash *fmtstr [ , arg1, arg2, ...])


outputs formatted text, using putchar, according to the format specifiers in the fmtstr string.


Дальше либо шаманство с перегрузкой, либо просто добавить в своей putchar() проверку, куда отправляются данные, и вызывать соответствующую функция. Сделать можно, к примеру, установкой глобальной переменной uart_number.

Сообщение отредактировал Savrik - Feb 14 2010, 11:36
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 23rd July 2025 - 13:17
Рейтинг@Mail.ru


Страница сгенерированна за 0.01366 секунд с 7
ELECTRONIX ©2004-2016