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.

[参考译文] CCS/EK-TM4C123GXL:为什么 sprintf 会使程序和 ADC 崩溃

Guru**** 2478765 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/682732/ccs-ek-tm4c123gxl-why-sprintf-crashing-program-and-adc

器件型号:EK-TM4C123GXL

工具/软件:Code Composer Studio

下午好!

我想知道、如果我使用 comand "sprintf"、我的 ADC 程序为什么会崩溃。 这是在没有 sprintf 的情况下运行我的程序的结果:

和终端:

所以一切看起来都很好。

好的、如果我使用 sprintf、现在是系统:

 我在终端上看不到任何东西。

那么为什么这不起作用呢?

最近帮助的速度非常快、现在可能我找到了解决方案。

(抱歉我的英语、但 这不是我的母语、我只是在学习)

谢谢。

这是代码:

#include
#include
#include
#include
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/adc.h"
#include "driverlib/debug.h"

空 UARTPutString (char* stg);

字符表[10]="0\r";


int main (void){

uint32_t ui32ADC0Value[4];
volatile uint32_t ui32TempAvg;
volatile uint32_t ui32TempValueC;
volatile uint32_t ui32TempValueF;

SysCtlClockSet (SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHz);

SysCtlPeripheralEnable (SYSCTL_Periph_UART0);
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOA);

SysCtlPeripheralEnable (SYSCTL_Periph_ADC0);
ADCHardwareOversampleConfigure (ADC0_BASE、64);
ADCSequenceConfigure (ADC0_BASE、1、ADC_TRIGGER_PROCESSOR、0);
ADCSequenceStepConfigure (ADC0_BASE、1、0、ADC_CTL_TS);
ADCSequenceStepConfigure (ADC0_BASE、1、1、ADC_CTL_TS);
ADCSequenceStepConfigure (ADC0_BASE、1、2、ADC_CTL_TS);
ADCSequenceStepConfigure (ADC0_BASE、1、3、ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable (ADC0_BASE、1);

GPIOPinConfigure (GPIO_PA0_U0RX);
GPIOPinConfigure (GPIO_PA1_U0TX);
GPIOPinTypeUART (GPIO_Porta_base、GPIO_PIN_0 | GPIO_PIN_1);

UARTConfigSetExpClk (UART0_BASE、SysCtlClockGet ()、115200、(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

while (1)

ADCIntClear (ADC0_BASE、1);
ADCProcessorTrigger (ADC0_BASE、1);
while (!ADCIntStatus (ADC0_BASE、1、false))
{}
ADCSequenceDataGet (ADC0_BASE、1、ui32ADC0Value);
ui32TempAvg =(ui32ADC0Value[0]+ ui32ADC0Value[1]+ ui32ADC0Value[2]+ ui32ADC0Value[3]+ 2)/4;
ui32TempValueC =(1475 -(2475 * ui32TempAvg)/ 4096)/10;
ui32TempValueF =((ui32TempValueC * 9)+ 160)/5;


//sprintf (table、"%d "、ui32TempValueC); //------------------------------------ 我改变了这个短跑!!!!!!!!!!!
UARTPutString (table);
SysCtlDelay (2000000);


空 UARTPutString (char* stg)

int i;
int len = 0;
len = strlen (stg);

for (i=0;<len; i++)
UARTCharPut (UART0_BASE、stg[i]);

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    通过说"我的 ADC 程序将崩溃"、您意味着该程序会进入 FaultISR 吗? 如果是、您可能需要查看此 E2E 论坛页面顶部的便签文章第7项中的信息:
    e2e.ti.com/.../374640
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我可以构建、加载和运行。 我没有任何错误。
    我是说、尽管我的程序没有错误、但它不起作用。

    好的、谢谢、我将看到这些信息。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您是否尝试使用 C 步进或断点单步执行代码以查看其失败的位置?
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    我没有听到您的反馈、因此我认为您已经解决了这个问题。 如果没有、请回复此帖子或启动另一个主题。