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.

CC2642R: DAC oprate got stuck

Part Number: CC2642R

I use DAC of cc2642R and triode to control led, here is my code

all the DAC handle got initialize,

Stangely,sometimes I use debug ,the program won't stuck , but it always stuck if I don't use debug. 

  • The status of return means The DAC is currently in use by another handle or by the sensor controller , But i check code ,it is free, and i don't use sensor controller.

  • Hello kai,

    I also assume that the sensor controller is not involved.  Can you please provide the code for which you disable one DAC handle before enabling the next?  Preferably using the Insert -> Code E2E tool so that your code is searchable.  How are you checking that the handle has been freed?  Debugging code can be inherently slower due to the JTAG interface, thus you could consider adding delays between DAC_setCode usage or handle handoffs to determine whether this improves performance.

    Regards,
    Ryan

  • sem_wait(&timersem);
            addBytesToUart(semPromt,sizeof(semPromt));
            switch(currentEvent)
            {
            case idle:
    
                break;
            case redLight:
                addBytesToUart(redPromt,sizeof(redPromt));
                if(redSwitch)
                {
                    setLedPower(redLedStru);
                }
                break;
            case redWork:
                sampleTimes = 0;
                break;
            case redOff:
                addBytesToUart(redoffPromt,sizeof(redoffPromt));
                averagePacket(1,sampleTimes);
                if(redSwitch)
                {
                    setLedOff(redLedStru);
                }
                break;
            case redNotWork:
                break;
            case irLight:
                addBytesToUart(irPromt,sizeof(irPromt));
                if(irSwitch)
                {
                    setLedPower(irLedStru);
                }
                break;
            case irWork:
                sampleTimes = 0;
                break;
            case irOff:
                addBytesToUart(iroffPromt,sizeof(iroffPromt));
                averagePacket(2,sampleTimes);
                if(irSwitch)
                {
                    setLedOff(irLedStru);
                }
                break;
            case irNotWork:
                break;
            case gnLight:
                addBytesToUart(gnPromt,sizeof(gnPromt));
                if(gnSwitch)
                {
                    setLedPower(gnLedStru);
                }
                break;
            case gnWork:
                sampleTimes = 0;
                break;
            case gnOff:
                addBytesToUart(gnoffPromt,sizeof(gnoffPromt));
                averagePacket(3,sampleTimes);
                if(gnSwitch)
                {
                    setLedOff(gnLedStru);
                }
                break;
            case gnNotWork:
                break;
            case envSample:
                envSampleTimes = 0;
                break;
            case upLoad:
                averageEnv();
                envSampleTimes = 0;
                sampleTimes = 0;
                uploadData();
                oprateUartBufferTx();
                redSwitch = setRedSwitch;
                irSwitch = setIrSwitch;
                gnSwitch = setGnSwitch;
                calcLedTime();
                GPIO_write(CONFIG_GPIO_ADCReset,0);
                usleep(adcResetTime);
                GPIO_write(CONFIG_GPIO_ADCReset,1);
                break;
            default:
                break;
            }

     I assert the time in the timer callback function , when it is on time then send the semaphore to switch the dac .the time between every switch at least has hundreds micro second。 I checked by uart send promt to ensure that there is no repeat enter set or disable. It works well in the debug mode ,but it stuck after i exit the debug mode .

    thanks for your reply.

  • OK, I tested  again, It in some case it would skip the DAC off  code, i wanna know is there any solution to ensure the thread will not get disturbed by other thread. Like mutex ,the example of mutex in the sdk  is semaphore , I am new to use the ti-rtos.

  • Several stacks use HwiP_disable/HwiP_restore to enter/exit critical sections.  You can read further from the TI-RTOS Kernel Runtime APIs.  If not done yet, consider turning off all DAC handles and confirming the return status of each immediately before enabling the next instance.

    Regards,
    Ryan