3509|3

4

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

28035的传感器采集并想上位机发送数据,我想求助大神看看成叙问题到底出在哪?老是... [复制链接]

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

// Prototype statements for functions found within this file.
interrupt void adc_isr(void);

// Global variables used in this example:

Uint16 ConversionCount;
float TempSensorVoltage;
float adclo=0;
float Dec;
char  rec_data[9];
int SampleCount;          //采样次数
int SampleCountSCI;
static int AsciiBuff[9];
#define array_size 9
typedef struct array array;
struct array
{
   int v[array_size];
};

array a;

void HexToASCII(float data);
array f();


void main()
{

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2803x_SysCtrl.c file.
   InitSysCtrl();


// Step 2. Initialize GPIO:
// This example function is found in the DSP2803x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();  // Skipped for this example

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
   DINT;

// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2803x_PieCtrl.c file.
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP2803x_DefaultIsr.c.
// This function is found in DSP2803x_PieVect.c.
   InitPieVectTable();

// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
   EALLOW;  // This is needed to write to EALLOW protected register
   PieVectTable.ADCINT1 = &adc_isr;
   EDIS;    // This is needed to disable write to EALLOW protected registers

// Step 4. Initialize the ADC:
// This function is found in DSP2803x_Adc.c
   InitAdc();  // For this example, init the ADC

// Step 5. Configure ADC to sample the temperature sensor on ADCIN5:
// The output of Piccolo temperature sensor can be internally connected to the ADC through ADCINA5
// via the TEMPCONV bit in the ADCCTL1 register. When this bit is set, any voltage applied to the external
// ADCIN5 pin is ignored.
        EALLOW;
        AdcRegs.ADCCTL1.bit.TEMPCONV         = 1;        //Connect internal temp sensor to channel ADCINA5.
        EDIS;

// Step 6. Continue configuring ADC to sample the temperature sensor on ADCIN5:
// Since the temperature sensor is connected to ADCIN5, configure the ADC to sample channel ADCIN5
// as well as the ADC SOC trigger and ADCINTs preferred. This example uses EPWM1A to trigger the ADC
// to start a conversion and trips ADCINT1 at the end of the conversion.
        EALLOW;
        AdcRegs.ADCCTL1.bit.INTPULSEPOS        = 1;        //ADCINT1 trips after AdcResults latch
        AdcRegs.INTSEL1N2.bit.INT1E     = 1;        //Enabled ADCINT1
        AdcRegs.INTSEL1N2.bit.INT1CONT  = 0;        //Disable ADCINT1 Continuous mode
        AdcRegs.INTSEL1N2.bit.INT1SEL        = 0;        //setup EOC0 to trigger ADCINT1 to fire
        AdcRegs.ADCSOC0CTL.bit.CHSEL         = 5;        //set SOC0 channel select to ADCINA5 (which is internally connected to the temperature sensor)
        AdcRegs.ADCSOC0CTL.bit.TRIGSEL         = 5;        //set SOC0 start trigger on EPWM1A
        AdcRegs.ADCSOC0CTL.bit.ACQPS         = 6;        //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
        EDIS;


// Step 7. User specific code, enable interrupts:

// Enable ADCINT1 in PIE
   PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
   PieCtrlRegs.PIEIER1.bit.INTx1 = 1;        // Enable INT 1.1 in the PIE
   PieCtrlRegs.PIEIER9.bit.INTx1 = 1;
   PieCtrlRegs.PIEIER9.bit.INTx2 = 1;
   IER |= M_INT1;
   IER |= M_INT9;                                                 // Enable CPU Interrupt 1
   EINT;                                                          // Enable Global interrupt INTM
   ERTM;                                                          // Enable Global realtime interrupt DBGM

   ConversionCount = 0;


// Assumes ePWM1 clock is already enabled in InitSysCtrl();
   EPwm1Regs.ETSEL.bit.SOCAEN        = 1;                // Enable SOC on A group
   EPwm1Regs.ETSEL.bit.SOCASEL        = 4;                // Select SOC from from CPMA on upcount
   EPwm1Regs.ETPS.bit.SOCAPRD         = 1;                // Generate pulse on 1st event
   EPwm1Regs.CMPA.half.CMPA         = 0x0080;        // Set compare A value
   EPwm1Regs.TBPRD                                 = 0xFFFF;        // Set period for ePWM1
   EPwm1Regs.TBCTL.bit.CTRMODE         = 0;                // count up and start

// Wait for ADC interrupt
   for(;;)
   {

   }

}


