Microchip
直播中

王敏

7年用户 245经验值
私信 关注
[问答]

SCLK线总是很低该怎么办?

我使用PIC16LF18325 MCU连接到PCB上的各种传感器。我已经设置了PIN 5(RC4)作为我的SCLK和PIN 8(RC1)作为我的SDA线用于I2C通信。我使用MPLAB代码配置器V3。当我使用MistWrror或MavigRead时,SCLK/SDA线没有发生任何事情。我在两条线上都有一个拉电阻(10k),时钟线总是很高,当我移除两个上拉电阻时,SCLK线现在总是很低。为什么没有开关,这是我的相关代码:void main(void){SYSTEM_Initialize();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);

}

回帖(11)

tijing忽忽

2019-7-22 13:43:51
PORTC具有模拟功能,您是否为这些引脚上的数字I/O配置了ANSELC-SFR?

以上来自于百度翻译


      以下为原文

    PORTC has analog functions, have you configured the ANSELC SFR correctly for digital I/O on these pins?
举报

曹光辉

2019-7-22 13:55:36
代码配置器为您这样做吗?我自己没有更改任何寄存器

以上来自于百度翻译


      以下为原文

    Does the code configurator do this for you? I didn't change any registers myself
举报

tijing忽忽

2019-7-22 14:00:58
这就是为什么发布所有代码有帮助的原因。在代码中的赋值语句中查找ANSELC寄存器名。

以上来自于百度翻译


      以下为原文

    This is why posting ALL the code helps. Look for the ANSELC register name in an assignment statement in the code.
举报

曹光辉

2019-7-22 14:19:36
ANSELC寄存器设置为0x5,或者在其他方面,RC4(SCLK)和RC1(SDA)都被设置为数字I/O引脚。一定是别的什么地方出错了。我刚看过我的TRISC寄存器,我说它是0x38,这意味着RC3、RC4和RC5被设置为输出引脚,其他的都是输入。奇怪的部分是我使用RC5,RC2,和RC0作为SPI工作完美。如果TISC寄存器将它们设置为输入,那么它如何作为数字输出引脚工作呢?

以上来自于百度翻译


      以下为原文

    The ANSELC register is set to 0x5, or in other worsd both RC4 (SCLK) and RC1 (SDA) are set to digital i/o pins. It must be something else that is wrong. 
 
I just looked at my TRISC register I said it is 0x38, which would mean that RC3, RC4, and RC5 are set as output pins and the others are all inputs. The strange part is I use RC5, RC2, and RC0 as SPI which works perfectly. How can that work as digital output pins if the TRISC register has them set to inputs?
举报

更多回帖

发帖
×
20
完善资料,
赚取积分