你好,
我想在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_DIREC
tiON_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