发 帖  
原厂入驻New
申请华秋企业认证 多层板首单免费打样!
30s提交资料,10分钟通过审核(免费赔付+顺丰包邮)>>立即报名
[问答] SCLK线总是很低该怎么办?
126 MCU 传感器 SDA
分享
我使用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);

}
0
2019-7-22 13:24:28   评论 分享淘帖 邀请回答

相关问题

11个回答
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:43:51 评论

举报

代码配置器为您这样做吗?我自己没有更改任何寄存器

以上来自于百度翻译


      以下为原文

    Does the code configurator do this for you? I didn't change any registers myself
2019-7-22 13:55:36 评论

举报

这就是为什么发布所有代码有帮助的原因。在代码中的赋值语句中查找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:00:58 评论

举报

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?
2019-7-22 14:19:36 评论

举报

这里是关于我的I2C配置寄存器的进一步信息:SSP2CON1= 0x28 SSP2STAT=0x00 SSP2CON3=0x00 SSP2ADAD= 0x03

以上来自于百度翻译


      以下为原文

    Here is further information on my I2C configuration registers:
 
SSP2CON1 = 0x28
SSP2STAT = 0x00
SSP2CON3 = 0x00
SSP2ADD   = 0x03
2019-7-22 14:28:55 评论

举报

事实上,我认为你已经颠倒过来了,在TrISX寄存器中设置为“1”的比特对应于输入状态的I/O引脚。

以上来自于百度翻译


      以下为原文

   
Actually I think you have it reversed, bits set to a "1" in the TRISx register correspond to I/O pins that are in the INPUT state.
2019-7-22 14:35:32 评论

举报

你好[link=mailto:Jack@kk.,]Jack@kk.,[/link]我想到了,我把TRISC寄存器改为0x18,但是仍然没有工作。RC4PPS寄存器很好,还有RC1PPS。我不明白为什么这不会起作用。时钟线总是飘得很高,我用的是一个10K的上拉电阻。还有其他想法吗?

以上来自于百度翻译


      以下为原文

    Hello [link=mailto:Jack@kksound,]Jack@kksound,[/link]
 
I figured that and I changed the TRISC register to 0x18, and it still didn't work.
The RC4PPS register is fine, RC1PPS as well. I cannot figure out why this won't work.
 
The clock line always floats high, I am using a 10k pull up resistor. Any other ideas?
2019-7-22 14:53:52 评论

举报

在TISISC寄存器0x18寄存器RC3和RC4作为输入,所有其他作为输出。你可能需要RC4作为输出来获得SCLK信号吗?

以上来自于百度翻译


      以下为原文

    A 0x18 in the TRISC register sets RC3 and RC4 as INPUTS, all others as outputs. Possibly you need RC4 as an output to get SCLK signals?
2019-7-22 15:06:06 评论

举报

I2C信号都应该配置为输入和输出——它们都是双向的。有关详细信息,请参阅数据表。

以上来自于百度翻译


      以下为原文

    Both I2C signals should be configured as inputs and outputs - they're both bidirectional.  See the Data Sheet for details.
2019-7-22 15:24:04 评论

举报

不确定如何将单个I/O引脚设置为输入和输出。如果你的意思是I2C输入函数和输出函数需要映射到同一个PIN,那么是的。以下是来自I2C模式下TRIS寄存器设置的数据表:添加斜体。这里是关于在同一引脚上选择输入和输出函数的说明:

以上来自于百度翻译


      以下为原文

   
Not sure how a single I/O pin can be set as both input and output. If you mean that the I2C input function and output function need to be mapped to the same pin then yes. Here is from the data sheet on the TRIS register setting in I2C mode : italics added.
Here is the note on selecting both input and output functions on the same pin:

 
2019-7-22 15:32:35 评论

举报

