STM8 I2C仿真上遇到的問題
請問各位高手,以下的程式是針對STM8-128-EVAL demonstration firmware去修改的環境是使用stvd 4.3.2
在仿真過程中,只有第一次剛送電仿真的時,程式可以順利執行過紅字的部分
但是如果chip reset之後,程式執行都會停在紅字的部分,請問該如何解決??
另外有哪些暫存器會影響I2C_SR1的START BIT的變化,由於是參考原廠提供的LIBRARY修改的
沒道理START bit不會enable阿 疑問....
void Read_HAF(void)
{
uint8_t i = 0x00;
uint8_t j = 0x00;
I2C_Cmd( ENABLE);
/* Re-send start & wait event detection */
I2C_GenerateSTART(ENABLE);
j=I2C->SR1;
while(!(I2C->SR1 & 0x01));
while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
/* Send slave Address in read direction & wait event */
I2C_Send7bitAddress(0x92, I2C_DIRECTION_RX);
while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
//I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
I2C_AcknowledgeConfig(I2C_ACK_NEXT);
while(I2C_GetFlagStatus( I2C_FLAG_ADDRESSSENTMATCHED) == RESET);
I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
(void)I2C->SR3;
I2C_AcknowledgeConfig(I2C_ACK_NONE);
I2C_GenerateSTOP(ENABLE);
EEPBuffer = (uint8_t)(I2C_ReceiveData());
//while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED));
i++;
EEPBuffer = (uint8_t)(I2C_ReceiveData());
/* Send STOP Condition to end transmission */
}
回复:STM8 I2C仿真上遇到的問題
請教各位先進,經由連日的修改 ,i2c已可以正常通訊程式如下,但是遇到個問題
經由示波器顯示的波形與認知的不同
依程式來看位址後接兩個byte date就應該要stop
但是實際狀況是兩個byte date接續出現0xff 之後才stop.
可是i2c_DR的內容兩個byte date又都有接收到
所以是哪邊有遺漏需改正
請指教
void main(void)
{
Init_Application();
EEPBuffer = 0x00;
do
{
int NumByteToRead=2;
int i=0;
I2C_GenerateSTART(ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
/* Send EEPROM address for read */
I2C_Send7bitAddress(0x92,I2C_DIRECTION_RX);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
/* While there is data to be read */
while(NumByteToRead)
{
if(I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED))
{
if(NumByteToRead == 2)
{
I2C_AcknowledgeConfig(I2C_ACK_NONE);
//I2C_AcknowledgeConfig(DISABLE);
}
if(NumByteToRead == 1)
{
//I2C_AcknowledgeConfig(I2C_ACK_NONE);
I2C_GenerateSTOP(ENABLE);
}
/* Read a byte from the EEPROM */
EEPBuffer = I2C_ReceiveData();
/* Point to the next location where the byte read will be saved */
i++;
/* Decrement the read bytes counter */
NumByteToRead--;
}
}
/* Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(I2C_ACK_CURR);
}while(1);
}
页:
[1]