I'm doing a simple program that reads UART buffer (S0BUF) on an incoming transmission and then transmits it back via the UART when I press a button. I'm using the Nordic Semiconductor nRF24LE1 chip.
I get it to work with C and I get it to work when I use one of the R0-R7 registers. What I want to do is to use a relocatable byte instead of the normal R-registers.
Here is a snippet of code that works.
UART_ISR: ; (Store incoming transmission in R0)
JNB RI0, UART_ISR_A
MOV R0, S0BUF
SETB P00
CLR RI0
JMP UART_ISR_END
UART_ISR_A:
SETB P01
CLR TI0
UART_ISR_END:
RETI
Main:
MOV A, P2
XRL A, #0x0FE
JZ Main_Case_A
XRL A, #(0x0FE XOR 0x0FD)
JZ Main_Case_B
...
Main_Case_A:
MOV S0BUF, R0
SJMP Main
But if I do the following changes (marked with <--- THIS) it wont work. I know I am missing out some segments and stuff in this snippet, but I don't want to many lines.
?DT?Data segment data ; <--- THIS
rseg ?DT?Data ; <--- THIS
RX_Message: ds 1 ; <--- THIS
UART_ISR: ; (Store incoming transmission in R0)
JNB RI0, UART_ISR_A
MOV RX_Message, S0BUF ; <-- THIS
SETB P00
CLR RI0
JMP UART_ISR_END
UART_ISR_A:
SETB P01
CLR TI0
UART_ISR_END:
RETI
Main:
MOV A, P2
XRL A, #0x0FE
JZ Main_Case_A
XRL A, #(0x0FE XOR 0x0FD)
JZ Main_Case_B
...
Main_Case_A:
MOV S0BUF, RX_Message ; <--- AND THIS
SJMP Main
It assembles and everything without warnings or errors but the result is not the same.
What I want is to let the assembler/linker to decide where in memory to put my RX_Message byte. If I look in the list file I can see that it assigned it to address 0x00 which is fine by me since I'm not using R0 anywhere.. But I assumed that if I used R0 somewhere it would set my RX_Message address to 0x01 (or something else).. but that didn't happen.
What am I missing out? Or am I doing it the wrong way?
Solution.. The stack is of course involved since I'm using interrupts (didn't mention that because I didn't think that was important.. Adding some code to reposition the stack solved the issue. Although I hoped that the linker wouldn't have put my RX_Message label on the stacks default address..