# timer crash on enable

Status
Not open for further replies.

#### Dr_Doggy

##### Well-Known Member
so a bit of history is that i use to not bother with strings cos i knew they were somehow bad, but for this project i had a logbuffer that could sometimes get extremely long and decided to string it.. but after about 12 hrs the fragmens caught up and crashed the atmega2560

so i ran this code to see if i could look in to the mem banks ... there was alot of blocks like this in it.....
Code:
char *p =0;
while (1){Serial.print(p++);}

dogg-house
ogg-house
gg-house
g-house
-house
house
ouse
use
se
e
superyumyum
uperyumyum
peryumyum
eryumyum
ryumyum
yumyum
umyum
myum
yum
um
m
Question #1!! ) is the above result the fragment problem they are talking about or is that my improper use of using a pointer!!?

so i decided to send the strings all to char arrays... conversions went smooth but i made one mistake where i used the ltoa functions very improperly.. but i got all the bugs sorted and this is where i noticed a bigger problem.

so i have been rolling back my code and had to bring it down to this... my problem is that TIMSK3 instructions is locking up arduino, it never makes it to the breakpoint = 1, it never calls the interrupt anymore, and never even makes it to main loop. when i comment that one line out i am able to make it to main loop.
I started off with timer1 and also everything was working before I started messing with the char arrays

could i have messed up a mem block? wouldnt a new upload fix that (also i tried burning new bootloader)?
could this be a HW issue that just so happened when i started messing with pointers?
... something else??:
Code:
#include <Arduino.h>

ISR(TIMER3_OVF_vect)
{
int xxx = 1;
}

void setupTimer1()
{

TCCR3B |= (1 << CS10);    // set up timer with prescaler
TCCR3B |= (1 << CS11);    // set up timer with prescaler
TCNT3 = 0;    // initialize counter
TIFR3 = 0;

int breakpoint = 0;
TIMSK3 |= (1 << TOIE3);    // enable overflow interrupt
breakpoint = 1;
sei();    // enable global interrupts
breakpoint = 2;
}

void setup()
{
setupTimer1();
}

void loop()
{
while (1)
{
int xxx = 1;
}
}

#### dknguyen

##### Well-Known Member
Is SetupTimer1() supposed to be working with ISR(TIMER3_OVF_vect)?

Also, isn't this setting a null adress?
char *p =0;

#### Dr_Doggy

##### Well-Known Member
yes the code above is all actually timer 3 ... it was all timer 1 at the begining ... the setuptimer1 call is just to call the setup vectors (which are for timer3!)

ALSO.. idk that was my first pointer! hope that wasnt self destruct!! .... it seemed to work though as it was dumping stuff!
i have removed that since then ... could that do long term damage?

Last edited:

#### Pommie

##### Well-Known Member
What are you trying to do? In my experience you shouldn't access the hardware direct on the Arduino as the operating system (said loosely) uses most of it. If you need a timed interrupt then look at using Ticker.h.

The serial print of the pointer will print everything up to a carriage return. So your memory contains
dogg-house<cr>superyumyum<cr> etc.

I avoid using the string class as it's reported as having memory leaks. I've always managed with simple C strings.

Mike.

Last edited:

#### Dr_Doggy

##### Well-Known Member
I am trying to get the timer function working again... the strange thing is that code above worked till I started messing around with the char arrays... now iv deleted everything but timer still is no go
thanks will try ticker tomorow!

#### Pommie

##### Well-Known Member
I've just realized that the Ticker I'm using is specific to the ESP processors. There does however seem to be similar for UNO etc. but doesn't appear to be interrupt driven.

Mike.

#### Pommie

##### Well-Known Member
Here's a simple example that works on ESP boards.
Code:
#include <Ticker.h>
Ticker IRQ;

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
IRQ.attach_ms(500,ISR);
}

void ISR(void){
}

void loop(){
}
It flashes the on board LED at 1Hz. As you can see it's very simple.

Mike.

#### Dr_Doggy

##### Well-Known Member
omg .. . it was having a breakpoint in the isr that was causing the problem!

#### Pommie

##### Well-Known Member
Breakpoint.... Breakpoint - on an Arduino. Time to do some research.

Mike.

#### Dr_Doggy

##### Well-Known Member
oh..ya.. i use the visual micro plugin for visual studio, cuts down on the compilers i need ... . not really a true breakpoint but an interesting way to implement a virtual one...

#### Pommie

##### Well-Known Member
Does that plugin work with the free version of VS?

Googling suggests that on the ESP you can have real breakpoints. I like these chips - 80k ram 4M flash and 80MHz speed and about \$4 each.

Mike.

#### Dr_Doggy

##### Well-Known Member
i got vs pro 2013 .. not sure if mines free or not, but it should work
check it out!:
https://www.visualmicro.com/

also do you got a link for the ESP , i wouldnt mind checking it out .. i like the mega2560 cos it has lots of headers and for this project i have them half filled up already but only 10%program memory full

#### Dr_Doggy

##### Well-Known Member
wait .. im confused i have a ESP8266 serial wifi module sitting in front of me i thought it was just a wifi module are you saying that i can program it without destroying the wifi stack?? or maybe mine is different from that?

also since were on the topic.. are you able to send outgoing requests with it? ... that is one thing i was never able to get working on the mt7681

#### Pommie

##### Well-Known Member
The Wemos and Lolin boards have 4M of flash on board and a USB to RS232 converter. Schematic. I'm assuming the flash is used to hold the external program.

I currently have a wemos mini board setup as a server. It is configured with a 3M spiffs drive and 1M program space. This can act as an access point, connect to wifi, serve up html pages, read a DHT22. The html pages can use GET and POST to read/store files and fetch the DHT data. The 1M program space is about half full.

I have a second wemos board driving a 32x8 LED display using MAX7219s and that connects to my wifi, fetches the IP address of time servers and then gets the time. Is this what you meant by outgoing requests?

Mike.

#### Dr_Doggy

##### Well-Known Member
ya GET request,,, thats great!

Status
Not open for further replies.