This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

UART控制GPRS模块



我想通过 Tiva C开发板控制GPRS模块,需要用串口输出如AT\r、AT+CSQ\r 等字符串,在论坛内找到代码并修改如下:

//******************* Uart.c ***************************
// 硬件连接:配置电脑串口波特率115200,8-N-1,字符发送和接收
// 软件配置:1 在startup_ccs.c中添加 extern void UARTIntHandler(void);
//           2 在startup_ccs.c中修改中断向量表
//             IntDefaultHandler改为UARTIntHandler //UART0 Rx and Tx
// 实验现象:通过电脑串口发送一些字符,LM4F232评估板收到后会回发这些字符
//******************************************************

#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"

// 串口接收中断服务程序
void UARTIntHandler(void)
{
    unsigned long ulStatus;
    // 获取中断状态
    ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
    // 清除中断标志
    ROM_UARTIntClear(UART0_BASE, ulStatus);
    // 直到串口FIFO中没有数据时才退出循环
    while(ROM_UARTCharsAvail(UART0_BASE))
    {
        // 读串口接收的字符并回发
        ROM_UARTCharPutNonBlocking(UART0_BASE,
                        ROM_UARTCharGetNonBlocking(UART0_BASE));
    }
}

//  串口发送函数
void  UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
    while(ulCount--)
    {
        // 将要发送的字符写进UART
        ROM_UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++);
    }
}

int main(void)
{
    // 使能FPU
    FPUEnable();
    FPULazyStackingEnable();

    // 设置时钟直接使用外部晶振
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    // 使能用到的外设
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
// 配置PA0和PA1为串口0引脚
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    // 使能中断
    ROM_IntMasterEnable();

    // 配置UART0为115200,8-N-1
    ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
                           (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));
    // 使能串口中断
    ROM_IntEnable(INT_UART0);
    ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
    // 发送提示信息
    int i=1;
    while(i++){
    	if(i%100000==0)
    UARTSend((unsigned char *)"AT\r", 4);

    }
    while(1)
    {
    }
}

串口助手选择可以持续的收到AT,用示波器观察,管脚PA1有信号,PA0一直高电平。此时用其他的串连接到PA1,收到的是一堆乱码,修改代码切换UART6和GPIOJ如下:

//******************* Uart.c ***************************
// 硬件连接:配置电脑串口波特率115200,8-N-1,字符发送和接收
// 软件配置:1 在startup_ccs.c中添加 extern void UARTIntHandler(void);
//           2 在startup_ccs.c中修改中断向量表
//             IntDefaultHandler改为UARTIntHandler //UART0 Rx and Tx
// 实验现象:通过电脑串口发送一些字符,LM4F232评估板收到后会回发这些字符
//******************************************************

#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"

// 串口接收中断服务程序
void UARTIntHandler(void)
{
    unsigned long ulStatus;
    // 获取中断状态
    //ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
    ulStatus = ROM_UARTIntStatus(UART6_BASE, true);
    // 清除中断标志
  //  ROM_UARTIntClear(UART0_BASE, ulStatus);
    ROM_UARTIntClear(UART6_BASE, ulStatus);
    // 直到串口FIFO中没有数据时才退出循环
  // while(ROM_UARTCharsAvail(UART0_BASE))
        while(ROM_UARTCharsAvail(UART6_BASE))
    {
        // 读串口接收的字符并回发
//        ROM_UARTCharPutNonBlocking(UART0_BASE,
//                        ROM_UARTCharGetNonBlocking(UART0_BASE));
        ROM_UARTCharPutNonBlocking(UART6_BASE,
                               ROM_UARTCharGetNonBlocking(UART6_BASE));
    }
}

//  串口发送函数
void  UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
    while(ulCount--)
    {
        // 将要发送的字符写进UART
//        ROM_UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++);
        ROM_UARTCharPutNonBlocking(UART6_BASE, *pucBuffer++);
    }
}

int main(void)
{
    // 使能FPU
    FPUEnable();
    FPULazyStackingEnable();

    // 设置时钟直接使用外部晶振
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    // 使能用到的外设
    //ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
//ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART6);
// 配置PA0和PA1为串口0引脚
//    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    ROM_GPIOPinTypeUART(GPIO_PORTJ_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    // 使能中断
    ROM_IntMasterEnable();

    // 配置UART0为115200,8-N-1
//    ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
//                           (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
//                             UART_CONFIG_PAR_NONE));
   ROM_UARTConfigSetExpClk(UART6_BASE, ROM_SysCtlClockGet(), 115200,
                              (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                                UART_CONFIG_PAR_NONE));
    // 使能串口中断
//    ROM_IntEnable(INT_UART0);
//    ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
   ROM_IntEnable(INT_UART6);
   ROM_UARTIntEnable(UART6_BASE, UART_INT_RX | UART_INT_RT);
    // 发送提示信息
    int i=1;
    while(i++){
    	if(i%100000==0)
    UARTSend((unsigned char *)"AT\r", 4);

    }
    while(1)
    {
    }
}

 

则PJ4和PJ5都没有信号,请问如何修改,多谢