搜索
bottom↓
回复: 4

串口转以太网通讯代码及问题

[复制链接]

出0入0汤圆

发表于 2010-6-30 10:41:47 | 显示全部楼层 |阅读模式
我用LM3S6432芯片,解决以下问题:
1.串口收数并处理,然后通过网口传输出去。
2.网口收数处理,然后从串口发出。
遇到的问题: 程序代码不知如何发到帖子上,以下代码为主函数代码,不知在哪里添加处理接收到的数据,并将其发送出去,请高人指点?我的联系方式:qq:22369427,多谢,有要代码的可以找我。

int main(void)
{
    unsigned long ulUser0, ulUser1;
    unsigned char pucMACAddr[8];
    unsigned long ulLoop;

    //
    // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    // a workaround to allow the PLL to operate reliably.
    //
    if(REVISION_IS_A2)
    {
        SysCtlLDOSet(SYSCTL_LDO_2_75V);
    }

    //
    // Set the processor to run at 50 MHz, allowing UART operation at up to
    // 3.125 MHz.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    //
    // Enable the peripherals used by the application.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);

    //
    // Enable the peripherals that should continue to run when the processor
    // is sleeping.
    //
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_ETH);

    //
    // Enable peripheral clock gating.  Note that this is required in order to
    // measure the the processor usage.
    //
    SysCtlPeripheralClockGating(true);

    //
    // Set the priorities of the interrupts used by the application.
    //
    IntPrioritySet(INT_UART0, 0x00);
    IntPrioritySet(INT_UART1, 0x00);
    IntPrioritySet(INT_ETH, 0x20);
    IntPrioritySet(FAULT_SYSTICK, 0x40);

    //
    // Configure SysTick for a periodic interrupt.
    //
    SysTickPeriodSet(SysCtlClockGet() / SYSTICKHZ);
    SysTickEnable();
    SysTickIntEnable();

    //
    // Enable Port F for Ethernet LEDs.
    //  LED0        Bit 3   Output
    //  LED1        Bit 2   Output
    //
    GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_DIR_MODE_HW);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3,
                     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);

    //
    // Set the link status based on the LED0 signal (which defaults to link
    // status in the PHY).
    //
    g_bLinkStatusUp = GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_3) ? false : true;

    //
    // Initialize the configuration parameter module.
    //
    ConfigInit();

    //
    // Get the MAC address from the UART0 and UART1 registers in NV ram.
    //
    FlashUserGet(&ulUser0, &ulUser1);

    //
    // Convert the 24/24 split MAC address from NV ram into a MAC address
    // array.
    //
    pucMACAddr[0] = ulUser0 & 0xff;
    pucMACAddr[1] = (ulUser0 >> 8) & 0xff;
    pucMACAddr[2] = (ulUser0 >> 16) & 0xff;
    pucMACAddr[3] = ulUser1 & 0xff;
    pucMACAddr[4] = (ulUser1 >> 8) & 0xff;
    pucMACAddr[5] = (ulUser1 >> 16) & 0xff;

    //
    // Initialize the lwIP TCP/IP stack.
    //
    lwIPInit(pucMACAddr, g_sParameters.ulStaticIP, g_sParameters.ulSubnetMask,
             g_sParameters.ulGatewayIP, ((g_sParameters.ucFlags &
             CONFIG_FLAG_STATICIP) ? IPADDR_USE_STATIC : IPADDR_USE_DHCP));

    //
    // Setup the device locator service.
    //
    LocatorInit();
    LocatorMACAddrSet(pucMACAddr);
    LocatorAppTitleSet((char *)g_sParameters.ucModName);

    //
    // Initialize the serial port module.
    //
    SerialInit();

    //
    // Initialize the telnet module.
    //
    TelnetInit();

    //
    // Initialize the UPnP session.
    //
    UPnPInit();

    //
    // Initialize the HTTPD web server.
    //
    httpd_init();

    //
    // Configure SSI and CGI processing for our configuration web forms.
    //
    ConfigWebInit();

    //
    // Start the remote software update module.
    //
    SoftwareUpdateInit(SoftwareUpdateRequestCallback);

    //
    // Wait for an IP address to be assigned to the board before we try to
    // initiate any connections.
    //
    while(!lwIPLocalIPAddrGet())
    {
        //
        // Do nothing until we get our IP address assigned.
        //
        SysCtlSleep();
    }

    //
    // Initialize the telnet session(s).
    //
    for(ulLoop = 0; ulLoop < MAX_S2E_PORTS; ulLoop++)
    {
        //
        // Are we to operate as a telnet server?
        //
        if((g_sParameters.sPort[ulLoop].ucFlags & PORT_FLAG_TELNET_MODE) ==
           PORT_TELNET_SERVER)
        {
            //
            // Yes - start listening on the required port.
            //
            TelnetListen(g_sParameters.sPort[ulLoop].usTelnetLocalPort,
                         ulLoop);
        }
        else
        {
            //
            // No - we are a client so initiate a connection to the desired
            // IP address using the configured ports.
            //
            TelnetOpen(g_sParameters.sPort[ulLoop].ulTelnetIPAddr,
                       g_sParameters.sPort[ulLoop].usTelnetRemotePort,
                       g_sParameters.sPort[ulLoop].usTelnetLocalPort, ulLoop);
        }
    }

    //
    // Main Application Loop (for systems with no RTOS).  Run every SYSTICK.
    //
    while(true)
    {
        //
        // Wait for an event to occur.
        //
        SysCtlSleep();

        //
        // Check for an IP update request.
        //
        if(g_bChangeIPAddress == true)
        {
            //
            // Delay 2 seconds or so to allow the response page to get back
            // to the browser before we initiate the IP address change.
            //
            SysCtlDelay((SysCtlClockGet() / 3) * 2);

            //
            // Actually update the IP address.
            //
            g_bChangeIPAddress = false;
            ConfigUpdateIPAddress();
        }

        //
        // Check for bootloader request.
        //
        if((g_bStartBootloader == true) || (g_bFirmwareUpdate == true))
        {
            //
            // Delay a couple of seconds to let any pending web server
            // transmission to complete.  Each loop within SysCtlDelay is
            // 3 instructions long so this delays approximately 2 seconds.
            //
            SysCtlDelay((SysCtlClockGet() / 3) * 2);

            //
            // Initiate the Software Update Process in the Ethernet
            // Bootloader.
            //
            SoftwareUpdateBegin();

            //
            // Should never get here, but stall just in case.
            //
            while(1)
            {
            }
        }
    }
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入0汤圆

发表于 2010-7-20 21:47:12 | 显示全部楼层
MARK

出0入0汤圆

发表于 2010-8-5 19:29:56 | 显示全部楼层
回复【楼主位】victorzifeng
-----------------------------------------------------------------------

楼主调试的怎么样了,我也在研究这个,加qq 526784250,一起交流

出0入0汤圆

发表于 2013-6-2 22:06:12 | 显示全部楼层
怎么只是代码有没有电路?

出0入0汤圆

发表于 2013-6-12 21:38:19 | 显示全部楼层
不用那么麻烦吧,有一个芯片,是IP210W,可以直接接UART,再直接接网络变压器,联上网络。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-25 13:12

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表