所以我来回切换寄存器,I2C仍然没有做任何事情。我调用I2C函数的方式有什么不对吗?它确实正在初始化,但是接下来我所做的就是这个,uint8_t状态=0;uint8_t压力_top=0;uint8_t压力_mid=0;uint8_t压力_low=0;I2C2_MasterWrite(LPS22_CTRL_REG1,1,LPS_Address,&status);I2C2_MasterWrite(0b00000000010,1,LPS_Address,&status);I2C2_MasterWriteLPS22_CTRL_REG2,1,LPS_地址,&状态;I2C2_主写(0b00000011001,1,LPS_地址,&状态);I2C2_主写(0b00000000011001,1,LPS_地址,&状态);I2C2_主写(LPS22_PRESS_PRESS_PRESS_OUT_OUT_XL,1,LPS_地址,&状态);I2C2_主读(I2C2_主读(压力_低压_低,1,LPS_地址,&状态);I2C2_主读(压力_低压_低压_低压,1,LPS_地址,&状态;状态);I2C2_1、LPS_Address、&status;I2C2_MasterRead(._mid,1,LPS_Address,&status);I2C2_MasterWrite(LPS22_PRESS_OUT_H,1,LPS_Address,&status);I2C2_MasterRead(._top,1,LPS_Address,&status);MasterWrite/Read函数如下:void I2C2_MasterWrite(uint8_t*pdata,uint8_t长度,uint16_t地址)。s s,I2C2_MESSAGE_STATUS*pflag){静态I2C2_TRANSAC._REQUEST_BLOCK trBlock;//如果(i2c2_object.tr..s..!{I2C2_MasterWritETRBBuild(&trBlock,pdata,长度,地址);I2C2_MasterTRBINSert(1,&trBlo块,p标志);}其他{{pflag*pflag=I2C2_MasC2_MasSSAGE_I2C2_MasSSAGE_I2C2_I2C2_MESSAGE_MESSAGE_MESSAGE_FAIL.}}}}无效I2C2 I2C2_MasterRead I2C2 I2C2_Master读取I2C2(uint8_t*t8_t*pdata,uint8_t8_t*t数据,uint8_t8_t8_t I2C2_TRANSAC._REQUEST_BLOCK tRbBug;//检查队列中是否有空间(I2C2Objut.TrStasU.S.Purror)!=true){I2C2_MasterReadTRBBuild(&trBlock,pdata,.,address);I2C2_MasterTRBInsert(1, &trBlock,pflag);}.{*pflag=I2C2_MESSAGE_FAIL;}

以上来自于百度翻译


      以下为原文

    So I switched around the registers back and forth and still the I2C is not doing anything. Is there something wrong with the way I am calling the I2C functions? It is definitely being initialized but then all I do is this,
 
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);
 
And the MasterWrite/Read functions are here:
 
void I2C2_MasterWrite(
uint8_t *pdata,
uint8_t length,
uint16_t address,
I2C2_MESSAGE_STATUS *pflag)
{
static I2C2_TRANSACTION_REQUEST_BLOCK trBlock;
// check if there is space in the queue
if (i2c2_object.trStatus.s.full != true)
{
I2C2_MasterWriteTRBBuild(&trBlock, pdata, length, address);
I2C2_MasterTRBInsert(1, &trBlock, pflag);
}
else
{
*pflag = I2C2_MESSAGE_FAIL;
}
}
void I2C2_MasterRead(
uint8_t *pdata,
uint8_t length,
uint16_t address,
I2C2_MESSAGE_STATUS *pflag)
{
static I2C2_TRANSACTION_REQUEST_BLOCK trBlock;

// check if there is space in the queue
if (i2c2_object.trStatus.s.full != true)
{
I2C2_MasterReadTRBBuild(&trBlock, pdata, length, address);
I2C2_MasterTRBInsert(1, &trBlock, pflag);
}
else
{
*pflag = I2C2_MESSAGE_FAIL;
}
}
2019-7-22 15:50:03 评论

举报

只有小组成员才能发言,加入小组>>

57个成员聚集在这个小组

加入小组

创建小组步骤

关闭

站长推荐 上一条 /10 下一条

快速回复 返回顶部 返回列表