4368|5

5

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

TM4C129en USRT0 发送数据 [复制链接]

使用TM4C129en MCU,在主循环(while())中 使用USRT0 发送数据,为什么只发送一次,而不是循环发送。每重启一次发送一次,发送的也是对的。
不知道我哪里设置错了。软件调试感觉是执行过了。就是没有数据接收到。
那位高手给指点指点!

最新回复

看看具体的设置情况,串口初始化中,有没有使能发送中断。最好不要使能。看看程序卡在了什么地方。  详情 回复 发表于 2015-12-27 21:31
 
点赞 关注

回复
举报

5

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
代码如下:
 
 

回复

5

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
//*****************************************************************************
//
// uart_polled.c - Example demonstrating UART polled I/O.
//
// Copyright (c) 2010-2015 Texas Instruments Incorporated.  All rights reserved.
// Software License Agreement
//
//   Redistribution and use in source and binary forms, with or without
//   modification, are permitted provided that the following conditions
//   are met:
//
//   Redistributions of source code must retain the above copyright
//   notice, this list of conditions and the following disclaimer.
//
//   Redistributions in binary form must reproduce the above copyright
//   notice, this list of conditions and the following disclaimer in the
//   documentation and/or other materials provided with the  
//   distribution.
//
//   Neither the name of Texas Instruments Incorporated nor the names of
//   its contributors may be used to endorse or promote products derived
//   from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// This is part of revision 2.1.1.71 of the Tiva Firmware Development Package.
//
//*****************************************************************************

#include
#include
#include
#include "hw_memmap.h"
#include "hw_ints.h"
#include "hw_gpio.h"
#include "gpio.h"
#include "pin_map.h"
#include "sysctl.h"
#include "uart.h"
#include "ssi.h"
#include "interrupt.h"
#include "SSIControl.h"
#include "timer.h"
#include "sysctl.h"

//*****************************************************************************
//
//! \addtogroup uart_examples_list
//!

UART Polled I/O (uart_polled)


//!
//! This example shows how to set up the UART and use polled I/O methods
//! for transmitting and receiving UART data.  The example receives characters
//! from UART0 and retransmits the same character using UART0.  It can be
//! tested by using a serial terminal program on a host computer.  This
//! example will echo every character that is type until the return/enter key
//! is pressed.
//!
//! This example uses the following peripherals and I/O signals.  You must
//! review these and change as needed for your own board:
//! - UART0 peripheral
//! - GPIO Port A peripheral (for UART0 pins)
//! - UART0RX - PA0
//! - UART0TX - PA1
//
//*****************************************************************************
#if defined(TARGET_IS_TM4C129_RA0) ||                                         \
                defined(TARGET_IS_TM4C129_RA1) ||                                         \
    defined(TARGET_IS_TM4C129_RA2)
uint32_t ui32SysClock;
#endif
//uint32_t ADC_Data[2];
//uint32_t test_Data[2];
//uint32_t DAC_Data[2];
//float voltage0[2];
//float voltage1[2];
const uint32_t ADarry_ch0_Len=12;
const uint32_t ADarry_ch1_Len=12;
       
uint32_t ADC_Data_ch0[4];
uint32_t ADC_Data_ch1[4];

uint32_t test_Data[4];
uint32_t DAC_Data;
float vol_get_ch0[1];
float vol_get_ch1[1];
uint32_t Fix_ADC_Data_ch0;
uint32_t Fix_ADC_Data_ch1;
uint32_t getad_chanel_0[ADarry_ch0_Len];
uint32_t getad_chanel_1[ADarry_ch1_Len];
uint32_t setad_st1[ADarry_ch1_Len];
uint32_t setad_st2[ADarry_ch1_Len];

uint32_t send_AD_val;
//uint32_t i;
uint32_t temp_AD_ch0;
uint32_t temp_AD_ch1;
float cmpflval[2];
uint8_t Dev_Adj_State;
uint32_t adj_count_st1;

uint32_t keepnum;
uint32_t loopnum;
uint32_t Ch1_overnum;
uint32_t Ch1_zerornum;
uint32_t outrange_num;       

uint32_t rangeok;
uint32_t st_1_outrange;

uint32_t fill_num_st1;
uint32_t fill_num_sum;
uint32_t fouse_set_DA;

uint8_t usart_send_data_state[15];




//void Data_AD2DA(uint32_t *ADC_Data, uint32_t *DAC_Data);
//void  inttofloat(float *valfloat, uint32_t *hexDataval);
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
    uint32_t ui32Status;

    //
    // Get the interrrupt status.
    //
    ui32Status = UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    UARTIntClear(UART0_BASE, ui32Status);

    //
    // Loop while there are characters in the receive FIFO.
    //
    while(UARTCharsAvail(UART0_BASE))
    {
        //
        // Read the next character from the UART and write it back to the UART.
        //
       UARTCharPutNonBlocking(UART0_BASE,
                                   UARTCharGetNonBlocking(UART0_BASE));
    }
}

