项目使用的芯片为MK10DN512VMC10。 正在尝试初始化 I2C 模块,以便和我的FXOS8700CQ 6轴传感器进行通讯 该传感器为4位加速度传感器和16位磁力计与高性能ASIC结合在一起 典型的方向分辨率为0.1°,罗盘方位精度误差小于5°
目前完成了IIC初始化,但一直无法和陀螺仪进行正常的通讯 用示波器进行监视,没能在示波器上看到 SCL 方波 当尝试写入 I2C 寄存器时,系统遇到hard fault
FXOS8700CQ的描述如下:
2.初始代码部分 #define I2C_Frequency_Divider_register__I2C1_F (*(uint32_t *)0x40067001U) #define I2C_Control_Register_1__I2C1_C1 (*(uint32_t *)0x40067002U) #define I2C_Status_Register__I2C1_S (*(uint32_t *)0x40067003U) #define Pin_Control_Register_n__PORTE_PCR0 (*(uint32_t *)0x4004D000U) #define Pin_Control_Register_n__PORTE_PCR1 (*(uint32_t *)0x4004D004U) #define System_Clock_Gating_Control_Register_4_SIM_SCGC4 (*(uint32_t *)0x40048034U) #define System_Clock_Gating_Control_Register_5_SIM_SCGC5 (*(uint32_t *)0x40048038U) void mcu_Initialise() { Pin_Control_Register_n__PORTE_PCR0 = 0x00000620U; Pin_Control_Register_n__PORTE_PCR1 = 0x00000620U; System_Clock_Gating_Control_Register_4_SIM_SCGC4 |= 0x00000080U; System_Clock_Gating_Control_Register_5_SIM_SCGC5 |= 0x00002000U; } void intitialiseI2C() { I2C_Frequency_Divider_register__I2C0_F |= 0x29U; //writing to this register takes the system into hard fault I2C_Control_Register_1__I2C1_C1 |= 0x80; } int main(void) { BOARD_InitBootPins(); BOARD_InitBootClocks(); mcu_Initialise(); intitialiseI2C(); }手册上面的地址如上图: 命令发送顺序如下:
4. 更新code按照上面的顺序,对程序进行了修改, 但是未能从 I2C 模块FXOS8700 中获取 我需要的值,
I2C 模块的电源电压为 5V。 在对 mcu 进行编程之前,SCL 和 SDA 线均以接地为基准测量 5 伏。 然后当在调试时,将示波器连接到 I2C 总线,电压从 5V 下降到 3.75V, 并在代码中复用 PortD 时保持在那里。
即使 mcu 和模块之间没有数据传输, 不应该在 scl 线上看到方波吗? 在状态寄存器没有更新参数。
下面为更新后的code:
Printing “ReceivedByte” array on tera term shows wrong WhoAmI value uint8_t Receivedbyte[3]; uint8_t WhoAmI_address[1] = {0x0D}; size_t RegSize = 1; void Mcu_Initialise() { PORTD->PCR[8] = 0x01000000; //clear the ISF flag PORTD->PCR[9] = 0x01000000; //clear the ISF flag PORTD->PCR[8] |= 0x00000200; //mux PTD8 for I2C0_SCL PORTD->PCR[9] |= 0x00000200; //mux PTD9 for I2C0_SDA SIM->SCGC4 |= SIM_SCGC4_I2C0_MASK; // I2C0 clock SIM->SCGC5 |= 0x00002000U; //portD //Im not sure about the following two lines EnableIRQ(I2C0_IRQn); NVIC_SetPriority(I2C0_IRQn,0); } void I2C_Initialise() { I2C0->A1 = 0; I2C0->F = 0; I2C0->C1 = 0; I2C0->S = 0xFFU; I2C0->C2 = 0; I2C0->S |= I2C_S_IICIF_MASK ; //clear IICIF I2C0->F = 0x27U; //bus clock is 48MHz, calculated baud rate for 100khz I2C0->C1 = I2C_C1_IICEN_MASK; //I2C0->C1 |= I2C_C1_IICIE_MASK; // When I enable this interrupt the system gets stuck in CLOCK_GetOutClkFreq() function. When I disable it Im able to run my code from mcu_initialise() to Read() void StartCondition() { I2C_MasterStart(I2C0, FXOS8700CQ_Address, kI2C_Write); } void StartRepeat() { I2C_MasterRepeatedStart(I2C0, FXOS8700CQ_Address, kI2C_Read); } void sendRegister() { I2C_MasterWriteBlocking(I2C0, WhoAmI_address, RegSize, kI2C_TransferNoStopFlag); } void Read() { I2C_MasterReadBlocking(I2C0,ReceivedByte, RegSize, kI2C_TransferNoStartFlag); } int main() { BOARD_InitPins(); __disable_irq(); InitVersion(); /* Init board hardware. */ BOARD_InitBootPins(); BOARD_InitBootClocks(); BOARD_InitBootPeripherals(); mcu_Initialise(); intitialiseI2C(); StartCondition(); sendRegister(); StartRepeat(); Read(); }免责声明:文章内容来自互联网,本站不对其真实性负责,也不承担任何法律责任,如有侵权等情况,请与本站联系删除。
转载请注明出处:MK10DN512VMC10主控陀螺仪调试记录 https://www.yhzz.com.cn/a/11739.html