Mysterious serial message

Hey guys,

I made my very first custom PCB using an ATmega328 and the Arduino IDE. Everything works fine so far, except that there is this one message on my serial window (inside the Arduino IDE) which I wonder where it comes from. If anyone of you sees a problem in my first project (a dual motor driver board), I'd really appreciate your help.

First off: Since my main code is a state machine, i wrote a function which makes sure that every serial message is only beeing sent once (to not flood the serial window). So every message gets it's own "ID", and only if there is a new message, it will actually be sent. Also, when the state machine reaches a new state, the array is cleared. This is the code:

void vDebugPrint(unsigned int uiID, String sMessage) {
    static String saMessages[DEBUG_ARRAYSIZE]; // Stores all messages
    static unsigned int uiStateOld = 0;        // Saves the previous state (of the state machine)
    
    if (DEBUG_ENABLE) {
        if (uiID > DEBUG_ARRAYSIZE)  // Prevent buffer overflow
            Serial.println("Error: DEBUG_ARRAYSIZE too small. Debugging disabled!");
        else {
            if (uiStateOld != uiState) { 
                for(int i=0; i<DEBUG_ARRAYSIZE; i++) saMessages[i] = ""; // On state transit, clear the array
            }
            if (saMessages[uiID] != sMessage) { // This is a 'new' message                 
                saMessages[uiID] = sMessage; // Store the message
                Serial.println(sMessage);    // Print the message
                Serial.flush();
            }
        }
     uiStateOld = uiState;   // Save previous state
    }
}

And here comes the mysterious message:

Tightening active...
Right motor reached max. tightening current and brakes!
Left motor reached max. tightening current and brakes!
Both Motors have been tightened!
[color=red]ning active...[/color] (this shouldn't be?!)
Brakes are cool, no retightening required!

To minimize the required parts on my PCB, i activated the internal 8MHz oscillator and removed the USB-to-Serial part of the circuit. Instead I use the Sparkfun FTDI Basic:

This is what my serial circuit looks like:

To make the Arduino IDE work with my 8MHz internal oscillator, I had to add a custom board to it. I started this project with Arduino 1.0.6 and still use this version, because the new version won't accept my custom board file "plug 'n' play" (it uses some kind of boards manager). This is the what my custom bootloader file (arduino\hardware\arduino\bootloaders\optiboot) looks like:

Standard ATmega328, but with internal clock (8MHz)

atmega328_384_8: TARGET = atmega328
atmega328_384_8: MCU_TARGET = atmega328p atmega328_384_8: CFLAGS += '-DLED_START_FLASHES=3'
'-DBAUD_RATE=38400'
atmega328_384_8: AVR_FREQ = 8000000L
atmega328_384_8: LDSECTIONS = -Wl,--section-start=.text=0x7e00
-Wl,--section-start=.version=0x7ffe atmega328_384_8: $(PROGRAM)_atmega328_384_8.hex
atmega328_384_8: $(PROGRAM)_atmega328_384_8.lst atmega328_384_8_isp: atmega328 atmega328_384_8_isp: TARGET = atmega328 atmega328_384_8_isp: MCU_TARGET = atmega328p atmega328_384_8_isp: HFUSE = DE atmega328_384_8_isp: LFUSE = E2 atmega328_384_8_isp: EFUSE = 05 atmega328_384_8_isp: isp

And of course I had to add this new bootloader to the Arduino IDE (arduino\hardware\arduino\boards.txt):

atmega328_384_8.name=ATmega328 with 8MHz clock at 38400 baud atmega328_384_8.upload.protocol=arduino atmega328_384_8.upload.maximum_size=30720 atmega328_384_8.upload.speed=38400 atmega328_384_8.bootloader.low_fuses=0xE2 atmega328_384_8.bootloader.high_fuses=0xDE atmega328_384_8.bootloader.extended_fuses=0x05 atmega328_384_8.bootloader.path=optiboot atmega328_384_8.bootloader.file=optiboot_atmega328_384_8.hex atmega328_384_8.bootloader.unlock_bits=0x3F atmega328_384_8.bootloader.lock_bits=0x0F atmega328_384_8.build.mcu=atmega328p atmega328_384_8.build.f_cpu=8000000L atmega328_384_8.build.core=arduino atmega328_384_8.build.variant=standard

Ok, I think this is everything regarding the serial communication. Do you see any mistake I could have made? (And thanks for reading!! ;D )

Your code snippet has a bug.

        if (uiID > DEBUG_ARRAYSIZE)  // Prevent buffer overflow

This does not prevent buffer overflow. It needs to be >=

Using the String class can also mysterious output and/or crashes because the 328 only has 2kB of sram. You'd be better off to change it so that it uses C-style null-terminated strings.

Pete