采用用两块STM8S003通过硬件IIC进行主从机通讯,已经能够进行正常的通讯;可是将程序移植到两块STM8S005上就不行了 我想问一下 这个是什么问题;我的程序是参考了ST官网的例程:主机程序如下:int IIC_send_DATA_num;void I2C_WriteRegister(u8 u8_NumByteToWrite, u8 Slave_Address)
{
IIC_send_DATA_num = 2;
while((I2C->SR3 & 2)) // Wait while the bus is busy
{
I2C->CR2 |= I2C_CR2_STOP; // STOP=1, generate stop
while((I2C->CR2 & I2C_CR2_STOP)) ; // wait until stop is performed
}
I2C->CR2 |= 1; // START=1, generate start
while(((I2C->SR1 & 1)==0)); // Wait for start bit detection (SB)
delay_us(3); // SB clearing sequence
#ifdef TEN_BITS_ADDRESS // TEN_BIT_ADDRESS decalred in I2c_master_poll.h
I2C->DR = (u8)(((Slave_Address >> 7) & 6) | 0xF0); // Send header of 10-bit device address (R/W = 0)
while(!(I2C->SR1 & 8)); // Wait for header ack (ADD10)
I2C->DR = (u8)(Slave_Address); // Send lower 8-bit device address & Write
#else
I2C->DR = (u8)(Slave_Address << 1); // Send 7-bit device address & Write (R/W = 0)
#endif
while(!(I2C->SR1 & 2)); // Wait for address ack (ADDR)
delay_us(3); // ADDR clearing sequence
I2C->SR3; // send Offset command
while(!(I2C->SR1 & 0x80));
I2C->DR = IIC_send_ceshi[u8_NumByteToWrite];
while(((I2C->SR1 & 0x84) != 0x84)); // Wait for TxE & BTF
delay_us(3); // clearing sequence
I2C->CR2 |= 2; // generate stop here (STOP=1)
while((I2C->CR2 & 2)); // wait until stop is performed
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>