//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void
UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
    //
    // Loop while there are more characters to send.
    //
    while(ui32Count--)
    {
        //
        // Write the next character to the UART.
        //
        UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++);
                        //UARTCharPut(UART0_BASE, *pui8Buffer++);
    }
}

void
UARTSend_arry_data(const uint8_t pui8Buffer[], uint32_t ui32Count)
{
                uint32_t loopnum_si;
       
                uint32_t ui32Status;

    //
    // Get the interrrupt status.
    //
    ui32Status = UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    UARTIntClear(UART0_BASE, ui32Status);
   
                for(loopnum_si=0;loopnum_si     {
      // UARTCharPutNonBlocking(UART0_BASE, pui8Buffer[loopnum_si]);
                        UARTCharPut(UART0_BASE,  pui8Buffer[loopnum_si]);
    }
}

//*****************************************************************************
//
// The interrupt handler for the Timer0B interrupt.
//
//*****************************************************************************
void
Timer0BIntHandler(void)
{
    //
    // Clear the timer interrupt flag.
    //
    TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT);

    //
    // Update the periodic interrupt counter.
    //
   // g_ui32Counter++;
       
}

void Timer0Init(uint32_t Nms)
{
#if defined(TARGET_IS_TM4C129_RA0) ||                                         \
        defined(TARGET_IS_TM4C129_RA1) ||                                         \
    defined(TARGET_IS_TM4C129_RA2)
        uint32_t ui32SysClock;
#endif
       
          //
    // The Timer0 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
       
          //
    // Configure Timer0B as a 16-bit periodic timer.
    //
    TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC);
       
          //
    // Set the Timer0B load value to 1ms.
    //
#if defined(TARGET_IS_TM4C129_RA0) ||                                         \
          defined(TARGET_IS_TM4C129_RA1) ||                                         \
    defined(TARGET_IS_TM4C129_RA2)
    TimerLoadSet(TIMER0_BASE, TIMER_B, ui32SysClock / 1000);
#else
    TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / 1000);
#endif
       
          //
    // Configure the Timer0B interrupt for timer timeout.
    //
    TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);

    //
    // Enable the Timer0B interrupt on the processor (NVIC).
    //
    IntEnable(INT_TIMER0B);
       
          //
    // Enable Timer0B.
    //
    TimerEnable(TIMER0_BASE, TIMER_B);
}




int
main(void)
{

usart_send_data_state[0]=0xEB;//frame head
usart_send_data_state[1]=0x01;//frame data type
usart_send_data_state[2]=0x00;//..device region
usart_send_data_state[3]=0x00;//..device code
usart_send_data_state[4]=0x01;//..data send reason
usart_send_data_state[5]=0x00;//..device state       
usart_send_data_state[6]=0x00;//..DA0 height
usart_send_data_state[7]=0x00;//..DA0 low
usart_send_data_state[8]=0x00;//..DA1 height
usart_send_data_state[9]=0x00;//..DA1 low
usart_send_data_state[10]=0x00;//..AD0 height
usart_send_data_state[11]=0x00;//..DA0 low
usart_send_data_state[12]=0x00;//parite height
usart_send_data_state[13]=0x00;//parite low
usart_send_data_state[14]=0xAA;//frame end

       
/*
#if defined(TARGET_IS_TM4C129_RA0) ||                                         \
        defined(TARGET_IS_TM4C129_RA1) ||                                         \
    defined(TARGET_IS_TM4C129_RA2)
        uint32_t ui32SysClock;
#endif
*/
    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
#if defined(TARGET_IS_TM4C129_RA0) ||                                         \
        defined(TARGET_IS_TM4C12ru9_RA1) ||                                         \
    defined(TARGET_IS_TM4C129ru_RA2)
    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                        SYSCTL_OSC_MAIN |
                                       SYSCTL_USE_OSC), 25000000);
#else
     //SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
     //               SYSCTL_XTAL_16MHZ);
               
     SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |  
                    SYSCTL_XTAL_25MHZ);

#endif

/////////////////uart init/////////////////////////////
#if  1
    //ru
    // Enruable the peripherals used by this example.
    // The UruART itself needs to be enabled, as well as the GPIO port
    // containirung the pins that will be used.
    //
     SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

     //
     // Configure the GPIO pin muxing for the UART function.
    //ru This is only necessary if your part supports GPIO pin function muxing.
    // Struudy the data sheet to see which functions are allocated per pin.
    // TODO:ru change this to select the port/pin you are using
    //
     GPIOPinConfigure(GPIO_PA0_U0RX);
     GPIOPinConfigure(GPIO_PA1_U0TX);

     //
     // Since GPIO A0 and A1 are used for the UART function, they must be
    //ru configured for use as a peripheral function (instead of GPIO).
    // TOruDO: change this to match the port/pin you are using
    //
     GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //ru This function uses SysCtlClockGet() or ui32SysClock to get the system clock
    // frruequency.  This could be also be a variable or hard coded value
    // insteruad of a function call.
    //