interrupt void  adc_isr(void)
{
  IER = 0x0000;
  IFR = 0x0000;
  ConversionCount++;
  TempSensorVoltage = ((float)AdcResult.ADCRESULT0)*3.0/65520.0+adclo;;

  // If 20 conversions have been logged, start over
  /*if(ConversionCount == 9)
  {
     ConversionCount = 0;
  }
  else ConversionCount++;*/

   HexToASCII(TempSensorVoltage);
   a=f();
   SciaRegs.SCIFFTX.bit.TXFFINTCLR=1;   //清除TXFFINT标志位

  AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;                //Clear ADCINT1 flag reinitialize for next SOC
  PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;   // Acknowledge interrupt to PIE

  return;
}
interrupt void SCITXINTA_ISR(void)    //SCIA发送中断函数
{
   int i;
   for(i=0;i<9;i++)
   {
      SciaRegs.SCITXBUF=a.v[i];  //发送数据
   }

   PieCtrlRegs.PIEACK.all=0x0100;      //使同组其他中断能够得到响应
   EINT;           // 开全局中断
}
interrupt void SCIRXINTA_ISR(void)     //SCIA接收中断函数
{
   int i;
   SampleCountSCI++;

   for(i=0;i<9;i++)
   {
      rec_data[i]=SciaRegs.SCIRXBUF.all;  //接收数据
   }

   Dec=(int)(rec_data[0]-0x30)*100.0+(int)(rec_data[1]-0x30)*10.0+(int)(rec_data[2]-0x30)*1.0
       +(int)(rec_data[4]-0x30)/10.0+(int)(rec_data[5]-0x30)/100.0+(int)(rec_data[6]-0x30)/1000.0;

   SciaRegs.SCIFFRX.bit.RXFIFORESET=0;  //复位FIFO指针
   SciaRegs.SCIFFRX.bit.RXFIFORESET=1;   //重新使能接收FIFO
   SciaRegs.SCIFFRX.bit.RXFFINTCLR=1;    //清除RXFFINT标志位
   PieCtrlRegs.PIEACK.all=0x0100;      //使同组其他中断能够得到响应
    EINT;           // 开全局中断
}


void HexToASCII(float data)
{
   AsciiBuff[0]=(Uint16)(data/100)%10+0x30;   //Chr(48) 0
   AsciiBuff[1]=(Uint16)(data/10)%10+0x30;
   AsciiBuff[2]=(Uint16)((int)(data)%10)+0x30;
   AsciiBuff[3]=46;    //chr(46) .小数点
   AsciiBuff[4]=((int)(data*10))%10+0x30;
   AsciiBuff[5]=((int)(data*100))%10+0x30;
   AsciiBuff[6]=((int)(data*1000))%10+0x30;
   AsciiBuff[7]=9;   //chr(9) 空格
   AsciiBuff[8]=(Uint16)'\0'; //字符串的结尾有一个空符作为结束,不显示

   if(AsciiBuff[0]==48&&AsciiBuff[1]==48)
  {
     AsciiBuff[0]=32;
     AsciiBuff[1]=32;
  }
   if(AsciiBuff[0]==48)
  {
     AsciiBuff[0]=32;
  }

}
array f()
{
   array z;
   int i;
   for(i=0;i<9;i++)
   z.v[i] = AsciiBuff[i];
   return z;
}


最新回复

有问题了  详情 回复 发表于 2016-10-13 16:33
 
点赞 关注

回复
举报

4

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
我先顶一下
 
 

回复

2

帖子

1

TA的资源

一粒金砂(初级)

板凳
 
有问题了
 
 
 

回复

4

帖子

0

TA的资源

一粒金砂(初级)

4
 

问题在哪
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表