hallo,
habs jetzt hinbekommen und falls mal jemand den BMA020 mit TI C2000 DSPs nutzen will poste ich mal meinen, durchaus verbesserungswürdigen, Code, welcher hier bereits gepostete Codeschnipsel enthält.
Code:
//I2C test
#include "DSP280x_Device.h" // DSP280x Headerfile Include File
#include "DSP280x_Examples.h" // DSP280x Examples Include File
// Prototype statements for functions found within this file.
void I2CA_Init(void);
int Values[6]={0,0,0,0,0,0};
Uint16 instr=0x02;
int i,dx=0,dy=0,dz=0;
double D2G,gx=0,gy=0,gz=0;
void main(void)
{
InitSysCtrl(); // Step 1. Initialize System Control:
InitI2CGpio(); // Step 2. Initalize GPIO only for I2C functionality
I2CA_Init(); // Step 4. Initialize all the Device Peripherals
D2G=0.00390625; // 4g/1024
for(;;) // Application loop
{
I2caRegs.I2CSAR = 0x38; //Set slave address
I2caRegs.I2CCNT = 1; //Set count to 1 Byte for instr 0x02
I2caRegs.I2CDXR = 0x02; //Send instr
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; //Stop when internal counter becomes 0
I2caRegs.I2CMDR.bit.STT = 1; //Send the start bit, transmission will follow
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out
I2caRegs.I2CCNT = 6; //read 6 bytes from sensor
I2caRegs.I2CMDR.bit.TRX = 0; //Set to Recieve mode
I2caRegs.I2CMDR.bit.MST = 1; //Set to Master mode
I2caRegs.I2CMDR.bit.FREE = 1; //Run in FREE mode
I2caRegs.I2CMDR.bit.STP = 1; //Stop when internal counter becomes 0
I2caRegs.I2CMDR.bit.STT = 1; //Repeated start, Reception will follow
for(i = 0; i < 6; i++)
{
while(I2caRegs.I2CSTR.bit.RRDY == 0){}; //I2CDRR not ready to read?
Values[i] = I2caRegs.I2CDRR;
}
DELAY_US(100); //wait for new data provided
dx=Values[0]; //dataadaptation by malthy & Sternthaler
dx=(dx|((Values[1]<<8))>>6);
gx=dx*D2G;
dy=Values[2];
dy=(dx|((Values[3]<<8))>>6);
gy=dy*D2G;
dz=Values[4];
dz=(dx|((Values[5]<<8))>>6);
gz=dz*D2G;
} // end of for(;;)
} // end of main
void I2CA_Init(void)
{
I2caRegs.I2CSAR = 0x38; // Slave address - EEPROM control code
I2caRegs.I2CPSC.all = 6; // Prescaler - need 7-12 Mhz on module clk for 60MHz CPU
I2caRegs.I2CCLKL = 42; // NOTE: must be non zero
I2caRegs.I2CCLKH = 21; // NOTE: must be non zero
I2caRegs.I2CIER.all = 0x3E; // Enable SCD,XRDY,RRDY,ARDY,NACK interrupts
I2caRegs.I2CMDR.bit.IRS = 1; // Take I2C out of reset, Stop I2C when suspended
I2caRegs.I2CFFTX.all = 0x0000; // Enable FIFO mode and TXFIFO
I2caRegs.I2CFFRX.all = 0x0000; // Enable RXFIFO, clear RXFFINT,
return;
}
//EOF
An der Stelle nochmals danke an die "Code-Sponsoren".
Das einzige was mich im Betrieb stört ist, dass die Ergebnisse nicht konstant bleiben selbst wenn ich den Sensor fest einspanne. Dabei treten manchmal Sprünge von bis zu 0.5g auf, was für meine anschließende Aufgabe tötlich sein wird. Hat schon mal jemand in dem Zusammenhang mit den Filtern rumgespielt ?
Lesezeichen