#if defined(TARGET_IS_TM4C129_RA0) ||                                         \
        defined(TARGET_IS_TM4C129_RA1) ||                                         \
    defined(TARGET_IS_TM4C129_RA2)
    UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200,
                       (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
#else
                UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                        UART_CONFIG_PAR_NONE));
#endif
               
    //IntEnable(INT_UART0);
    //ruUARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
#endif
/////////////////uart init end/////////////////////////////
                UARTFlowControlSet(UART0_BASE,UART_FLOWCONTROL_NONE);
                UARTFIFODisable();
                UARTEnable(UART0_BASE);
          IntEnable(INT_UART0); //??UART1??
//    UARTIntEnable(UART0_BASE, UART_INT_RX );
//                UARTIntEnable(UART0_BASE, UART_INT_TX);
               
        //        UARTSend((uint8_t *)"ssi test...\r\n", 16);
                //////ru/////////////////////////////////////////////////////
    //spi inirut
    ////////////ru//////////////////////////////////////////////
    SSIConfigure(SSI2,1000000, SSI_FRF_MOTO_MODE_0, SSI2_DATA_WIDTH);
                SSIConfigure(SSI3, 1000000, SSI_FRF_MOTO_MODE_1, SSI3_DATA_WIDTH);
               
                ///////////////////////////////////////////////////////////
    //GPIO init
    //ru////////////////////////////////////////////////////////
                //GPIruO config (use TS12A4515 control)
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

     *(uint32_t *)(GPIO_PORTA_BASE + GPIO_O_LOCK) = 0x4C4F434B;
     *(uint32_t *)(GPIO_PORTA_BASE + GPIO_O_CR) = 0xFF;

     //set PA dir
    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3);
               
                //GPIO[PQ] config (use DAC8551 cs)
                SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);

    *(uint32_t *)(GPIO_PORTQ_BASE + GPIO_O_LOCK) = 0x4C4F434B;
    *(uint32_t *)(GPIO_PORTQ_BASE + GPIO_O_CR) = 0xFF;

    //set PQ dir
    GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_1);
               
                //Timer0Init(1);
               
                IntMasterEnable();
               
                //
    // Prompt for text to be entered.
    //
    //UARTSend((uint8_t *)"\033[2JEnter text: ", 16);
               
                SSIRev_ADS_7950(ADC_Data_ch0, 0);
                SysCtlDelay(1000000);
                SSIRev_ADS_7950(ADC_Data_ch1, 1);
               
                //DAC SSI cs
                GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_1, 1);
                // LOW ON; HIGH OFF
                GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3, 0);
               
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
                GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);
               
                Dev_Adj_State=0;
               
                while(1)
                {                       
                       
                        led_state_on();
                        SysCtlDelay(1000000);
         
               

                       
//ROM_UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT);
//ROM_UARTIntEnable(UART2_BASE, UART_INT_TX);

//ROM_UARTIntDisable(UART2_BASE, UART_INT_RX | UART_INT_RT);
//ROM_UARTIntDisable(UART2_BASE, UART_INT_TX);
//                        UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
//                        UARTIntEnable(UART0_BASE, UART_INT_TX);

        //                UARTIntDisable(UART0_BASE, UART_INT_RX | UART_INT_RT);
                //        UARTIntDisable(UART0_BASE, UART_INT_RX|UART_INT_TX);
//                        UARTDisable(UART0_BASE);
//                SysCtlDelay(10000);
//                UARTEnable(UART0_BASE);
//                SysCtlDelay(10000);
//                while(!UARTCharsAvail(UART0_BASE))
//                {}
//                while(UARTCharGetNonBlocking(UART0_BASE))
//                {}

                        //UARTEnable(UART0_BASE);       
                        UARTSend_arry_data(usart_send_data_state, 15);
                       
                        //UARTSend((uint8_t *)"usart0 test...\r\n", 16);       
                        SysCtlDelay(1000000);
               
//                        UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
//                        UARTIntEnable(UART0_BASE, UART_INT_RX);

//                        UARTIntDisable(UART0_BASE, UART_INT_RX | UART_INT_RT);
//                        UARTIntDisable(UART0_BASE, UART_INT_TX);
                                                       
                       
                        led_state_off();       
                }               
               
               
}



 
 
 

回复

5

帖子

0

TA的资源

一粒金砂(初级)

4
 
注释过的语句都是试验过的,不行。
 
 
 

回复

5

帖子

0

TA的资源

一粒金砂(初级)

5
 
能看到电路板上的指示灯在闪烁。
就是没报文发出来。
 
 
 

回复

3471

帖子

13

TA的资源

五彩晶圆(高级)

6
 
看看具体的设置情况,串口初始化中,有没有使能发送中断。最好不要使能。看看程序卡在了什么地方。
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
有奖直播:当AI遇见仿真,会有什么样的电子行业革新之路?
首场直播:Simcenter AI 赋能电子行业研发创新
直播时间:04月15日14:00-14:50

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网 12

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表