Quantcast
Channel: Data converters
Viewing all articles
Browse latest Browse all 27683

Forum Post: RE: CCS/ADS8699: ADS8699 SPI DMA example c code

$
0
0
Hi, hope you all have a beautiful christmas time. Now I have a O'Scope to monitor the signals. Furthermore I have written new example code with different clock sources to find a working one: 1. external clock 48MHz: maybe my target SPI clock of 16MHz is not possible because of the fixed dividers -> 12MHz with divider 4 2. internal clock: set to 32MHz that I reach the 16MHz with divider 2 3. intenal clock slow: as I have seen in the USERS GUIDE example #include #include #include #include #include #include static volatile uint8_t RXData[10]; static volatile uint8_t i = 0; static uint8_t TXData = 0; static uint8_t ii = 0; /* SPI Master Configuration Parameter */ const eUSCI_SPI_MasterConfig spiMasterConfig = { // ========== external clock ================== // EUSCI_B_SPI_CLOCKSOURCE_SMCLK, // SMCLK Clock Source // 24000000, // SMCLK // 12000000, // SPICLK // EUSCI_B_SPI_MSB_FIRST, // ========== internal clock =================== // EUSCI_B_SPI_CLOCKSOURCE_SMCLK, // SMCLK Clock Source // 32000000, // SMCLK // 16000000, // SPICLK // EUSCI_B_SPI_MSB_FIRST, // ========== internal clock example slow ====== EUSCI_B_SPI_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 3000000, // SMCLK 500000, // SPICLK EUSCI_B_SPI_MSB_FIRST, // ============================================= // MSB First EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT, // Phase EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW, // low polarity EUSCI_B_SPI_3PIN // 3Wire SPI Mode }; int main(void) { volatile uint32_t ii; /* Halting WDT */ WDT_A_holdTimer(); MAP_PCM_setCoreVoltageLevel(PCM_VCORE1); // Achtung zwingend vor clock set, sonst factory reset nötig MAP_FlashCtl_A_setWaitState(FLASH_A_BANK0, 3); MAP_FlashCtl_A_setWaitState(FLASH_A_BANK1, 3); /* ========== external clock ==================================================================== */ /* Starting and enabling HFXT */ // GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); // CS_setExternalClockSourceFrequency(32000, 48000000); // // /* ------------------------------------------- Pos.1 for initClockSignal ---------- */ // MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); //48MHz // MAP_CS_initClockSignal(CS_SMCLK,CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_4); //12MHz // /* ---------------------------------------------------------------------------------------- */ // // /* Starting HFXT in non-bypass mode without a timeout. Before we start // * we have to change VCORE to 1 to support the 48MHz frequency */ // CS_startHFXT(false); // /* ------------------------------------------- Pos.2 for initClockSignal ----------- */ // /* ----------------------------------------------------------------------------------------- */ /* ========== internal clock ===================================================================== */ // CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_3); //48MHz // CS_setDCOFrequency(32000000); // CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2); /* ========== internal clock example slow ======================================================== */ CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_3); //48MHz CS_setDCOFrequency(3000000); CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // ============================================================================================== //![Simple SPI Example] /* Selecting P1.5 P1.6 and P1.7 in SPI mode */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); // P1.0 LED GPIO_setAsInputPin(GPIO_PORT_P4, GPIO_PIN6); // P4.6 RVS GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN3); // P4.3 CONV GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);// P1.0 LED GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3); // P4.3 CONV /* Configuring SPI in 3-wire master mode & enabling it & interrupts */ bool statusFlag = false; statusFlag = SPI_initMaster(EUSCI_B0_BASE, &spiMasterConfig); SPI_enableModule(EUSCI_B0_BASE); SPI_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_SPI_RECEIVE_INTERRUPT); Interrupt_enableInterrupt(INT_EUSCIB0); //Interrupt_enableSleepOnIsrExit(); /* Delaying waiting for the module to initialize */ for(ii=0;ii high)"); while (GPIO_getInputPinValue(GPIO_PORT_P4, GPIO_PIN6) == 0); // RVS // set CONV to low for reading buffer: GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3); int k; for (k = 0; k < 4; ++k) { RXData[k] = SPI_receiveData(EUSCI_B0_BASE); } __no_operation(); } /*PCM_gotoLPM0(); __no_operation();*/ } //void euscib0_isr(void) //{ // int i = 0; // uint32_t status = SPI_getEnabledInterruptStatus(EUSCI_B0_BASE); // SPI_clearInterruptFlag(EUSCI_B0_BASE, status); // // if(status & EUSCI_B_SPI_RECEIVE_INTERRUPT) // { // RXData[i++] = SPI_receiveData(EUSCI_B0_BASE); // if ((i % 2) == 1) { // for( ii=0;ii<10;ii++); // GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3); // } // GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); // for(i=0;i<48000000;i++); // delay 1s // GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); // } //} My first issue when i debug is, that I always end in the default handler when I enter the line "GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3);" after the for loop. /* This is the code that gets called when the processor receives an unexpected */ /* interrupt. This simply enters an infinite loop, preserving the system state */ /* for examination by a debugger. */ void Default_Handler(void) { /* Fault trap exempt from ULP advisor */ #pragma diag_push #pragma CHECK_ULP("-2.1") /* Enter an infinite loop. */ while(1) { } #pragma diag_pop } If I do "step into F5" steps I don't end in the handler, but with "step over F6" steps I'm ending in the default handler. I cannot find the explanation for this.

Viewing all articles
Browse latest Browse all 27683

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>