#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "inc/hw_types.h"
#include "driverlib/fpu.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "inc/hw_gpio.h"
#define UARTConfigSet(a, b, c) UARTConfigSetExpClk(a, 16000000, b, c)
#define NUM_UART_DATA 4
#define GPIO_PA5_U3TX 0x00001401
#define GPIO_PA4_U3RX 0x00001001
uint8_t ui8DataTx[NUM_UART_DATA];
/*char SerialRxData[200];
int SerialDataCount = 0;
void
UARTSend(const uint8_t *pui8Buffer, unsigned long ui32Count)
{
while(ui32Count--)
{
UARTCharPut(UART5_BASE, *pui8Buffer++);
}
}*/
///
int main(void)
{
void UARTSend();
void uartPuts();
// char c;
uint32_t ui32SysClock;
ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
/*
IntMasterDisable();
IntEnable(SYSCTL_OSC_INT);
*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);//ê1ÄüGPIOA¿ú
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
GPIOPinConfigure(GPIO_PA4_U3RX);
GPIOPinConfigure(GPIO_PA5_U3TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5);
//UARTClockSourceSet(UART3_BASE,UART_CLOCK_PIOSC);
UARTConfigSet(UART3_BASE, 9600, (UART_CONFIG_WLEN_8 |
UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
//μãááLED
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);//ê1ÄüGPIOH¿ú
GPIODirModeSet(GPIO_PORTH_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,GPIO_DIR_MODE_OUT);
GPIOPadConfigSet(GPIO_PORTH_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,GPIO_STRENGTH_8MA_SC,GPIO_PIN_TYPE_STD);
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x00);///½óêÕμ½êy¾Y£¬ááμÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///Ñóê±3ìDò
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0xff);///½óêÕμ½êy¾Y£¬ááμÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///Ñóê±3ìDò
ui8DataTx[0] = 'u';
ui8DataTx[1] = 'a';
ui8DataTx[2] = 'r';
ui8DataTx[3] = 't';
while(1)
{
uartPuts("HELLO EEWORLD:
"); // Çëêäèëò»¸öÃüá°′»Ø3μÖ′DD
UARTSend(UART3_BASE, (uint8_t *)ui8DataTx, NUM_UART_DATA);
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x00);///½óêÕμ½êy¾Y£¬ááμÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///Ñóê±3ìDò
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0xff);///½óêÕμ½êy¾Y£¬ááμÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///Ñóê±3ìDò
/* c=UARTCharGet(UART3_BASE);
if(c=='1')
{
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_3,0x07);///½óêÕμ½êy¾Y£¬ááμÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///Ñóê±3ìDò
}
if(c=='0')
{
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_3,0xff);///½óêÕμ½êy¾Y£¬ááμÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///Ñóê±3ìDò
}
SerialRxData[SerialDataCount]=UARTCharGet(UART3_BASE);///2»½óêÕμ½êy¾Y£¬μè′y
if(SerialRxData[SerialDataCount])
{
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_3,0x07);///½óêÕμ½êy¾Y£¬ááμÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///Ñóê±3ìDò
}*/
}
}
void
UARTSend(uint32_t ui32UARTBase, const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
MAP_UARTCharPut(ui32UARTBase, *pui8Buffer++);
}
}
// í¨1yUART·¢Ëíò»¸ö×Ö·û
void uartPutc(const char c)
{
UARTCharPut(UART3_BASE, c);
}
// í¨1yUART·¢Ëí×Ö·û′®
void uartPuts(const char *s)
{
while (*s != ' ')
{
//UARTCharPut(UART3_BASE, *(s++));
uartPutc(*(s++));
}
}
此帖出自
小平头技术问答
串口助手上的显示的数据就是图片上这样。我单步运行了一下,确实是执行UARTSend时才会在串口助手上写00。无论怎么改程序里待发送的值都是这样。
一周热门 更多>