We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi again. I have a custom 8051 processor which has defined a series of sfr, such as "sfr id_custom = 0x32" in the header reg51.h file. When I tried to access from C, throws the error "Error 146: Invalid Base Address". As I can do to disable this protection? or enabling the access to these registers? Thanks.
PS: Sorry about my english. =)
If I remember correctly, SFR's are located in the addresses 0x80 through 0xFF. So it's not surprising that the compiler complains when it sees the address 0x32. If the register really is located at address 0x32, you can access it with a macro:
#define MYREG_INDIRECT (*(unsigned char volatile data*)0x32) /* indirect addressing */ #define MYREG_DIRECT (*(unsigned char volatile idata*)0x32) /* direct addressing */
Correction: use data for direct addressing and idata for indirect addressing. If the register can be accessed both ways, direct addressing is preferred.
I have a custom 8051 processor which has defined a series of sfr, such as "sfr id_custom = 0x32" in the header reg51.h file. When I tried to access from C, throws the error "Error 146: Invalid Base Address". my guess is that you try to bit address it. Please read the manual only SFRs with address divisible by 8 can be bit addressed.
Erik
My guess.. Have you read MFQ? Nowhere does it say that I am trying to bit address the sfr. The access is doing by: id_custom = some_val; thanks for your answer.
Thanks for your answer, it's very useful. Gonzalo.
a custom 8051 processor which has defined a series of sfr, such as "sfr id_custom = 0x32" in the header reg51.h file.
Then you need to complain to whoever made that file --- it's broken. There is no SFR at that address.
Have you read MFQ? Nowhere does it say that I am trying to bit address the sfr.
Neither does it say anything about how you do access it.
id_custom = some_val;
So how else other than by guessing was anyone supposed to know that?
"Then you need to complain to whoever made that file --- it's broken. There is no SFR at that address."
Note that the original post said "custom 8051 processor". So maybe someone did something less clever, when designing their own chip in programmable logic. Maybe this poor processor designer have placed a sfr in the middle of normal data addresses, just to make life interesting for the compiler/linker.
That's not true, if I compile with the $NOMOD51 param, in an assembly file, the sfr declared like that work well. Moreover, the entire soft was in A51, now I'm trying to pass it to C, and I encountered this little things... Gonzalo.
Maybe this poor processor designer have placed a sfr in the middle of normal data addresses
They can't have, because whatever they placed there is not an SFR. It's a memory-mapped peripheral in a spectacularly poorly chosen place, but not an SFR.
No, it does not.
By Definition, any thing at any address less that 0x80 is not an SFR.
Semantics (My Opinion)
However since the compiler will assume in is RAM you will have to reserve all of them so the compiler does not use them as RAM. This may make the compiler unhappy when it tries to setup the RAM and stack. You may have some issues with the small memory model.
ASM allows you to work around more things. Compilers have expectations.
A Look at how chip makers solved the same issue may help if it is your chip.
SiLabs use paging of the SFR space.
Triscend, IIRC, gave you the choice to have your custom peripherals appear as SFRs, or as memory-mapped in DATA or XDATA space...
Have you read MFQ? no, I have not, I have no idea what it is