When calling the function "shiftOutByte" outside of an assembler block it is recognized correctly + compiles but when called from inside an assembler block it is not recognized + I get an error message:
In function nrf24_writeRegs': ..Arduino\libraries\nRF24L01_t13-main/nRF24L01.c:369: undefined reference to shiftOutByte'
Where is the shiftOutByte function located? You are using an RCALL instruction, which is a relative call, and implies a short distance. Try using CALL instead. But, without further knowledge of your code, it’s hard to say.
Furthermore, the C Compiler always passes function arguments and returns values in specific register locations. Knowing these locations are essential to writing efficient inline assembly code, especially when interfacing with the C language. An 8-bit, byte-sized value is passed to and from a function via the r24 register. What are you doing with r22?
This function is on purpose not defined in the nRF24L01.h header file, as it is not general usable but only in a limited context.
Anyway I've tried to add it to the header file and also that is not working.
I've also tried to add an "extern" statement to it and also that is not working.
The simple sketch below is reproducing the problem:
#define F_CPU 1200000UL //ONLY used if fuse was set to lower internal frequency
#include <avr/io.h>
#include <util/delay.h>
#include "projdefs.h"
#include <nRF24L01.h>
void setup() {
}
void loop() {
}
The function is multiple times. When called inside an assembler block it is not found.
When called outside an assembler block it is found.
Any suggestions how to change the library code?
This library uses assembler to reduce the footprint of the code, and that is exactly why I'm using it. It's intended for an ATTINY13 with 1K of ram only.
Converting to C will likely blow up that footprint
presumably shiftOutByte() is defined in C++ code (.cpp or .ino file), and is therefore "name mangled" into a symbol that reflects the full function signature (including argument types.) Try prototyping it like:
The ATtiny13 does no have "call", everything is reachable via "rcall."
The nRF24 library being used is C, not C++, so my comments about "extern "C"" are irrelevant.
Sigh. Could you please provide a full compilable program (and compile instructions, including which core you're using?
(Never mind. I put one together myself.)
Turn off "link time optimization" - it's a board option if you're using ATTinyCore.
With LTO enabled, the compile step produces some sort of weird lightly-processed code, and that apparently doesn't include the ability to resolve symbols within inline assembly.
sketch\ATTINY_nrf24L01_Sensor.ino.cpp.o: In function nrf24_writeReg(unsigned char, unsigned char)': C:\Users\Nout\Documents\Arduino\ATTINY_nrf24L01_Sensor/ATTINY_nrf24L01_Sensor.ino:470: undefined reference to shiftOutByte'
C:\Users\Nout\Documents\Arduino\ATTINY_nrf24L01_Sensor/ATTINY_nrf24L01_Sensor.ino:470: undefined reference to shiftOutByte' sketch\ATTINY_nrf24L01_Sensor.ino.cpp.o: In function nrf24_writeRegs(unsigned char, unsigned char const*, unsigned char)':
C:\Users\Nout\Documents\Arduino\ATTINY_nrf24L01_Sensor/ATTINY_nrf24L01_Sensor.ino:470: undefined reference to shiftOutByte' C:\Users\Nout\Documents\Arduino\ATTINY_nrf24L01_Sensor/ATTINY_nrf24L01_Sensor.ino:470: **undefined reference to shiftOutByte'**
collect2.exe: error: ld returned 1 exit status
exit status 1
I was able to discussed the topic with the guy who made the library and he solved it. His new release will include the updates to make it run for Arduino as well., but only when LTO is disabled.
It was done by elaborating further on your suggestion and apply it on a few more places.
I suggest you view it in the library rather then copying all changes out of context.
It remains a pitty that LTO cannot be enabled. Solving that in Arduino idee would stille save on valuable memory size.