I'm using a Atmega32u4 in my own project, but i flashed the Sparkfun Pro Micro (3.3V,8Mhz) bootloader, its similar to the Leonardo, but they removed the 8 second wait.
The most part of the code works without problems and for long cycles. But if i push a button, the USB just stops working, and disappiers from Windows "Device-Manager" as if you would pull the USB Cable.
-> Tried to swap the button, and then the pin, to make sure its not a Hardware Issue
-> Still not worked.
So i added debut texts for Serial.
This is happening.
Hold button for a specific time and then release
Release event will trigger a function "log_prepare()";
Function works, since "Prepare!" and "done!" gets printed
After Preparation the function that does something should run and wait for events. This works a small time. The function Runs exactly 951 times by printing "Service Cycle Nr. " 0 to 951. In the last run only "Service Cycl" gets printed. Thats where the USB-Port disappears.
-> When the Service Cycle is running, it doesnt matter if there are events, or button-pusheds, the port gets removed anyway.
Find attached my code, maybe someone can help. Sorry, i know the code is a mess, but i'm developing. Sorry for missing libraries...
I hope someone could help me with this, I'm really stuck here...
2.) The problem is not about "case : 1", i found out that it still not works, and the "Cycle" runs not always exactly the same time
3.) Find attached the zip with libraries. I have worked since i posted this topic, so this code differs from the first one i posted, but this has to do nothing with the issue
the sketch uses 26443 of 28672 (92%) program space
and it says 963 bytes of dynamic memory.
The function that causes trouble starts on LINE 632
Oh sorry, the first .ino i posted, the line would be 483!!
on the later .zip file with libraries its line 632 the function "m2_service()" starts, thats the function that causes the problem, since the serial Print "Service Cycle Nr:" gets executed a few times before bricking.
For trying i removed the switch's case 1 (line 645) content, but this DID NOT solve the problem
About DOG.string. I use this in other parts of the code way much and faster - no problem.
Here is the fucntion from the library that executes DOG.String
void dog_7565R::string(byte column, byte page, const byte *font_adress, const char *str)
{
unsigned int pos_array; //Postion of character data in memory array
byte x, y, column_cnt, width_max; //temporary column and page adress, couloumn_cnt tand width_max are used to stay inside display area
byte start_code, last_code, width, page_height, bytes_p_char; //font information, needed for calculation
const char *string;
start_code = pgm_read_byte(&font_adress[2]); //get first defined character
last_code = pgm_read_byte(&font_adress[3]); //get last defined character
width = pgm_read_byte(&font_adress[4]); //width in pixel of one char
page_height = pgm_read_byte(&font_adress[6]); //page count per char
bytes_p_char = pgm_read_byte(&font_adress[7]); //bytes per char
if(type != DOGM132 && page_height + page > 8) //stay inside display area
page_height = 8 - page;
else if(type == DOGM132 && page_height + page > 4)
page_height = 4 - page;
//The string is displayed character after character. If the font has more then one page,
//the top page is printed first, then the next page and so on
for(y = 0; y < page_height; y++)
{
position(column, page+y); //set startpositon and page
column_cnt = column; //store column for display last column check
string = str; //temporary pointer to the beginning of the string to print
digitalWrite(p_a0, HIGH);
digitalWrite(p_cs, LOW);
while(*string != 0)
{
if((byte)*string < start_code || (byte)*string > last_code) //make sure data is valid
string++;
else
{
//calculate positon of ascii character in font array
//bytes for header + (ascii - startcode) * bytes per char)
pos_array = 8 + (unsigned int)(*string++ - start_code) * bytes_p_char;
pos_array += y*width; //get the dot pattern for the part of the char to print
if(type != DOGM132 && column_cnt + width > 128) //stay inside display area
width_max = 128-column_cnt;
else if(type == DOGM132 && column_cnt + width > 132)
width_max = 132-column_cnt;
else
width_max = width;
for(x=0; x < width_max; x++) //print the whole string
{
spi_out(pgm_read_byte(&font_adress[pos_array+x]));
//spi_out(pgm_read_byte(&font_adress[pos_array+x])); //double width font (bold)
}
}
}
digitalWrite(p_cs, HIGH);
}
}
it looks like the gps gets a new message each Second. So if we looks at the Status, the next message should be arrive at around "16220" right?
So i added to my m2_service(), a Serial.print with Service run + millis().
Like i guessed, the code stops exactly at 16220...
Service run16218
Service run16218
Service run16220
Service run
Its very interesting, that the code even breaks when there is no SERIAL Stuff in the Service...
I removed all Serial.print() from the Service and its pre-functions, but still it breaks
Interesting fact is, that when i use //GPSLoop() or //m2_service(), so they can not run, it works perfectly when one of them is disabled.
Very weird.
I also added a function to the display to see the ram even if the serial port is gone, and its always around 1400, it never breaks down alot...