初级会员
- 积分
- 138
- 金钱
- 138
- 注册时间
- 2016-3-13
- 在线时间
- 40 小时
|
1金钱
采用用两块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
}
|
最佳答案
查看完整内容[请看2#楼]
问题已经解决。stm8s005的PB4,PB5的默认是作为ADC通道的,要想作为硬件IIC的使用的话 是要进行remap的 ,即要对flash进行操作。stm8s003的话是不用的。
|