Tool/software: TI C / c++编译器
My problem now is to use the hardware IIC interrupt to read the addresses of more than one register in MPU6050, but I can only read one register now. When I set it to read more than one register, the data will be different from that of the same register. My idea is that tm4c writes multiple registers of MPU6050, writes the data received every time in the interrupt into an array, and finally sorts out the data in the array and sends it to the upper computer with serial port.This is my code.
extern short count;
extern text_num;
extern unsigned char Data[5];
void I2C0SlaveIntHandler()
{
//清除中断标志位
I2CMasterIntClear(I2C0_BASE);
text_num = I2CMasterDataGet(I2C0_BASE);
count=0;
Data[count]=text_num;
count = count + 1;
if (count==6)count=0;
}
void init_write(uint8_t slave_addr,uint8_t reg_addr)
{
I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr,false);
I2CMasterDataPut(I2C0_BASE,reg_addr);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);//TRUE
while(I2CMasterBusy(I2C0_BASE));
I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr,true);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);//TRUE
while(I2CMasterBusy(I2C0_BASE));
}
void Write_MultipleSlave(uint8_t slave_addr,uint8_t reg_addr,uint8_t num)
{
static uint8_t i=0;
for (i=0;i<num;i++)
{
init_write(slave_addr, reg_addr);
reg_addr=reg_addr+1;
}
}
int main(void)
{
//使能FPU
FPUEnable();
FPULazyStackingEnable();
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
Init_MPU6050();
UART0_Init();
while(1)
{
Write_MultipleSlave(MPU6050_Addr,MPU_ACCEL_XOUTH_REG,6);
Acce_x= ((u16) Data[0]<<8)|Data[1];
UART0_Report_Imu(Acce_x,Acce_y,Acce_z,Gyro_x,Gyro_y,Gyro_z,1,1,1,2,2,2);//串口发送
}
}
Looking forward to your help and I would like to ask which country you are from can you use Chinese? My English is so poor that I have to use the translation software every time