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.
Hi guys,
I am trying to implement millis() function from Arduino. What it does, it counts number of milliseconds since the program started and returns it.
What I have so far is a Timer A3, sourced from SMCLK in UP mode: Gist. (for some reason, I was unable to insert code directly here).
The problem is, that for some reason, after 5-6 uart messages, the program halts and no other millis() update is sent to the uart.
I don't know, if that is UART problem, or it has something to do with the millis implementation. But I spent two last days looking into it, following tutorials online and nothing helped. Clearly, I need second pair of eyes.
Would you please be so kind to look at the code and point to some parts, which could be wrong? Thank you in advance.
Yes, its volatile, defined on the first line of linked gist.
static volatile uint32_t TIMER_MS_COUNT = 0;
1) This
EUSCI_A_UART_enableInterrupt(EUSCI_A2_BASE, EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT); // void enables UCTXCPTIE, but I don't see an ISR, so as soon as you get a UCTXCPTIFG you will end up in ISR_trap. Just remove this line. (I'm a bit surprised you ran as long as you did, given Erratum USCI42.) 2) I don't see uart_write. I do see something called ss_uart_write. 3) Check your stack size -- CCS's default is usually rather small. sprintf uses maybe 200 bytes of stack, along with texty[200]. |
Ad1) Yes, it was the line enabling interruptions. I used to have an ISR in there, just to set uart_busy flag in uart_write(), but later on I decided to rather wait for UCTXCPTIFG flag. Thank you so much!
ad2) ss_uart_write() should be named uart_write(), its just a relic of me copying and editing the code for the publication.
ad3) According to this thread, stack size should not be limited (except the total stack size). So I have to check current stack pointer and compare it to stack end, to make sure my program does not run out of memory?
3) By "check" I just meant go to "Build Settings->Build->Linker->Basic->Set C Stack Size" and see if that value is even vaguely reasonable. I tossed out (200+200) as a possible estimate; alternatively, just add 200 (for text[]) to whatever's there.
**Attention** This is a public forum