Compiling Error with interrupt service routines for ATtiny using xc8 - c

I am working on a project using an ATtiny 202 and I am nearly done with my programming, but I have run into a large problem. I can't create any ISRs, because I always get a compiler error.
I am using the newest version of MPLABX IDE (5.35) (yes it is for pic and avr mcus) and the second newest version of the xc8 compiler (v2.10). I cannot use the newest version of the compiler, because that is for some reason missing the device header for the ATtiny 202. (I had a different thread about that problem a while ago)
I have created the ISRs exactly like described in the XC8 Manual, and the IDE doesn't mark it as a problem either, but when I then try to compile the program I always get a compiler error.
Here is one of my ISRs:
void __interrupt (RTC_PIT_vect_num) pit_int(void){
onPIT(); //Run the function
RTC.PITINTFLAGS = 0x0; //and clear the interrupt flags
}
The IDE marks the RTC_PIT_vect_num blue and correctly recognizes it, as it is defined in the device header.
When I try to compile it, I get this error message, and the build fails:
main.c:864:19: error: expected declaration specifiers or '...' before numeric constant
void __interrupt (RTC_PIT_vect_num) pit_int(void){
^
I dont know what exactly the problem is and how to solve it.
For comparison, here is an example from the "XC8 User Guide for AVR", page 83:
void __interrupt(SPI_STC_vect_num) spi_Isr(void) {
process(SPI_SlaveReceive());
return;
}
As you can see, the structure of the function is exactly the same as in my own ISR.
Does someone have an idea what the problem is or may be and how to fix it?

Fixed:
I had posted this question on the microchip forum as well, as no one here seemed to be able to help.
So I figured out that the problem was that in the project properties under
XC8 Global Options -> XC8 Compiler -> Option categories: Preprocessing and messages
the option "Use CCI Syntax" was disabled. This needs to be enabled for the __interrupt to work.

Related

ISR declaration for LPC2148 in gcc compiler

I am new to gcc compiler and I am trying to compile code for LPC2148 using gcc compiler on mac m1. As per suggestions by some answers, I am using attribute((interrupt("IRQ"))) instead of __irq.
When I am compiling, there is no error and hex file is getting generated. However, the code written in interrupt Service Routine is not at all executing.
Can some one please help me here. I am completely fed up by searching solution for this.
Thankyou :)

MPLAB X IDE / XC32 / SAMD21XPlained Pro / printf() not working

