完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,所有STM社区,
首先,我为我的英语道歉,我的语言水平相当基本。也就是说,当我写这篇文章时,我将继续解释原因。 我是西班牙语的学生,我正在开发一个带有演示板stm8l发现的proyect。对于这个项目,我需要将MCU与外部ADC通信,因为我需要18位分辨率。 所以我试图用MCP3424(从机)与STM8L DISCOVERY(主机)通信。 升级I2C协议,首先我检查I2C总线不再忙,接下来,我发送启动条件。问题是在发送启动条件后,SDA变为低电平(正确)但SCL也变为低电平且没有产生时钟信号,SCL持续低电平。 我试图改变I2C总线的频率,上拉电阻是正确的,芯片不是borken。我使用的启动条件函数如下: / *此函数发出开始条件和 *发送从机地址+ R / W位 * *参数: * I2Cx - > I2C外设,例如I2C1 *地址 - > 7位从机地址 *方向 - >传输方向可以是: *主发送器模式的I2C_Direction_Tranmitter *主接收器的I2C_Direction_Receiver * / void I2C_start(I2C_TypeDef * I2Cx,uint8_t address,uint8_t direction){ //等到I2C1不再忙 while(I2C_GetFlagStatus(I2Cx,I2C_FLAG_BUSY)); //发送I2C1 START条件 I2C_GenerateSTART(I2Cx,ENABLE); //等待I2C1 EV5 - >奴隶已承认开始状况 while(!I2C_CheckEvent(I2Cx,I2C_EVENT_MASTER_MODE_SELECT)); //发送从站地址进行写入 I2C_Send7bitAddress(I2Cx,地址,方向); / *等待I2C1 EV6,检查是否 * Slave已经确认Master发射器或 *主接收器模式,取决于传输 *方向 * / if(direction == I2C_Direction_Transmitter){ while(!I2C_CheckEvent(I2Cx,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); } 否则if(direction == I2C_Direction_Receiver){ while(!I2C_CheckEvent(I2Cx,I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); } } 发送奴隶adrees后功能正在等待,显然,beouse它不是时钟。 (我用示波器测量过)。 如果有人试图帮助我,我将不胜感激。 来自西班牙的问候, JuanCristóbal 以上来自于谷歌翻译 以下为原文 Hello all STM comunity, First of all my apologies for my English, my language level is rather basic yet. That said, I will proceed to explain te reasons as I am writing this post. I am a Spanish estudent and I am developing a proyect with the demo board stm8l discovery. For this proyect I need to comunicate the MCU with an external ADC, becouse I need a 18-bit resolution. So I am trying to comunicate STM8L DISCOVERY (master) with MCP3424 (Slave). Folowing I2C protocol, at first I check that the I2C bus is not busy anymore and next, I send the start condition. The problem is that after I send the start condition, SDA goes low (that its correct) but SCL goes lo too and no clock signal is generated, SCL is low level constantly. I have tried to change the I2C bus frecuency, the pull up resistor are correct, and the chip is not borken. The start condition function that I´m using as follows: /* This function issues a start condition and * transmits the slave address + R/W bit * * Parameters: * I2Cx --> the I2C peripheral e.g. I2C1 * address --> the 7 bit slave address * direction --> the tranmission direction can be: * I2C_Direction_Tranmitter for Master transmitter mode * I2C_Direction_Receiver for Master receiver */ void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction){ // wait until I2C1 is not busy anymore while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY)); // Send I2C1 START condition I2C_GenerateSTART(I2Cx, ENABLE); // wait for I2C1 EV5 --> Slave has acknowledged start condition while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT)); // Send slave Address for write I2C_Send7bitAddress(I2Cx, address, direction); /* wait for I2C1 EV6, check if * either Slave has acknowledged Master transmitter or * Master receiver mode, depending on the transmission * direction */ if(direction == I2C_Direction_Transmitter){ while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); } else if(direction == I2C_Direction_Receiver){ while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); } } The function is waiting ack after send the slave adrees, is obvious, beouse it is not clock. (I have measured whit an oscilloscope). I would be ver grateful if someone trying to help me. Greetings from Spain, Juan Cristóbal |
|
相关推荐
1个回答
|
|
嗨娟,
此回复是在多年之后发生的,因此这可能不符合您的目的。我最近开始研究STM8L并遇到了一些I2C问题,这就是我进入这个页面的原因。这可能会为其他一些工作类似的人服务。 面对你所面临的问题,为了正确使用函数''I2C_Send7bitAddress',我们应该将地址移位一位。我不知道它是否是库函数中的错误,或者他们希望我们改变自己。无论如何,在调用此函数之前需要左移。 一行解决方案: I2C_Send7bitAddress(I2Cx,地址&lt;&lt; 1,方向); 其次,我们应该指定一个读或写请求以及7位地址。如果LSB为'0',则它指定对从设备的写请求。如果LSB为'1',则它指定对从设备的读请求。 因此解决方案在一行: I2C_Send7bitAddress(I2Cx,地址&lt;&lt; 1&amp; 0xFE,方向); //用于写请求 I2C_Send7bitAddress(I2Cx,地址&lt;&lt; 1 | 0x01,方向); //用于读取请求 很高兴成为这个庞大社区的一员。 以上来自于谷歌翻译 以下为原文 Hi Juan, This reply comes after years and thus this may not serve your purpose. I started working on STM8L recently and came across some problems with I2C and that is what led me to this page. This may serve some others working in similar lines. Coming to the problem that you are facing, in order to use the function ''I2C_Send7bitAddress'' properly we should left shift the address by one bit. I don't know if it is a bug in the library function or they expect us to do the shifting our self. Anyway a left shift is required before calling this function. Solution in one line: I2C_Send7bitAddress( I2Cx, address << 1, direction ); Second is that, we should specify a read or write request along with the 7 bit address. If the LSB is '0', it specifies a write request to the slave device. If the LSB is '1', it specifies a read request to the slave device. Thus solution in one line: I2C_Send7bitAddress( I2Cx, address << 1 & 0xFE, direction ); // for write request I2C_Send7bitAddress( I2Cx, address << 1 | 0x01, direction ); // for read request Happy to be part of this huge community. |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
1582 浏览 1 评论
2265 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1518 浏览 1 评论
2889 浏览 6 评论
5393 浏览 21 评论
393浏览 4评论
653浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
295浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
742浏览 3评论
613浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-5-11 07:32 , Processed in 0.856573 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号