我使用PIC16LF18325 MCU连接到
PCB上的各种传感器。我已经设置了PIN 5(RC4)作为我的SCLK和PIN 8(RC1)作为我的SDA线用于I2C
通信。我使用MPLAB代码配置器V3。当我使用MistWrror或MavigRead时,SCLK/SDA线没有发生任何事情。我在两条线上都有一个拉电阻(10k),时钟线总是很高,当我移除两个上拉电阻时,SCLK线现在总是很低。为什么没有开关,这是我的相关代码:void main(void){SYSTEM_Ini
tialize();I2C2_Initialize();INTERRUPT_GlobalInter.Enable();INTERRUP(1){get压力();}}无效get压力(void){uint8_t状态=0;uint8_t压力_顶=0;uint8_t压力_顶=0;uint8_t压力_mid=0;uint8_t_t压力_mid=0;uint8_t压力_低压_低=0;I2C2_MasterWrite(LPS22_CTRL_REG1,1,LPS_地址,&状态);同时(1){{get压力({get压力();}get压力({get压力();}}}}空get压力(get压力(get压力();}}}空get压力(void)}I2C2_MasterWrite(LPS22_CTRL_REG2,1,LPS_地址,&状态);I2C2_母写I2C2_母写I2C2_母写I2C2_母写I2C2_母写I2C2_母写I2C2_母写LPS22_PREPRESS_PRE_OUT_OUT_XL,1,LPS_地址,&;状态;I2C2_母读I2C2_母读II2C2_母读读I压力低,1,LPS_低压,1,LPS_地址,&;状态;I2LPS_地址,&;状态;(LPS22_PRESS_OUT_L,1,L)PS地址,&状态);I2C2_MasterRead(压力_mid,1,LPS_地址,&;状态);I2C2_Master读(压力_mid,1,LPS_地址,&;状态);I2C2_Mas读读主读(LP_地址,&;地址,&;地址,&;地址;地址);I2C2_MasPSPS地址,&;地址,&;地址;地址;地址;地址;地址;地址;地址;地址;地址;状态);I2C2C2-MasUSART_写入;EUSART_写入;EUSART_写入;EUSART_写入;EUSART_写入;EUSART_写入;EUSART_写入;EUSART_写入
以上来自于百度翻译
以下为原文
I am using a PIC16LF18325 MCU connected to various sensors on a PCB. I have set up pin 5 (RC4) as my SCLK and pin 8 (RC1) as my SDA line for I2C communication.
I am using Mplab Code Configurator v3. When I use masterWrite or MasterRead nothing happens on the SCLK/SDA lines. I had a pull resistor (10k) on both lines and the clock line was always high, when I removed both pull up resistors the SCLK line is always low now.
Why is nothing switching, Here is my relevant code:
void main(void)
{
SYSTEM_Initialize();
I2C2_Initialize();
INTERRUPT_GlobalInterruptEnable();
INTERRUPT_PeripheralInterruptEnable();
while (1)
{
getPressure();
}
}
void
getPressure(void)
{
uint8_t status = 0;
uint8_t pressure_top = 0;
uint8_t pressure_mid = 0;
uint8_t pressure_low = 0;
I2C2_MasterWrite(LPS22_CTRL_REG1, 1, LPS_Address, &status);
I2C2_MasterWrite(0b00000010, 1, LPS_Address, &status);
I2C2_MasterWrite(LPS22_CTRL_REG2, 1, LPS_Address, &status);
I2C2_MasterWrite(0b00011001, 1, LPS_Address, &status);
I2C2_MasterWrite(LPS22_PRESS_OUT_XL, 1, LPS_Address, &status);
I2C2_MasterRead(pressure_low, 1, LPS_Address, &status);
I2C2_MasterWrite(LPS22_PRESS_OUT_L, 1, LPS_Address, &status);
I2C2_MasterRead(pressure_mid, 1, LPS_Address, &status);
I2C2_MasterWrite(LPS22_PRESS_OUT_H, 1, LPS_Address, &status);
I2C2_MasterRead(pressure_top, 1, LPS_Address, &status);
EUSART_Write(pressure_top);
EUSART_Write(pressure_mid);
EUSART_Write(pressure_low);
}