Hi Guys,
I am attempting to use a C2000 Launchpad, chip: TMS320F28027 as a slave device to a Beagle Bone Black(BBB). Thus far I was able to verify that my BBB can see a I2c slave device by running the I2C-tools and a some code that verifies a connection. My issue seems to be in the initial setup of my F28027. I have made the following unsuccessful attempt at setting up the chip as a slave device however whenever I porbe it using the BBB I am unable to see its address or get any sort of response. I am using 4.7k pull-up resistors in the associated circuit.I included the whole code to ensure that I am not making some sort of clock error that could throw off everything. Again I am trying to get the Beagle Bone Black to see the C2000 TMS320F28027 as a slave device. I feel like I am close but am missing something simple. Any and all help is appreciated!!
Thank you in advance,
Carlo
//############################################################################# // // File: f2802x_examples_ccsv4/external_interrupt/Example_F2802xExternalInterrupt.c // // Title: F2802x External Interrupt test program. // // Group: C2000 // Target Device: TMS320F2802x // //! \addtogroup example_list //! <h1>External Interrupts</h1> //! //! This program sets up GPIO0 as XINT1 and GPIO1 as XINT2. Two other //! GPIO signals are used to trigger the interrupt (GPIO28 triggers //! XINT1 and GPIO29 triggers XINT2). The user is required to //! externally connect these signals for the program to work //! properly. //! //! XINT1 input is synched to SYSCLKOUT. //! XINT2 has a long qualification - 6 samples at 510*SYSCLKOUT each. //! //! GPIO34 will go high outside of the interrupts and low within the //! interrupts. This signal can be monitored on a scope. //! //! Each interrupt is fired in sequence - XINT1 first and then XINT2 //! //! Watch Variables: //! - Xint1Count for the number of times through XINT1 interrupt //! - Xint2Count for the number of times through XINT2 interrupt //! - LoopCount for the number of times through the idle loop // // (C) Copyright 2012, Texas Instruments, Inc. //############################################################################# // $TI Release: LaunchPad f2802x Support Library v100 $ // $Release Date: Wed Jul 25 10:45:39 CDT 2012 $ //############################################################################# #include "DSP28x_Project.h" // Device Headerfile and Examples Include File #include "f2802x_common/include/clk.h" #include "f2802x_common/include/flash.h" #include "f2802x_common/include/gpio.h" #include "f2802x_common/include/pie.h" #include "f2802x_common/include/pll.h" #include "f2802x_common/include/pwr.h" #include "f2802x_common/include/wdog.h" #include "f2802x_common/include/adc.h" #include "f2802x_common/include/sci.h" #include "f2802x_common/include/i2c.h" CPU_Handle myCpu; PLL_Handle myPll; WDOG_Handle myWDog; ADC_Handle myAdc; CLK_Handle myClk; FLASH_Handle myFlash; GPIO_Handle myGpio; PIE_Handle myPie; PWM_Handle myPwm1; SCI_Handle mySci; // Prototype statements for functions found within this file. interrupt void xint1_isr(void); interrupt void adc_isr(void); interrupt void adc_isr_pressure(void); interrupt void i2c_int1a_isr(void); void Init(); void ADC_INIT_Fn(); void ADC_SETUP_Fn(); void pwm_Init_(); void Motor_stop(); void Motor_forward(); void Motor_reverse(); void set_duty( int a); //------------------I2C Prototypes START-------------------// void I2CA_Init(void); Uint16 Values[6]; Uint16 instr=0x02; int i; int data[4] = {1,2,3,4}; int I2C_NUMBYTES = 4; //-------------------I2C Prototypes END-------------------// //-------------------UART/SCI Prototypes START-------------------// interrupt void sciaRxIsr(void); void scia_init(); void scia_xmit(int a); void scia_intpt_en(); void send_msg(); void send_back(char data); unsigned char msg[]="send any data now- Controller will send back it"; unsigned char msg2[]="You Sent:"; unsigned char rx_data; //-------------------UART/SCI Prototypes END-------------------// // Global variables for this example volatile uint32_t Xint1Count; int32_t adc_button_max= 800; int32_t adc_button_min = 4095; int32_t adc_slide_min = 20; int32_t adc_slide_max = 4085; //I2c Testing Uint16 Register; Uint16 InData[3]; char OutData[12]={"visiongrid"}; //data to be transmitted Uint16 I2cIndex; ////I2ctesting //Numbers for Testing Rig/// //int32_t adc_slide_min = 2915; //int32_t adc_slide_max = 3045; //////////////////////////// int32_t constant = 0; int32_t adc_slide_pot = 0; int32_t adc_button = 0; int32_t slope = 0; int32_t delta = 25; int32_t expected_value = 0; int32_t top_new = 0; //PWM int32_t CMPA=0; int32_t TBPRD = 4096; #define DELAY 100000 // us #define MOTOR_SWITCH_DELAY 10 // us enum State {STOP = 0, FORWARD, REVERSE}; uint8_t Previous_state = STOP, Current_state = STOP; void main(void) { // Initialize all GPIOs and variables Init(); //Init I2c InitSysCtrl(); // Step 1. Initialize System Control: Need this for UART AND I2c to function properly //InitI2CGpio(); //Shouldnt need this anymore due to intialization in Init() I2CA_Init(); // Step 4. Initialize all the Device Peripherals //initialize adc ADC_INIT_Fn(); ADC_SETUP_Fn(); // Set up chip to good state Motor_stop(); //UART INIT scia_intpt_en(); scia_init(); send_msg(); //Perform necessary calculations to linearize motor states //number multiplied by 1000 to allow for integer calculations int32_t top = (adc_slide_max-adc_slide_min); int32_t bottom = (adc_button_max - adc_button_min); top_new = ((adc_slide_max-adc_slide_min)<<10); slope = top_new/bottom; //slope = (((adc_slide_min-adc_slide_max)<<10)/(adc_button_max - adc_button_min)); constant = adc_slide_max - ((slope * adc_button_max)>>10); set_duty(2096); for(;;) { //----------------------------------I2C Start?-------------------------------------// //I2c slave setup //----------------------------------------------I2C END?-----------------------------------------------------------// //---------------------------------------ADC/CACULATION START---------------------------------// Previous_state = Current_state; // This is where you collect data // Wait for ADC interrupt, must go before state change interrupt ADC_forceConversion(myAdc, ADC_SocNumber_0); ADC_forceConversion(myAdc,ADC_SocNumber_1); adc_slide_pot = ADC_readResult(myAdc, ADC_SocNumber_0); adc_button = ADC_readResult(myAdc, ADC_SocNumber_1 ); expected_value = ((slope * adc_button)>>10) + constant; if(abs(expected_value - adc_slide_pot) < delta) { Current_state = STOP; Motor_stop(); DELAY_US(DELAY); continue; } // This is where you determine the next state // This is also where you adjust the Duty cycle based on the PID results if (adc_slide_pot < adc_slide_max && adc_slide_pot > adc_slide_min) { if (adc_slide_pot < expected_value ) { Current_state = FORWARD; } else if(adc_slide_pot > expected_value) { Current_state = REVERSE; } else { Current_state = STOP; } } else { Current_state = STOP; } //---------------------------------------ADC/CACULATION END---------------------------------// // This is where you act on said state change // Here you process said state change switch(Current_state) { case STOP: if(Previous_state != STOP) Motor_stop(); break; case FORWARD: if(Previous_state != FORWARD) Motor_forward(); break; case REVERSE: if(Previous_state != REVERSE) Motor_reverse(); break; default: Current_state = STOP; if(Previous_state != STOP) Motor_stop(); } } } interrupt void xint1_isr(void) { // This needs to set pin low GPIO_setLow(myGpio, GPIO_Number_12); // expected_value += 500; // // if(expected_value > adc_slide_max) // expected_value = adc_slide_min; // Acknowledge this interrupt to get more from group 1 PIE_clearInt(myPie, PIE_GroupNumber_1); } interrupt void adc_isr(void) { //discard ADCRESULT0 as part of the workaround to the 1st sample errata for rev0 ADC_clearIntFlag(myAdc, ADC_IntNumber_1); // Clear ADCINT1 flag reinitialize for next SOC PIE_clearInt(myPie, PIE_GroupNumber_10);// Acknowledge interrupt to PIE return; } interrupt void adc_isr_pressure(void) { //discard ADCRESULT7 as part of the workaround to the 1st sample errata for rev0 ADC_clearIntFlag(myAdc, ADC_IntNumber_2); // Clear ADCINT1 flag reinitialize for next SOC PIE_clearInt(myPie, PIE_GroupNumber_10);// Acknowledge interrupt to PIE return; } //---------------------------------------MOTOR STOP START-------------------------------------------// void Motor_stop() { GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_0, GPIO_Direction_Input); GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_1, GPIO_Direction_Input); GPIO_setMode(myGpio, GPIO_Number_2, GPIO_0_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_2, GPIO_Direction_Input); GPIO_setMode(myGpio, GPIO_Number_3, GPIO_1_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_3, GPIO_Direction_Input); } //---------------------------------------MOTOR STOP END-------------------------------------------// //---------------------------------------MOTOR FOWARD START-------------------------------------------// void Motor_forward() { Motor_stop(); DELAY_US(MOTOR_SWITCH_DELAY); //sets top connected GPIO0 to PWM function GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A); GPIO_setDirection(myGpio, GPIO_Number_0, GPIO_Direction_Output); //set bottom connected Gpio2 to on position // GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_GeneralPurpose); // GPIO_setDirection(myGpio,GPIO_Number_2, GPIO_Direction_Output); // GPIO_setHigh(myGpio, GPIO_Number_2); } //---------------------------------------MOTOR FOWARD END-------------------------------------------// //---------------------------------------MOTOR REVERSE START-------------------------------------------// void Motor_reverse() { Motor_stop(); DELAY_US(MOTOR_SWITCH_DELAY); //sets top connected GPIO1 to PWM function GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B); GPIO_setDirection(myGpio, GPIO_Number_1, GPIO_Direction_Output); //set bottom connected Gpio2 to on position // GPIO_setMode(myGpio, GPIO_Number_3, GPIO_2_Mode_GeneralPurpose); // GPIO_setDirection(myGpio,GPIO_Number_3, GPIO_Direction_Output); // GPIO_setHigh(myGpio, GPIO_Number_3); } //---------------------------------------MOTOR REVERSE END-------------------------------------------// void Init() { // Initialize all the handles needed for this application myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj)); myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj)); myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj)); myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj)); mySci = SCI_init((void *)SCIA_BASE_ADDR, sizeof(SCI_Obj)); // Perform basic system initialization WDOG_disable(myWDog); CLK_enableAdcClock(myClk); (*Device_cal)(); //Select the internal oscillator 1 as the clock source CLK_setOscSrc(myClk, CLK_OscSrc_Internal); // Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2 PLL_setup(myPll, PLL_Multiplier_10, PLL_DivideSelect_ClkIn_by_2); //from UART //PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2); // Disable the PIE and all interrupts PIE_disable(myPie); PIE_disableAllInts(myPie); CPU_disableGlobalInts(myCpu); CPU_clearIntFlags(myCpu); // // If running from flash copy RAM only functions to RAM // #ifdef _FLASH // memcpy(&secureRamFuncs_RunStart, &secureRamFuncs_LoadStart, (Uint32) &secureRamFuncs_LoadSize); // #endif #ifdef _FLASH // Copy time critical code and Flash setup code to RAM // This includes the following ISR functions: EPwm1_timer_isr(), EPwm2_timer_isr() // and FLASH_setup(); // The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart // symbols are created by the linker. Refer to the F2280270.cmd file. memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); // Call Flash Initialization to setup flash waitstates // This function must reside in RAM FLASH_setup(myFlash); #endif // end #ifdef _FLASH // Setup a debug vector table and enable the PIE PIE_setDebugIntVectorTable(myPie); PIE_enable(myPie); // Register interrupt handlers in the PIE vector table PIE_registerPieIntHandler(myPie, PIE_GroupNumber_1, PIE_SubGroupNumber_4, (intVec_t)&xint1_isr); // Enable XINT1 and XINT2 in the PIE: Group 1 interrupt 4 & 5 // Enable INT1 which is connected to WAKEINT PIE_enableInt(myPie, PIE_GroupNumber_1, PIE_InterruptSource_XINT_1); CPU_enableInt(myCpu, CPU_IntNumber_1); // Enable Global Interrupts CPU_enableGlobalInts(myCpu); //GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_GeneralPurpose); //GPIO_setDirection(myGpio, GPIO_Number_2, GPIO_Direction_Output); //GPIO_setMode(myGpio, GPIO_Number_3, GPIO_3_Mode_GeneralPurpose); //GPIO_setDirection(myGpio, GPIO_Number_3, GPIO_Direction_Output); //Setup GPIO 0&1 for PWM output GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A); GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B); //Initialize PWM CLK_disableTbClockSync(myClk); pwm_Init_(); CLK_enableTbClockSync(myClk); //INITIALIZE UART GPIO // Initalize GPIO GPIO_setPullUp(myGpio, GPIO_Number_19, GPIO_PullUp_Enable); GPIO_setPullUp(myGpio, GPIO_Number_12, GPIO_PullUp_Disable); GPIO_setQualification(myGpio, GPIO_Number_19, GPIO_Qual_ASync); GPIO_setMode(myGpio, GPIO_Number_19, GPIO_19_Mode_SCIRXDA); GPIO_setMode(myGpio, GPIO_Number_12, GPIO_12_Mode_SCITXDA); //follow example from UART for I2c Initialization GPIO_setPullUp(myGpio, GPIO_Number_28, GPIO_PullUp_Enable); GPIO_setPullUp(myGpio, GPIO_Number_29, GPIO_PullUp_Enable); GPIO_setMode(myGpio, GPIO_Number_28, GPIO_28_Mode_SDDA); GPIO_setMode(myGpio, GPIO_Number_29, GPIO_29_Mode_SCLA); // GPIO12 is XINT1, GPIO_setExtInt(myGpio, GPIO_Number_12, CPU_ExtIntNumber_1); // Configure XINT1 PIE_setExtIntPolarity(myPie, CPU_ExtIntNumber_1, PIE_ExtIntPolarity_FallingEdge); // Enable XINT1 PIE_enableExtInt(myPie, CPU_ExtIntNumber_1); } //----------------------------------ADC Functions START-------------------------------------// void ADC_INIT_Fn() { ADC_enableBandGap(myAdc); ADC_enableRefBuffers(myAdc); ADC_powerUp(myAdc); ADC_enable(myAdc); ADC_setVoltRefSrc(myAdc, ADC_VoltageRefSrc_Int); } void ADC_SETUP_Fn() { //set up adc for slide pot PIE_registerPieIntHandler(myPie, PIE_GroupNumber_10, PIE_SubGroupNumber_1, (intVec_t)&adc_isr); PIE_enableAdcInt(myPie, ADC_IntNumber_3); // Enable ADCINT1 in PIE //Note: Channel ADCINA1 will be double sampled to workaround the ADC 1st sample issue for rev0 silicon errata ADC_setIntPulseGenMode(myAdc, ADC_IntPulseGenMode_Prior); //ADCINT1 trips after AdcResults latch ADC_enableInt(myAdc, ADC_IntNumber_3); //Enabled ADCINT1 ADC_setIntMode(myAdc, ADC_IntNumber_3, ADC_IntMode_ClearFlag); //Disable ADCINT1 Continuous mode ADC_setIntSrc(myAdc, ADC_IntNumber_3, ADC_IntSrc_EOC0); //setup EOC0 to trigger ADCINT1 to fire ADC_setSocChanNumber (myAdc, ADC_SocNumber_0, ADC_SocChanNumber_A3); //set SOC0 channel select to ADCINA4 ADC_setSocTrigSrc(myAdc, ADC_SocNumber_0, ADC_SocTrigSrc_EPWM1_ADCSOCA); //set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1 ADC_setSocSampleWindow(myAdc, ADC_SocNumber_0, ADC_SocSampleWindow_7_cycles); //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1) //set up adc for presssure pot PIE_registerPieIntHandler(myPie, PIE_GroupNumber_10, PIE_SubGroupNumber_1, (intVec_t)&adc_isr_pressure); PIE_enableAdcInt(myPie, ADC_IntNumber_7); // Enable ADCINT7 in PIE //Note: Channel ADCINA1 will be double sampled to workaround the ADC 1st sample issue for rev0 silicon errata ADC_setIntPulseGenMode(myAdc, ADC_IntPulseGenMode_Prior); //ADCINT1 trips after AdcResults latch ADC_enableInt(myAdc, ADC_IntNumber_7); //Enabled ADCINT1 ADC_setIntMode(myAdc, ADC_IntNumber_7, ADC_IntMode_ClearFlag); //Disable ADCINT1 Continuous mode ADC_setIntSrc(myAdc, ADC_IntNumber_7, ADC_IntSrc_EOC1); //setup EOC7 to trigger ADCINT7 to fire ADC_setSocChanNumber (myAdc, ADC_SocNumber_1, ADC_SocChanNumber_A7); //set SOC07 channel select to ADCINA3 ADC_setSocTrigSrc(myAdc, ADC_SocNumber_1, ADC_SocTrigSrc_EPWM1_ADCSOCA); //set SOC2 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1 ADC_setSocSampleWindow(myAdc, ADC_SocNumber_1, ADC_SocSampleWindow_7_cycles); //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1) } //----------------------------------ADC Functions END-------------------------------------// //----------------------------------PWM Functions START-------------------------------------// void pwm_Init_() { CLK_enablePwmClock(myClk, PWM_Number_1); // Setup TBCLK PWM_setPeriod(myPwm1, TBPRD); // Set timer period 801 TBCLKs PWM_setPhase(myPwm1, 0x0000); // Phase is 0 PWM_setCount(myPwm1, 0x0000); // Clear counter // Setup counter mode PWM_setCounterMode(myPwm1, PWM_CounterMode_UpDown); // Count up and down PWM_disableCounterLoad(myPwm1); // Disable phase loading PWM_setHighSpeedClkDiv(myPwm1, PWM_HspClkDiv_by_10); // Clock ratio to SYSCLKOUT PWM_setClkDiv(myPwm1, PWM_ClkDiv_by_1); ///setup for GPIO6 PWM // Setup shadowing PWM_setShadowMode_CmpA(myPwm1, PWM_ShadowMode_Shadow); PWM_setLoadMode_CmpA(myPwm1, PWM_LoadMode_Zero); // Set actions PWM_setActionQual_CntUp_CmpA_PwmA(myPwm1, PWM_ActionQual_Clear); // Set PWM1A on event A, up count PWM_setActionQual_CntDown_CmpA_PwmA(myPwm1, PWM_ActionQual_Set); // Clear PWM1A on event A, down count //SETUP for GPIO 7 PWM // Setup shadowing PWM_setShadowMode_CmpB(myPwm1, PWM_ShadowMode_Shadow); PWM_setLoadMode_CmpB(myPwm1, PWM_LoadMode_Zero); // Set actions PWM_setActionQual_CntUp_CmpB_PwmB(myPwm1, PWM_ActionQual_Clear); // Set PWM1A on event A, up count PWM_setActionQual_CntDown_CmpB_PwmB(myPwm1, PWM_ActionQual_Set); // Clear PWM1A on event A, down count } void set_duty( int a) { CMPA = a; PWM_setCmpA(myPwm1, CMPA); PWM_setCmpB(myPwm1, CMPA);// Set compare A value } //----------------------------------PWM Functions END-------------------------------------// //----------------------------------I2C Functions START-------------------------------------// //Use pins 28 and 29 void I2CA_Init(void) { //SLAVE ATTEMPT // Initialize I2C I2caRegs.I2CSAR = 0x29; //Set slave address I2caRegs.I2CCNT = 4; //Numbe rof bytes to transfer I2caRegs.I2CFFTX.all = 0x6000; //enable FIFO mode and reset TX FIFO I2caRegs.I2CDXR = data[0]; //Send data[0-3] I2caRegs.I2CDXR = data[1]; //Store in next FIFO level I2caRegs.I2CDXR = data[2]; //Store in next FIFO level I2caRegs.I2CDXR = data[3]; //Store in next FIFO level I2caRegs.I2CMDR.bit.TRX = 1; //Set to Transmit mode I2caRegs.I2CMDR.bit.MST = 1; //Set to Master mode I2caRegs.I2CMDR.bit.FREE = 1;//Run in FREE mode I2caRegs.I2CMDR.bit.STP = 1; // release the bus after Tx I2caRegs.I2CMDR.bit.STT = 1; //Send the start bit, transmission will follow return; } //----------------------------------I2C Functions END-------------------------------------// //----------------------------------UART/SCI Functions START-------------------------------------// interrupt void sciaRxIsr(void) { rx_data = SCI_getData(mySci); send_back(rx_data); PIE_clearInt(myPie, PIE_GroupNumber_9); } void scia_init() { CLK_enableSciaClock(myClk); SCI_disableParity(mySci); SCI_setNumStopBits(mySci, SCI_NumStopBits_One); SCI_setCharLength(mySci, SCI_CharLength_8_Bits); SCI_enableRx(mySci); SCI_enableTx(mySci); SCI_enableRxInt(mySci); SCI_setBaudRate(mySci, SCI_BaudRate_9_6_kBaud); SCI_enable(mySci); } void scia_intpt_en() { PIE_enable(myPie); PIE_registerPieIntHandler(myPie, PIE_GroupNumber_9, PIE_SubGroupNumber_1, (intVec_t)&sciaRxIsr); PIE_enableInt(myPie, PIE_GroupNumber_9, PIE_InterruptSource_SCIARX); CPU_enableInt(myCpu, CPU_IntNumber_9); CPU_enableGlobalInts(myCpu); // Enable Global Interrupts } void scia_xmit(int a) { while(SCI_getTxFifoStatus(mySci) != SCI_FifoStatus_Empty); //while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {} SCI_putDataBlocking(mySci, a); // SciaRegs.SCITXBUF=a; } void send_msg() { int i=0; while(msg[i]!='\0') { scia_xmit(msg[i]); i++; } } void send_back(char data) { int i=0; while(msg2[i]!='\0') { scia_xmit(msg2[i]); i++; } scia_xmit(rx_data); scia_xmit('\r'); scia_xmit('\n'); } //----------------------------------UART/SCI Functions END-------------------------------------// //=========================================================================== // No more. //===========================================================================