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.
I have just started using the keil compiler and had a simple question about getting data to and from an xdata buffer. Say I have declared a buffer and two global integer variables as follows; xdata volatile BYTE TEMPBUF[64]; int nTemperature, nTemperature2; How do I get data from the TEMPBUF to the integer variables? nTemperature = (int)TEMPBUF; nTemperature2 = (int)TEMPBUF [2]; And how do I get integer data to the TEMPBUF? (int)TEMPBUF = nTemperature; (int)TEMPBUF[2] = nTemperature2; Any help would be greatly appreciated, JD
Simple assignment should work fine to move data between memory spaces. The compiler will figure out what sort of instructions it needs to do the job. Do you have a problem with those statements? The first example should probably be TEMPBUF[0]. (Otherwise, you'll get the address of the array, not value of the first entry.) If 8 bits is enough for your samples, why not declare all the relevant variables (TEMPBUF as well as nTemp*) with the same type? Maybe even typedef char TempSample; xdata volatile TempSample TempBuf[64]; TempSample nTemp, nTemp2; so that you can change the representation of every related variable in one swoop if necessary. Conversely, if the samples are really 16 bits wide (as it appears from the attemps to store them at multiples of 2 bytes), then just declare TEMPBUF as a U16 (unsigned int).
"I have just started using the keil compiler" Are you already familiar with 'C' in general?
Yes already familiar with 'C', it's just I tried the following code
if (SETUPDAT[0] == VR_UPLOAD) { // to host *((WORD*)(EP0BUF+0)) = nShutter; *((WORD*)(EP0BUF+2)) = nShutterSpeed; } else { // from host nShutter = *((WORD*)(EP0BUF+0)); nShutterSpeed = *((WORD*)(EP0BUF+2)); }