Good morning
Is there a way to memcpy from SFR's in the C51?
I have tried to memcpy((char*)&buffer, (char*)&CAN0IF2DA1L, 8); but it doesn't work
Other things i tried
memcpy((char*)&buffer, CAN0IF2DA1L, 8); //error C214: illegal pointer conversion
memcpy((char*)&buffer, (char*)&CAN0IF2DA1L, 8); //error C189: '&' on bit/sfr illegal
Any ideas?
Richard
RichardT said:memcpy from SFR's in the C51?
memcpy from SFR's in the C51?
Why do you want to do that?
http://www.catb.org/esr/faqs/smart-questions.html#goal
RichardT said:it doesn't work
What, exactly, do you mean by that?
Do you get error messages - or what?
Are you aware of the different address spaces on an 8051 - in particular, how that impacts pointers in C51 ?
http://www.keil.com/support/man/docs/c51/c51_le_ptrs.htm
Andy Neil said:Why do you want to do that?
My Canbus receive routine needs to copy the incoming CAN message from SFR registers, the length of the message changes depending on the message so i'd like to use a for loop with a pointer or a memcpy with the length
Andy Neil said:What, exactly, do you mean by that? Do you get error messages - or what?
The memcpy copies either the pointer address info or info from another address space but not the SFR data
Andy Neil said:Are you aware of the different address spaces on an 8051 - in particular, how that impacts pointers in C51 ?
I am aware of the different address spaces but do not know how to create a pointer to the SFR address space
RichardT said:do not know how to create a pointer to the SFR address space
http://www.keil.com/support/man/docs/c51/c51_le_memspecificptrs.htm
Although, IIRC, SFR space is not indirectly addressable ... ?
RichardT said:My Canbus receive routine needs to copy the incoming CAN message from SFR registers
Doesn't the chip maker give examples of doing that?
you need to familiarize yourself with the ;51
http://www.danlhenry.com/mfg/philips/docs/80C51_FA​M_ARCH_1.pdf http://www.danlhenry.com/mfg/philips/docs/80C51_FA​M_HARDWARE_1.pdf http://www.danlhenry.com/mfg/philips/docs/80C51_FA​M_PROG_GUIDE_1.pdf
²erik malund - Dan's site has been dead for some time now.
NXP do still seem to have archive copies of the so-called "bible" for the 8051:
https://community.nxp.com/docs/DOC-334648 - 80C51 Family Architecture.pdf
https://community.nxp.com/docs/DOC-334649 - 80C51 Family Hardware Description.pdf
https://community.nxp.com/docs/DOC-334650 - 80C51 Family Programmer's Guide and Instruction Set.pdf
Also on Dr. Linden McClure's page at the University of Colorado, Boulder:
http://ecee.colorado.edu/~mcclurel/
Andy Neil said:IIRC, SFR space is not indirectly addressable
It's been a long time since I last used an 8051 - but that recollection is correct:
From the Philips Semiconductors 80C51 Family Architecture document - linked earlier
RichardT said:I am aware of the different address spaces but do not know how to create a pointer to the SFR address space
That statement is self-contradictory. Just about the single most important thing to learn about the different address spaces of an 8051 is that one cannot create a pointer to an SFR.
just made aware the links I previously used are dead, here are some others
community.nxp.com/.../DOC-334648 - 80C51 Family Architecture.pdf
community.nxp.com/.../DOC-334649 - 80C51 Family Hardware Description.pdf
community.nxp.com/.../DOC-334650 - 80C51 Family Programmer's Guide and Instruction Set.pdf
²erik malund - err ... I just posted those above!
You don't quite seem to have got the hang of this new forum, yet!
;-)
Note that you can edit your posts via the 'Actions' button:
and can now post pictures!
Are the registers even contiguous?
*p++ = CAN0IF2DA1L;*p++ = CAN0IF2DA1H;
...
given that SFR space isn't indirectly accessible, I guess the whole question is moot?
RichardT said:memcpy((char*)&buffer, (char*)&CAN0IF2DA1L, 8 );
and, as we're only talking 8 bytes anyhow, eight direct assignments is almost certainly going to be the quickest solution.
Unless the chip has some DMA tricks ...
But RichardT seems to have lost interest.
Andy Neil said:given that SFR space isn't indirectly accessible, I guess the whole question is moot?
Agreed
Andy Neil said:and, as we're only talking 8 bytes anyhow, eight direct assignments is almost certainly going to be the quickest solution.
Length is dynamic but in my case maximum of 8 bytes
Andy Neil said:Unless the chip has some DMA tricks ...
No tricks here
Andy Neil said:eight direct assignments
I tried googling the "CAN0IF2DA1L" from the OP, and found this: https://gist.github.com/petscare/3884991 - which does exactly that:
// copy message into CAN0rx; m->Data[0] = CAN0IF2DA1L; m->Data[1] = CAN0IF2DA1H; m->Data[2] = CAN0IF2DA2L; m->Data[3] = CAN0IF2DA2H; m->Data[4] = CAN0IF2DB1L; m->Data[5] = CAN0IF2DB1H; m->Data[6] = CAN0IF2DB2L; m->Data[7] = CAN0IF2DB2H;
Andy Neil said:I tried googling the "CAN0IF2DA1L" from the OP, and found this: https://gist.github.com/petscare/3884991 - which does exactly that:
I have been using very similar code for a while now.
The can protocol gives the length of the packet (being 1 - 8 bytes) so I wanted to try copy the exact number of bytes into my rx buffer for processing.
No point passing the invalid characterst but it seems like the most efficient way of doing this is to copy all 8 bytes every time