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.

TMS320F28377S: CLA Reading ADC result registers

Genius 5910 points
Part Number: TMS320F28377S

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

  • Hi,

    You should check how uint16_t is defined. For CLA it must be unsigned short, not int. Defines in #include <stdint.h> take into account is it CLA or not.
    Mixing uintptr_t with uint16_t * is dangerous. One specifies bit count, another isn't, how do you know how uintptr_t is defined? At least in stdint.h on CLA they point to the same thing.

    Edward
  • I tried multiple definition to get it working. But to be sure I tested this also:

    volatile uintptr_t* resAddrB;
    volatile uintptr_t* resAddrD;
    volatile unsigned short *ADCmem;
    ADCmem = (unsigned short *)ADCB_BASE;
    CLA_DEBUG[2]=ADCmem[1];
    resAddrB = (uintptr_t *)(ADCB_BASE + ADC_O_RESULT1);
    resAddrD = (uintptr_t *)(ADCD_BASE + ADC_O_RESULT1);
    CLA_DEBUG[0]=*resAddrB;
    CLA_DEBUG[1]=*resAddrD;

    No result :-(
  • 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.

    • uintptr_t* resAddrB;  

     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

    • uintptr_t* resAddrD;
    • resAddrB = (uint16_t *)(ADCB_BASE + ADC_O_RESULT1);

    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.

    •     resAddrD = (uint16_t *)(ADCD_BASE + ADC_O_RESULT1);
    •     CLA_DEBUG[0]=*resAddrB;

    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.

    •     CLA_DEBUG[1]=*resAddrD;

  • I'm no pointer casting expert and is is really confusing the pointer witdth difference between the CLA and MCU.
    I tried many options and copied every example I could find.
    and uintptr_t I found in an example and used it if it make any difference but no.
    I already tested it with the uint16_t

    #pragma DATA_SECTION(CLA_DEBUG,"Cla1ToCpuMsgRAM")
    volatile uint16_t CLA_DEBUG[3];

    volatile uint16_t* resAddrB;
    volatile uint16_t resAddrD;
    resAddrB = (uint16_t *)(ADCB_BASE + ADC_O_RESULT1);
    resAddrD = (uint16_t *)(ADCD_BASE + ADC_O_RESULT1);
    CLA_DEBUG[0] = *(uint16_t*)resAddrB;
    CLA_DEBUG[1] = *(uint16_t*)resAddrB;

    The result is the same.



    Note:
    In stdint.h
    typedef unsigned short uintptr_t;
  • You keep making new bugs

    a)
    volatile uint16_t* resAddrB;
    volatile uint16_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;

    b)
    volatile uintptr_t resAddrB;
    volatile uintptr_t resAddrD;
    resAddrB = (ADCB_BASE + ADC_O_RESULT1);
    resAddrD = (ADCD_BASE + ADC_O_RESULT1);
    CLA_DEBUG[0] = *(uint16_t*)resAddrB;
    CLA_DEBUG[1] = *(uint16_t*)resAddrD;

    c)
    CLA_DEBUG[0] = *(uint16_t*)(ADCB_BASE + ADC_O_RESULT1);
    CLA_DEBUG[1] = *(uint16_t*)(ADCD_BASE + ADC_O_RESULT1);

    d)
    CLA_DEBUG[0] = AdcbResultRegs.ADCRESULT1;
    CLA_DEBUG[1] = AdcdResultRegs.ADCRESULT1;

    all should be fine. Did you verify with debugger right data is really in ADC result registers?

    Edward
  • You make no new bug when it doesn't work in the first place.
    But all the variants you suggested don't work. I think the problem is somewhere else.

    I compare the register value in the CCS debug register value with the CLA_DEBUG value and there aren't the same.
    I'm sure that the CLA updates them because I have a counter to verify that.
  • Hi evs,

    It looks like EK has given you some good tips and notes.

    I don't believe this will make a difference but you have use the hw_types.h in driverlib folder.

    Accessed are defined like this
    #define HWREG(x) \
    (*((volatile uint32_t *)(x)))

    This may not be the issue though since what EK posted above looks correct.

    Regards,
    sal
  • 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.

  • Hi evs,

    so you know the answer and won't tell us, right? No single problem with CLA and ADC lead me diving into your puzzle. Now you say it's obvious and will reveal it only for money? Alright! I shouldn't try helping for incomplete requests.

    Edward
  • WOW. I don't think it is very useful to anyone. But in case you like to know.
    ADCB_BASE is not the correct base register for the ADC results: ADCBRESULT_BASE is.
  • Thanks. Obvious but not easy to catch. Since you are doing it smart way, vase, offset, etc, I thought you knew what are you doing. It could be simpler to instruction single step CLA and check what address and how is it reading :-).

    Regards
    Edward