ST意法半导体
直播中

康永清

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

stm8s208cb和stm8s105c6t6 I2C通信不起作用

你好,


我想在stm8s208cb(slave)和stm8s105c6t6(master)之间使用I2C通信。我使用stm8s标准外设库。

stm8s105c6t6(主)代码:
- 在虚空主体
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); // 16MHz时钟
I2C_Init(400000,0xA0,I2C_DUTYCYCLE_2,I2C_ACK_CURR,I2C_ADDMODE_7BIT,16); // i2c init
I2C_Cmd(ENABLE);
I2C_GenerateSTART(ENABLE); //发送开始条件
I2C_Send7bitAddress(0x30,I2C_DIRECtiON_TX); //发送写入的从站地址
/ ******************* ******************* /
- 一会儿(1)
I2C_GenerateSTART(ENABLE);
I2C_SendData(0x61);
I2C_GenerateSTOP(ENABLE);

stm8s208cb(slave)代码:
- 在虚空主体
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); // 16MHz系统时钟
I2C_DeInit();
I2C_Init(400000,0x30,I2C_DUTYCYCLE_2,I2C_ACK_CURR,I2C_ADDMODE_7BIT,16);
I2C_Cmd(ENABLE);
- 一会儿(1)
uint8_t RxBuffer = I2C_ReceiveData();

但它不起作用。求救,谢谢!
#i2c#stm8#i2c-example

以上来自于谷歌翻译


以下为原文




Hello,


I want to use I2C communication between stm8s208cb(slave) and stm8s105c6t6(master). I use stm8s standard peripheral library.

stm8s105c6t6(master) code:
-in the void main
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); //16MHz clock
I2C_Init(400000, 0xA0, I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_7BIT, 16); //i2c init
I2C_Cmd(ENABLE);
I2C_GenerateSTART(ENABLE); //send start condition
I2C_Send7bitAddress(0x30, I2C_DIRECTION_TX); //send slave address for write
/********************************************************************/
-in the while(1)
I2C_GenerateSTART(ENABLE);
I2C_SendData(0x61);
I2C_GenerateSTOP(ENABLE);

stm8s208cb(slave) code:
-in the void main
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); //16MHz System Clock
I2C_DeInit();
I2C_Init(400000, 0x30, I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_7BIT, 16);
I2C_Cmd(ENABLE);
-in the while(1)
uint8_t RxBuffer = I2C_ReceiveData();

But it does not work. Help please, thank you!  
#i2c #stm8 #i2c-example

回帖(1)

毛雅清

2018-10-22 16:44:06
亲爱的sakarya.erhan,
 
 
首先调试主机,如果它为init,start和stopn生成正确的波形。您可以在CRO或逻辑分析仪上看到主CLK和DATA引脚。
 
/*请
 如果这篇文章可以帮助您或解决您的问题。* /
 
/ **免责声明** /
 
/ *我不是ST技术支持团队的成员。因此,请在您的最后验证/测试任何支持/建议。* /
 
/ *此帖仅用于一般支持目的,不收取任何费用。如果您需要任何个人支持,请联系
embeddeddesign.help@gmail.com
 
* /

以上来自于谷歌翻译


以下为原文





Dear sakarya.erhan,


First debug your master, if it is generating correct waveform for init, start and stopn. You can see the master CLK and DATA pin on CRO or Logic Analyzer.

/*Please
if this post helps you or solves your problem.*/

/**disclaimer**/

/* I am not a person from ST Technical Support Team. So please verify/test any support/suggestion at your end.*/

/* This post is only for general support purpose and free of any charge.If you need any personal support for your work please contact at
embeddeddesign.help@gmail.com

*/
举报

更多回帖

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