Hello, i'm student from Brazil. And i tryed to use uart2 to having comunication to my hc-05 bluetooth module. But i don't know how unlock the pin( PD7, PD6) for that. I read all the forum and nothing resolves. Every time give me the same result. Every time, when program do the line "GPIOPinConfigure(GPIO_PCTL_PD7_U2TX);" result in FaultISR.
All my code is below.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/gpio.c"
#include "driverlib/pin_map.h"
#include "inc/lm4f120h5qr.h"
//#include "inc/hw_memmap.h"
//#include "inc/hw_types.h"
//#include "driverlib/gpio.h"
//#include "driverlib/pin_map.h"
//#include "driverlib/sysctl.h"
//#include "driverlib/uart.h"
//#include "inc/lm4f120h5qr.h"
int main(void) {
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //habilita a porta B
//HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
//HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x80;
// HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = 0x4C4F434B; //GPIO_LOCK_KEY; 0x4C4F434B// 0xACCE551
// HWREG(GPIO_PORTD_BASE + GPIO_O_CR) |= 0xC0;
// HWREG(GPIO_PORTD_BASE + GPIO_O_AFSEL) &= ~0x80;
// HWREG(GPIO_PORTD_BASE + GPIO_O_DEN) |= 0x80;
// HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = 0;
// Unlock access to the commit register
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
//
// Set the commit register for PD7 to allow changing the function
//
HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x80;
//
// Enable the alternate function for PD7 (U2TX)
//
HWREG(GPIO_PORTD_BASE + GPIO_O_AFSEL) |= 0x400;
//
// Turn on the digital enable for PD7
//
HWREG(GPIO_PORTD_BASE + GPIO_O_DEN) |= 0x80;
//
// Relock the commit register
//
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = 0;
GPIOPinConfigure(GPIO_PCTL_PD7_U2TX); //quer disser que o pino pb7 vai ser o TX
SysCtlDelay(20000000);
GPIOPinConfigure(GPIO_PCTL_PD6_U2RX); //quer disser que o pino pb6 vai ser o RX
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); //vai habilitar o modulo 1 uart2
// GPIO_PCTL_PB0_U1RX
// GPIOPinConfigure(GPIO_PA0_U0RX);
// GPIOPinConfigure(GPIO_PA1_U0TX);
//GPIOPinConfigure(GPIO_PCTL_PA0_U0RX);
// GPIOPinConfigure(GPIO_PCTL_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_7 | GPIO_PIN_6); //vai setar as portas como uart
//na prototipação é qual uart vai ser, o valor do clock, baud rate, numerodebits|1bitdeparada|sembitdeparidade
UARTConfigSetExpClk(UART2_BASE, SysCtlClockGet(), 9600,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); //com4
UARTCharPut(UART2_BASE, 'E');
UARTCharPut(UART2_BASE, 'n');
UARTCharPut(UART2_BASE, 't');
UARTCharPut(UART2_BASE, 'e');
UARTCharPut(UART2_BASE, 'r');
UARTCharPut(UART2_BASE, ' ');
UARTCharPut(UART2_BASE, 'T');
UARTCharPut(UART2_BASE, 'e');
UARTCharPut(UART2_BASE, 'x');
UARTCharPut(UART2_BASE, 't');
UARTCharPut(UART2_BASE, ':');
UARTCharPut(UART2_BASE, ' ');
while (1)
{
UARTCharPut(UART2_BASE, '1');
UARTCharPut(UART2_BASE, '2');
UARTCharPut(UART2_BASE, '3');
UARTCharPut(UART2_BASE, '4');
UARTCharPut(UART2_BASE, '5');
UARTCharPut(UART2_BASE, '6');
UARTCharPut(UART2_BASE, ' ');
SysCtlDelay(20000000);
//if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
}
}