TI中文支持网
TI专业的中文技术问题搜集分享网站

ads1110数据转换

用dsp28335采集三路传感器数据,用三路ads1110进行AD转换,写入控制字为0x8C,在采集数据时,回采控制字时,0x8C中夹杂着0xC,这是为什么

KW X:

亲;建议查下竞争。

Zhiyong Chen3:

回复 KW X:

能帮我详细的讲一下吗,万分感激,我的程序上都是等待上一路采集完才开始下一路的采集,I2C模块程序附在下面。

还有一个现象是:

                     采集出的数据顺序和技术手册上也不一样,

                            技术手册上:第三个字节是控制字,

                           我采集出的控制字是第二个字节。

#include "DSP2833x_Device.h" // Headerfile Include File#include "DSP2833x_Examples.h" // Examples Include File

/*****************************IIC通信程序*******************************/Uint16 HighDate=0;Uint16 LowDate=0;Uint16 ContDate=0;

struct I2cmsg *CurrentMsgPtr; // Used in interrupts

/*****************************IIC初始化*******************************/void I2CA_Init(void){ //I2caRegs.I2CSAR = I2C_SLAVE_ADDR; // Slave address – EEPROM control code

#if (CPU_FRQ_150MHZ) // Default – For 150MHz SYSCLKOUT I2caRegs.I2CPSC.all = 14; // Prescaler – need 7-12 Mhz on module clk (150/15 = 10MHz) #endif #if (CPU_FRQ_100MHZ) // For 100 MHz SYSCLKOUT I2caRegs.I2CPSC.all = 9; // Prescaler – need 7-12 Mhz on module clk (100/10 = 10MHz) #endif

I2caRegs.I2CCLKL = 10; // NOTE: must be non zero I2caRegs.I2CCLKH = 5; // NOTE: must be non zero I2caRegs.I2CIER.all = 0x28; // Enable SCD & ARDY interrupts

I2caRegs.I2CMDR.all = 0x0020; // Take I2C out of reset // Stop I2C when suspended

I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO I2caRegs.I2CFFRX.all = 0x2060; // Enable RXFIFO, clear RXFFINT,

return;}

Uint16 I2CA_WriteData(struct I2cmsg *msg){ Uint16 i;

// Wait until the STP bit is cleared from any previous master communication. // Clearing of this bit by the module is delayed until after the SCD bit is // set. If this bit is not checked prior to initiating a new message, the // I2C could get confused. if (I2caRegs.I2CMDR.bit.STP == 1) { return I2C_STP_NOT_READY_ERROR; }

// Setup slave address I2caRegs.I2CSAR = msg->SlaveAddress;

// Check if bus busy if (I2caRegs.I2CSTR.bit.BB == 1) { return I2C_BUS_BUSY_ERROR; }

// Setup number of bytes to send // MsgBuffer I2caRegs.I2CCNT = msg->NumOfBytes; // Setup data to send for (i=0; i<msg->NumOfBytes; i++) { I2caRegs.I2CDXR = *(msg->MsgBuffer+i); } // Send start as master transmitter I2caRegs.I2CMDR.all = 0x6E20;

return I2C_SUCCESS;}

Uint16 I2CA_ReadData(struct I2cmsg *msg){

if (I2caRegs.I2CMDR.bit.STP == 1) { return I2C_STP_NOT_READY_ERROR; } I2caRegs.I2CSAR = msg->SlaveAddress; if (I2caRegs.I2CSTR.bit.BB == 1) { return I2C_BUS_BUSY_ERROR; }

I2caRegs.I2CCNT = msg->NumOfBytes; // Setup how many bytes to expect I2caRegs.I2CMDR.all = 0x2C20; // Send restart as master receiver

return I2C_SUCCESS; }

interrupt void i2c_int1a_isr(void) // I2C-A{ Uint16 IntSource, i;

IntSource = I2caRegs.I2CISRC.all;// Read interrupt source

// Interrupt source = stop condition detected if(IntSource == I2C_SCD_ISRC) { // If completed message was writing data, reset msg to inactive state if (CurrentMsgPtr->MsgStatus == I2C_MSGSTAT_WRITE_BUSY) { CurrentMsgPtr->MsgStatus = I2C_MSGSTAT_INACTIVE; } } else if (I2caRegs.I2CFFTX.bit.TXFFINT == 1) { if (I2caRegs.I2CSTR.bit.NACK == 1) { I2caRegs.I2CMDR.bit.STP = 1; I2caRegs.I2CSTR.all = I2C_CLR_NACK_BIT; } else if(CurrentMsgPtr->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP_BUSY) { for(i=0; i < CurrentMsgPtr->NumOfBytes; i++) { CurrentMsgPtr->MsgBuffer[i] = I2caRegs.I2CDRR; } LowDate=CurrentMsgPtr->MsgBuffer[0]; ContDate=CurrentMsgPtr->MsgBuffer[1]; HighDate=CurrentMsgPtr->MsgBuffer[2]; CurrentMsgPtr->MsgStatus = I2C_MSGSTAT_SEND_NOSTOP; I2caRegs.I2CFFTX.bit.TXFFINT == 1; } } else { // Generate some error due to invalid interrupt source asm(" ESTOP0"); }

// Enable future I2C (PIE Group 8) interrupts PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;} /////////////////////////////////// ///////////I2C 数据读取////////////// /////////////////////////////////// int16 I2C_ADread(struct I2cmsg *msg) { int16 advalue=0; // Check outgoing message status. Bypass read section if status is // not inactive. //while(I2cMsgIn2.MsgStatus == I2C_MSGSTAT_SEND_NOSTOP); if(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP) { // Check incoming message status. // EEPROM address setup portion while(I2CA_ReadData(msg) != I2C_SUCCESS) { } // Update current message pointer and message status CurrentMsgPtr = msg; msg->MsgStatus = I2C_MSGSTAT_SEND_NOSTOP_BUSY; } while(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP_BUSY); advalue=(HighDate<<8)|LowDate; return advalue; } /////////////////////////////////// ///////////I2C 写控制字 //////// ///////////////////////////////////void I2C_WriteCont(struct I2cmsg *msg) { Uint16 Error; if(msg->MsgStatus == I2C_MSGSTAT_SEND_WITHSTOP) { Error = I2CA_WriteData(msg); if (Error == I2C_SUCCESS) { CurrentMsgPtr = msg; msg->MsgStatus = I2C_MSGSTAT_WRITE_BUSY; } while(msg->MsgStatus == I2C_MSGSTAT_WRITE_BUSY); } }

赞(0)
未经允许不得转载:TI中文支持网 » ads1110数据转换
分享到: 更多 (0)