UART485通信,请问为什么接收的到的数据都是00?

2019-03-24 08:36发布

#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++));
    }

}


此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
16条回答
东西南北142
2019-03-26 08:44
wateras1 发表于 2017-4-10 13:47
是的,你这块不是用一个GPIO控制的吗

配置了一个GPIO控制,输出的量还是00。
#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 GPIO_PA5_U3TX           0x00001401
#define GPIO_PA4_U3RX           0x00001001
#define GPIO_PA6_U2RX           0x00001801
#define GPIO_PA7_U2TX           0x00001C01

        void
UARTSend(uint32_t ui32UARTBase, const uint8_t *pui8Buffer, uint32_t ui32Count);
        //void uartPuts();
int main(void)
{
    uint8_t ui8DataTx[4];
    uint8_t ui8DataRx[4];
     uint32_t ui32index;
       
         uint32_t ui32SysClock;
         ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);
       
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);///PC7£¬485¿úμÄêÕ·¢¿ØÖÆ
        GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_7);
        GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_7,0xff);
       
  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);
        UARTConfigSet(UART3_BASE, 115200, (UART_CONFIG_WLEN_8 |
       UART_CONFIG_STOP_ONE |
       UART_CONFIG_PAR_NONE));

        //UARTLoopbackEnable(UART3_BASE);
       
          ui8DataTx[0] = 'u';
    ui8DataTx[1] = 'a';
    ui8DataTx[2] = 'r';
    ui8DataTx[3] = 't';
                /*       
         // UARTSend(UART3_BASE, (uint8_t *)" Sending : ",
     //        strlen(" Sending : "));
    //UARTSend(UART3_BASE, (uint8_t*)ui8DataTx, 4);
               
       
        for(ui32index = 0 ; ui32index < 4 ; ui32index++)
    {
        UARTCharPut(UART3_BASE, ui8DataTx[ui32index]);
    }

    //
    // Wait for the UART module to complete transmitting.
    //
    while(MAP_UARTBusy(UART3_BASE))
    {
    }
               
         // UARTSend(UART3_BASE, (uint8_t *)" Receiving : ",
     //        strlen(" Receiving : "));
    //
    // Read data from the UART's receive FIFO and store it.
    //
   for(ui32index = 0 ; ui32index < 4 ; ui32index++)
    {
        //
        // Get the data received by the UART at its receive FIFO
        //
        ui8DataRx[ui32index] = UARTCharGet(UART3_BASE);
    }
               
*/
       
       

        UARTSend(UART3_BASE, (uint8_t*)ui8DataRx, 4);       
       
       
        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);       
       
        while(1)
        {

        UARTSend(UART3_BASE, (uint8_t *)" UART Loopback Example ->",
            strlen(" UART Loopback Example ->"));
       

                //UARTCharPut(UART3_BASE,ui8DataTx);
                //uartPuts("HELLO EEWORLD: ");   //  Çëêäèëò»¸öÃüá°′»Ø3μÖ′DD
               
        GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x00);///½óêÕμ½êy¾Y£¬ááμÆ
                                SysCtlDelay(500 * (ui32SysClock/ 3000));///Ñóê±3ìDò
        GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0xff);///½óêÕμ½êy¾Y£¬ááμÆ
                                SysCtlDelay(500 * (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++));
    }

}

一周热门 更多>

相关问题

    相关文章