打印结构数组数据导致在Atmega 2560上重新启动

时间:2018-08-31 13:43:23

标签: c++ struct arduino

我有一个定制的PCB,可容纳ATmega2560 MCU。我将Atmel Studio 7用于保险丝并闪烁十六进制。我将Visual Studio与Visual Micro插件结合使用,将C / C ++和Arduino编码结合使用。

我有一个结构体数组定义。

定义:

#define MAX_RECORDS 20 //Max number of records in the struct

typedef struct Record {
    uint8_t id;//unique number to define data sequence
    uint8_t sec;
    uint8_t obj;
    uint16_t xs;
    uint16_t ys;
    uint16_t xe;
    uint16_t ye;
    uint8_t clr;
    uint8_t tsz;
    uint8_t tid;
} tRecord;

struct Record recordsOut[MAX_RECORDS];

这是我将数据打印到串行输出的方式:

void ListDesignData() {
    Serial.println("========================================");
    Serial.println("Design data in non-volatile memory:");
    //int size = sizeof recordsOut / sizeof recordsOut[0];
    //Serial.print("Design Size:");
    //Serial.println(size);
    Serial.println("========================================");
    uint8_t i = 0;
    for (i = 0; i < MAX_RECORDS; i++)
    {
        if (recordsOut[i].id != 255) {
            delay(10);
            Serial.print("id:"); Serial.print(recordsOut[i].id);
            Serial.print(",");
            Serial.print("sec:"); Serial.print(recordsOut[i].sec);
            Serial.print(",");
            Serial.print("obj:"); Serial.print(recordsOut[i].obj);
            Serial.print(",");
            Serial.print("xs:"); Serial.print(recordsOut[i].xs);
            Serial.print(",");
            Serial.print("xe:"); Serial.print(recordsOut[i].xe);
            Serial.print(",");
            Serial.print("ye:"); Serial.print(recordsOut[i].ye);
            Serial.print(",");
            Serial.print("clr:"); Serial.print(recordsOut[i].clr);
            Serial.print(",");
            Serial.print("tsz:"); Serial.print(recordsOut[i].tsz);
            Serial.print(",");
            Serial.print("tid:"); Serial.println(recordsOut[i].tid);
        }
    }
    Serial.print(getPSTR("Old way to force String to Flash"));
    Serial.println(F("Free RAM 3 = ")); //F function does the same and is now a built in library, in IDE > 1.0.0
    Serial.println(freeMemory(), DEC); // print how much RAM is available.

    Serial.println("========================================");
}

所有打印代码运行后,它将导致MCU重新启动。 为了查看内存消耗,我正在使用一个库。但是,它并没有显示出内存不足。 (还是我在错误的时间/地点进行探测?)

这是我在串行监视器上获得的输出:

========================================
Design data in non-volatile memory:
========================================
id:1,sec:1,obj:1,xs:1,xe:157,ye:60,clr:0,tsz:0,tid:0
id:2,sec:1,obj:2,xs:1,xe:158,ye:60,clr:2,tsz:0,tid:0
id:3,sec:1,obj:3,xs:5,xe:0,ye:0,clr:2,tsz:2,tid:1
id:4,sec:2,obj:1,xs:1,xe:158,ye:60,clr:0,tsz:0,tid:0
id:5,sec:2,obj:2,xs:1,xe:158,ye:60,clr:2,tsz:0,tid:0
id:6,sec:2,obj:3,xs:5,xe:0,ye:0,clr:2,tsz:2,tid:1
Old way to force String to FlashFree RAM 3 = 
4882
========================================

编辑:这也是该函数的调用方式:

void loop() {
    serialEvent(); //Listens input from serial 
    ProcessCommands(); //Process received serial commands and call functions accordingly. In our case, the function is ListDesignData().
}

那么,如何找到瓶颈并解决此问题? 任何输入都非常感谢。

0 个答案:

没有答案