This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
I have the following problem:
I don't get the correct values from the ADC result register inside the CLA
Code from CLA:
uintptr_t* resAddrB;
uintptr_t* resAddrD;
resAddrB = (uint16_t *)(ADCB_BASE + ADC_O_RESULT1);
resAddrD = (uint16_t *)(ADCD_BASE + ADC_O_RESULT1);
CLA_DEBUG[0]=*resAddrB;
CLA_DEBUG[1]=*resAddrD;
DEBUG window:
CLA_DEBUG long[2] [198,198] 0x000014D4@Data
[0] long 198 0x000014D4@Data
[1] long 198 0x000014D6@Data
GRP( AdcbResultRegs ).REG( ADCRESULT1 ) Unsigned / Readable,Writeable 23272 (Decimal)
GRP( AdcdResultRegs ).REG( ADCRESULT1 ) Unsigned / Readable,Writeable 22032 (Decimal)
So any suggestion how to solve it?
Thanks,
EVS
Sorry for disturbing, I didn't know what uintptr_t is used for. But I wonder if you use it properly. First of all what's CLA_DEBUG, it's not clear what did you copy from debug window.
unitptr_t is int type wide enough to store pointer. Pointer on CLA is 16bits wide. I wonder why do you declare pointer to int type, which is wide enough to store pointer (intptr_t)? I think star should be removed here
then without star in resAddrB declaration, typecast to pointer to uint16_t wouldn't be necessary. uintptr_t with pointer inside would point to adc result1, no problem.
Now the question is what's CLA_DEBUG[0]. Do you won't to copy data there. Then using intptr_t resAddrB without star, it should be
CLA_DEBUG[0] = *(uint16_t*)resAddrB;
That would be valid usage for intptr_t typedef, no bug reading too wrong type at adc result N.
As I said the problem is not in the pointer casting/adressing. I don't think HWREG is suitable for the CLA.
The problem is very obvious if you know how the ADC works. And I hopped someone pointed that out to me early.