请大家帮忙
主机是dsPIC33FJ64GP206 现在想STM8当从机,程序一直调不通
我的中断部分
static u8 sr1;
static u8 sr2;
static u8 sr3;
sr1 = I2C->SR1;
sr2 = I2C->SR2;
sr3 = I2C->SR3;
if (sr2 & (I2C_SR2_WUFH | I2C_SR2_OVR |I2C_SR2_ARLO |I2C_SR2_BERR))
{
I2C->CR2|= I2C_CR2_STOP;
I2C->SR2= 0;
}
if ((sr1 & (I2C_SR1_RXNE | I2C_SR1_BTF)) == (I2C_SR1_RXNE | I2C_SR1_BTF))
{
I2C_byte_received(I2C->DR);
}
if (sr1 & I2C_SR1_RXNE)
{
I2C_byte_received(I2C->DR);
}
if (sr2 & I2C_SR2_AF)
{
I2C->SR2 &= ~I2C_SR2_AF;
I2C_transaction_end();
}
if (sr1 & I2C_SR1_STOPF)
{
I2C->CR2 |= I2C_CR2_ACK;
I2C_transaction_end();
}
/* Slave address matched (= Start Comm) */
if (sr1 & I2C_SR1_ADDR)
{
I2C_transaction_begin();
}
if ((sr1 & (I2C_SR1_TXE | I2C_SR1_BTF)) == (I2C_SR1_TXE | I2C_SR1_BTF))
{
I2C->DR = I2C_byte_write();
}
if (sr1 & I2C_SR1_TXE)
{
I2C->DR = I2C_byte_write();
}
}
有哪里不对的吗?大家帮忙看看
|