#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);//ʹÄÜ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);//ʹÄÜ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);///½ÓÊÕµ½Êý¾Ý£¬ÁÁµÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///ÑÓʱ³ÌÐò
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0xff);///½ÓÊÕµ½Êý¾Ý£¬ÁÁµÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///ÑÓʱ³ÌÐò
ui8DataTx[0] = 'u';
ui8DataTx[1] = 'a';
ui8DataTx[2] = 'r';
ui8DataTx[3] = 't';
while(1)
{
//uartPuts("HELLO EEWORLD:\r\n"); // ÇëÊäÈëÒ»¸öÃüÁ°´»Ø³µÖ´ÐÐ
UARTSend(UART3_BASE, (uint8_t *)"0101", NUM_UART_DATA);
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x00);///½ÓÊÕµ½Êý¾Ý£¬ÁÁµÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///ÑÓʱ³ÌÐò
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0xff);///½ÓÊÕµ½Êý¾Ý£¬ÁÁµÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///ÑÓʱ³ÌÐò
/* c=UARTCharGet(UART3_BASE);
if(c=='1')
{
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_3,0x07);///½ÓÊÕµ½Êý¾Ý£¬ÁÁµÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///ÑÓʱ³ÌÐò
}
if(c=='0')
{
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_3,0xff);///½ÓÊÕµ½Êý¾Ý£¬ÁÁµÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///ÑÓʱ³ÌÐò
}
SerialRxData[SerialDataCount]=UARTCharGet(UART3_BASE);///²»½ÓÊÕµ½Êý¾Ý£¬µÈ´ý
if(SerialRxData[SerialDataCount])
{
GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_3,0x07);///½ÓÊÕµ½Êý¾Ý£¬ÁÁµÆ
SysCtlDelay(1000 * (ui32SysClock/ 3000));///ÑÓʱ³ÌÐò
}*/
}
}
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++);
}
}
// ͨ¹ýUART·¢ËÍÒ»¸ö×Ö·û
void uartPutc(const char c)
{
UARTCharPut(UART3_BASE, c);
}
// ͨ¹ýUART·¢ËÍ×Ö·û´®
void uartPuts(const char *s)
{
while (*s != '\0')
{
//UARTCharPut(UART3_BASE, *(s++)); uartPutc(*(s++));
}
}
xyz549040622:
你用的是485吗?先看看串口是否可以输出数据呢?然后再调485?硬件是怎么连接485的呢?给的信息不全
TI中文支持网