I am using a SAMD21XPlained Pro board on Mac (OS Big Sur) with MPLAB X IDE v6.00 (XC32 compiler) and I am currently experiencing a problem when trying to display a message on my terminal via the printf() function.
I am a beginner in embedded programming and I try to follow this tutorial about STDIO Serial Communications : https://www.youtube.com/watch?v=3pwdpYj5s_A&t=397s
Based on this tutorial I first tried to do only a printf() but I didn't see anything on the terminal (I didn't try the scanf() for this first try).
The only thing I changed is that I included the stdio.h file and I did a second test with a baud rate 9600 (because I don't really know how to define the baud rate and I wanted to test like that).
I have read on several forums that the problem comes from the fact that the XC32 compiler uses by default the UART2 while the printf() must use the UART1 to be displayed on the terminal.
Several people suggest to include xc.h to redefine the default UART1 (__XC_UART = 1) but this seems to work only for PIC32MX µCs.
According to my research in the XC32 compiler files, the xc.h file for PIC32MX is not the same as the one for PIC32/SAM and only the one for PIC32MX defines __XC_UART.
I also tried to apply what is proposed in "Microchip Developer Help" for "Redirect stdout for Use With printf()" in the XC32 category:
https://microchipdeveloper.com/xc32:redirect-stdout
The problem is that it also seems to be only for PIC32MX µCs (the p32xxxx.h file that is included at the beginning of the code exists only for PIC32MX in the XC32 compiler).
After a few days of research, I tried many solutions proposed on different forums but I still can't find the one that works so I was wondering if you have an idea?
Thank you !

XC8 pconfig.h not selecting chip

I am working with XC8 1.20 and a PIC18F66K80 and having some trouble with using the pwm.h library. Whenever I open pwm.h, the only functions that are actually being generated (IE, the #ifdef compile time conditionals are returning true) are for PWM1. After tracing through the code, I came to the pconfig.h file and went down to the section regarding the 18F66K80, and it was all being ignored.
The conditional that was returning false is:
#ifdef __18F66K80
In fact, there were no sections that were being compiled. It was like I had no chip selected, even though the project was targeting the 18F66K80. I went into the compiler macro options and add __18F66K80 as a defined macro, and this block suddenly was compiling, giving me access to PWM2-5.
My question is - what is the correct way to tell pconfig.h what chip I am using? My project settings clearly show the PIC18F66K80 as the target device, but pconfig.h was acting like I had no chosen device. By adding this macro, it appears to work, but I have a feeling this is a hack and not the right way to do things.

How do I implement tone() and noTone() for the Arduino Due?

As it turns out, noTone() and tone() are in the core arduino API, but seemingly not implemented for the Arduino Due. I was hoping to use tone() and noTone() to implement the mario death sound found here, but when I add the code and compile it, I get the following errors:
trenchRun:154: error: 'tone' was not declared in this scope
trenchRun:156: error: 'noTone' was not declared in this scope
In case you're interested, here's an SSCCE, compiled against Arduino 1.5.4 on Mac OS X 10.8:
void setup() {
// put your setup code here, to run once:
}
void loop() {
tone(1, 12345, 1000);
}
sketch_oct24a.ino: In function 'void loop()':
sketch_oct24a:7: error: 'tone' was not declared in this scope
Since I have an Arduino Due, I am limited in using Arduino 1.5.4.
How do I implement the tone() and noTone() functions for the Due?
Yes it seems that it is still disabled in the current version.
A quick search on the Arduino forum got me this : Arduino Due and tone()
I can't test their code but it seems that the guy found a pretty decent solution to make his own tone().
Have a look and tell us if it's working good.
Hope it helps! :)

System calls not working in Atmel AVR Studio (with ASF)

I am not getting answers on the AVR Freaks forum and wonder if someone here could help me.
The answer might lie in this SO question, but I am not sure why it would be necessary.
Basically, I have my fist ever Atmel project (AVR studio 6, UC3 processor). The code compiles and links and I can load it to the Atmel board and step through in the debugger.
However, when I try to step over (or run until a breakpoint on the line after) a (valid) call to sprintf(), malloc() or memcpy() (there may be more, which I have not yet discovered), the IDE never returns to the next line of my code, just seeming to hang, or run forever.
[Note] Compiler optimization is off
Do I need to set some linker options (e.g link static (which I tried & it didn't help)? Or build with some library?
What confuses me is that the code compilers and links - what is being linked when I call these standard functions? If I need something else I would expect a compiler or linker error, but get none - so why won't my code run?
Sorry for such a stupid n00nb question, but it is my first micro-controller project.
I discovered that the CPU on my board is an Engineering Sample and not supported by Atmel Studio without a new io.h file.
I sort of figured that out from this question: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=106652
Sorry to have troubled you.
what is being linked when I call these standard functions?
The AVR-libc, the implementation of the C standard library ported to the AVR platform.
so why won't my code run?
Compiler errors and runtime errors are not even related. Both of these lines are valid C and they compile, however, on most systems, I'd expect them to dump core:
int x = 1 / 0;
*(int *)0 = 41;
So it might be either:
a bug in the standard library (very unlikely), or
a bug in the online debugger (very unlikely), or
maybe you just expect something that is not supposed to happen?
Instead of trying to step over, what happens if you set a breakpoint at next line after the line you want to step over?
Also, does the operation change if you turn off compiler optimization?

Resources