Lê Quang Dũng
Trứng gà
anh/ chị giúp em xem code giao tiếp với bluetooth dưới đây với, hc05 kết nối được nhưng khi gởi dữ liệu thì đèn PF_2 không nháy và Terminal nối uart0 không hiển thị ký tự @@. Đã khai báo Interrupt trong statup. Em xin cám ơn!
Code:
#include<stdint.h>
#include<stdbool.h>
#include"inc/hw_types.h"
#include"inc/hw_memmap.h"
//#include"inc/tm4c123gh6pm.h"
#include"inc/hw_ints.h"
#include"driverlib/gpio.h"
#include"driverlib/sysctl.h"
#include"driverlib/interrupt.h"
#include"driverlib/timer.h"
#include"driverlib/uart.h"
#include"utils/uartstdio.h"
#include"driverlib/pin_map.h"
/*
* main.c
*/
void clockSet()
{
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
}
void gpioSet()
{
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3);
}
void uartSet()
{
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0|GPIO_PIN_1);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
UARTStdioConfig(0,115200, 16000000);
}
void bluetoothInt(void)
{
uint32_t state;
state=UARTIntStatus(UART3_BASE, true);
UARTIntClear(UART3_BASE,state);
while (UARTCharsAvail(UART3_BASE))
{
UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART3_BASE));
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
SysCtlDelay((SysCtlClockGet()/3)/1000);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,0);
}
}
void bluetoothSet()
{
GPIOPinConfigure(GPIO_PC6_U3RX);
GPIOPinConfigure(GPIO_PC7_U3TX);
GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6|GPIO_PIN_7);
UARTConfigSetExpClk(UART3_BASE, SysCtlClockGet(), 9600, UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE);
IntMasterEnable();
IntEnable(INT_UART3);
UARTIntEnable(UART3_BASE, UART_INT_RX|UART_INT_RT);
}
void main()
{
clockSet();
uartSet();
gpioSet();
bluetoothSet();
// GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);
while (1)
{
/** unsigned char chars;
while (UARTCharsAvail(UART3_BASE))
{
chars=UARTCharGet(UART3_BASE);
UARTCharPut(UART3_BASE, chars);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
// SysCtlDelay(SysCtlClockGet()/3);
}
//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,0);**/
}
}