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

 
 
> Как сконфигурировать второй UART в Tiva TM4C123?
kuka_v
сообщение Aug 25 2016, 08:28
Сообщение #1





Группа: Участник
Сообщений: 9
Регистрация: 1-08-16
Пользователь №: 92 797



Вкуривание документации и просмотр учебных видео мне не помогло.
Помогите, что надо поправить в коде, чтобы задействовать UART1 на плате TI Tiva TM4C123?
Вот код из учебника, который рассказывает иностранный дядечка.
Первые две строчки я понял как расширить на пару портов, я вот дальше...
Я хочу оставить UART0 для отладочных сообщений, тогда как UART1 работает с внешней аппаратурой.
Даташит на плату вот:
http://www.ti.com/general/docs/lit/getlite...mp;fileType=pdf

CODE
#include <lm4f120h5qr.h>

char readChar(void);
void printChar(char c);
void printString(char * string);

int main(void) {
char c;
// 1. Enable the UART module using the RCGCUART register (see page 344).
SYSCTL->RCGCUART |= (1<<0)|(1<<1);

// 2. Enable the clock to the appropriate GPIO module via the RCGCGPIO register (see page 340).
SYSCTL->RCGCGPIO |= (1<<0)|(1<<1);

// 3. Set the GPIO AFSEL bits for the appropriate pins (see page 671 To determine which GPIOs to
// configure see table 23-4 on page 1344
GPIOA->AFSEL = (1<<1)|(1<<0);

// 4. Configure the GPIO current level and/or slew rate as specified for the mode selected (see
// page 673 and page 681

// 5. Configure the PMCn fields in the GPIOPCTL register to assign the UART signals to the appropriate
// pins (see page 688 and Table 23-5 on page 1351).
GPIOA->PCTL = (1<<0)|(1<<4);

GPIOA->DEN = (1<<0)|(1<<1);

// Find the Baud-Rate Divisor
// BRD = 16,000,000 / (16 * 9600) = 104.1666666666666666666666666666666
// UARTFBRD[DIVFRAC] = integer(0.166667 * 64 + 0.5) = 11

// With the BRD values in hand, the UART configuration is written to the module in the following order

// 1. Disable the UART by clearing the UARTEN bit in UARTCTL register
UART0->CTL &= ~(1<<0);

// 2. Write the integer portion of the BRD to the UARTIBRD register
UART0->IBRD = 104;
// 3. Write the fractional portion of the BRD to the UARTFBRD register
UART0->FBRD = 11;

// 4. Write the desired serial parameters to the UARTLCTL register
UART0->LCRH = (0x3<<5);

// 5. Configure the UART clock source by written to the UARTCC register
UART0->CC = 0x0;

// 6.
// 7. Enable the USRT by setting the UARTEN bit in the UARTCTL register
UART0->CTL = (1<<0)|(1<<8)|(1<<9);

//Configure LED pins
SYSCTL->RCGCGPIO |= (1<<5); // enable clock on PortF
GPIOF->DIR = (1<<1)|(1<<2)|(1<<3); //make LED pins (PF1 PF2 PF3) outputs
GPIOF->DEN = (1<<1)|(1<<2)|(1<<3); // enable digitalfunctions for the LED pins
GPIOF->DATA &= ~((1<<1)|(1<<2)|(1<<3)); // turn off leds

while(1) {
printString("Enter \"r\", \"g\", or \"b\":\n\r");

c = readChar();
printChar©;
printString("\n\r");
switch© {
case 'r':
GPIOF->DATA = (1<<1); // red LED on
break;
case 'b':
GPIOF->DATA = (1<<2); // blue LED on
break;
case 'g':
GPIOF->DATA = (1<<3); // red LED on
break;
default:
GPIOF->DATA &= ~(1<<1)|(1<<2)|(1<<3); // red LED on
break;
}
}
}
char readChar(void){
char c;
while((UART0->FR & (1<<4)) != 0);
c = UART0->DR;
return c;
}

void printChar(char c) {
while((UART0->FR & (1<<5)) != 0);
UART0->DR = c;
}

void printString(char * string) {
while(*string)
{
printChar(*(string++));
}
}


Сообщение отредактировал IgorKossak - Aug 25 2016, 09:09
Причина редактирования: [codebox] для длинного кода, [code] - для короткого!
Go to the top of the page
 
+Quote Post



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

 


RSS Текстовая версия Сейчас: 19th July 2025 - 19:40
Рейтинг@Mail.ru


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