Other Parts Discussed in Thread: MOTORWARE, C2000WARE
Hi,
Thanks to your help, I wrote the program that reads gyro x axis degrees using i2c communication.
I based it on example:
C:\ti\c2000\C2000Ware_1_00_06_00\device_support\f2806x\examples\c28\i2c_eeprom
Now I need to paste that code into motorware project (I want to change the speed of my motor by angle of sensor.)
I spent two days on it, and only progress i make is replacing floats data type to _IQ standard.
How can I access to i2c registers in motorware project? (How to write : "I2caRegs.I2CSAR = 0x0068;" ?)
Is it possible not to use API? (it looks very difficult to write and use)
There is another problem - InitI2CGpio(); function makes some pinout setup:
GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0; // Enable pull-up for GPIO32 (SDAA) GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0; // Enable pull-up for GPIO33 (SCLA) GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3; // Asynch input GPIO32 (SDAA) GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 3; // Asynch input GPIO33 (SCLA) GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1; GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1;
How can I do that setup in motorware project?
I attach my code:
void main(void) { InitSysCtrl(); InitI2CGpio(); DINT; //init of i2c: I2caRegs.I2CSAR = 0x0068; // Slave address - EEPROM control code I2caRegs.I2CPSC.all = 35; // Prescaler - need 7-12 Mhz on module clk I2caRegs.I2CCLKL = 10; // NOTE: must be non zero I2caRegs.I2CCLKH = 5; // NOTE: must be non zero I2caRegs.I2CMDR.all = 0x0020; //write to gyro 0x00 to wake it up I2caRegs.I2CSAR = 0x68; //Set slave address I2caRegs.I2CCNT = 2; //Set count to 5 characters plus 2 address bytes I2caRegs.I2CDXR = 0x6B; //register where i will write 0x00 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.I2CDXR = 0x00; //delay loop j=5; for(i = 0; i < 4000; i++){ j++; } for(i = 0; i < 4000; i++){ j--; } for(;;) { I2caRegs.I2CSAR = 0x68; //Set slave address I2caRegs.I2CCNT = 1; //Set count to 1 address bytes I2caRegs.I2CDXR = 0x3B; //Send high address of register to read 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 = 0; //Dont release the bus after Tx I2caRegs.I2CMDR.bit.STT = 1; //Send the start bit, transmission will follow //delay loop j=5; for(i = 0; i < 1000; i++){ j++; } for(i = 0; i < 1000; i++){ j--; } while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out I2caRegs.I2CCNT = 14; //read 14 bytes from eeprom 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 < 14; i++){ while(I2caRegs.I2CSTR.bit.RRDY == 0){}; //I2CDRR not ready to read? RxdData[i] = I2caRegs.I2CDRR; //data reading } //raw data to degrees for(i = 0; i < 7; i++){ GyroData[i] = RxdData[2*i]<<8 | RxdData[(2*i)+1]; } x_acce=(GyroData[0]-333)*1.304347; y_acce=(GyroData[1]-333)*1.304347; z_acce=(GyroData[2]-333)*1.304347; x_angle=((atan2(-y_acce,-z_acce)+M_PI)*180)/M_PI; //delay loop j=5; for(i = 0; i < 60000; i++){ j++; } for(i = 0; i < 60000; i++){ j--; } } }
Regards,
Wojciech