主题中讨论的其他器件:HALCOGEN
工具与软件:
#include "sys_common.h"
/*用户代码 begin (1)*/
#include "i2c.h"
#include "Gio.h"
#include
/*用户代码结束*/
/**@fn void main (void)
*@简要应用程序主函数
*@注意此函数默认为空。
*
*此函数在启动后调用。
*用户可以使用此函数来实现应用程序。
*/
/*用户代码 begin (2)*/
#define DATA_COUNT 10.
#define Master_Address 0x26
#define Slave_Address 0x8
uint8_t TX_TX_UCT[10] Data_Master ={0x10、0x11、0x12、0x13、0x14、0x15、0x16、0x17、0x18、0x19};
uint8_t RX_UCT[10] Data_Master ={0};
/*用户代码结束*/
int main (void)
{
/*用户代码 begin (3)*/
_enable_irq();
i2cInit ();
gioInit ();
int repeat = 0;
INT DELAY = 0;
INT I = 0;
gioSetDirection (gioPORTB、0xFF);
i2cSetSlaveAdd (i2cREG1、Slave_Address);
i2cSetDirection (i2cREG1、I2C_transmitter);
i2cEnableNotification (i2cREG1、I2C_TX_INT);
对于(REPEAT = 0;REPEAT < 2;REPEAT ++){
i2cSetCount (i2cREG1、DATA_COUNT);
i2cSetMode (i2cREG1、I2C_MASTER);
i2cSetStop (i2cREG1);
i2cSetStart (i2cREG1);
i2cSend (i2cREG1、DATA_COUNT、TX_REG1 Data_Master);
while (i2cIsBusBusy (i2cREG1)= true);
while (i2cIsStopDetected (i2cREG1)=0);
i2cClearSCD(i2cREG1);
for (delay=0;delay<1000000;delay++);
}
while (1);
/*用户代码结束*/
返回0;
}
/*用户代码 begin (4)*/
void i2cNotification (i2cbase_t * i2c、Uint32标志){
if (FLAGS & I2C_TX_INT){
printf ("I2C ile TX_I2C Data_Master dizisinde ki veriler başarıyla gönderildi Ω。");
}
}
/*用户代码结束*/
我使用两个板通过 I2C 进行通信。 我将使用以下代码将TX_Data_Master[10]
数组中的值发送到第二个电路板。 下面、我将添加第二块电路板的代码。 在该代码中、TX_Data_Master[10]
数组中的值将保存到RX_Data_Slave[10]
数组中。 当我将代码发送到开发板并逐步运行上述代码时、程序会卡在"while (i2cIsStopDetected (i2cREG1)== 0)"部分、并且不执行。 此外,i2cNotification ()中断不会在执行"i2cSend ()"函数时触发。 我该怎么办? (我还附上了下面第二个委员会的必要代码。 .
#include "sys_common.h"
/*用户代码 begin (1)*/
#include "i2c.h"
#include "Gio.h"
#include
/*用户代码结束*/
/**@fn void main (void)
*@简要应用程序主函数
*@注意此函数默认为空。
*
*此函数在启动后调用。
*用户可以使用此函数来实现应用程序。
*/
/*用户代码 begin (2)*/
#define DATA_COUNT 10.
#define Slave_Address 0x8
uint8_t RX_UCT[10] Data_Slave ={0};
INT I = 0;
/*用户代码结束*/
int main (void)
{
/*用户代码 begin (3)*/
_enable_irq();
i2cInit ();
gioInit ();
int repeat = 0;
INT DELAY = 0;
gioSetDirection (gioPORTB、0xFF);
i2cSetSlaveAdd (i2cREG1、Slave_Address);
i2cSetDirection (i2cREG1、I2C_RECEIVER);
i2cEnableNotification (i2cREG1、I2C_RX_INT);
对于(REPEAT = 0;REPEAT < 2;++REPEAT){
i2cSetCount (i2cREG1、DATA_COUNT);
i2cSetMode (i2cREG1、I2C_SLAVE);
i2cSetStop (i2cREG1);
i2cSetStart (i2cREG1);
i2cReceivive (i2cREG1、DATA_COUNT、RX_REG1 Data_Slave);
while (i2cIsBusBusy (i2cREG1)= true);
while (i2cIsStopDetected (i2cREG1)=0);
i2cClearSCD(i2cREG1);
对于(DELAY = 0;DELAY < 1000000;DELAY++);
}
while (1);
/*用户代码结束*/
返回0;
}
/*用户代码 begin (4)*/
void i2cNotification (i2cbase_t * i2c、Uint32标志){
if (FLAGS & I2C_RX_INT){
printf ("I2C ile RX_I2C Data_Slave dizisine değerler başarıyla kaydildi.");
对于(I = 0;I < DATA_COUNT;I++){
如果(RX_LVD[i] Data_Slave!= 0){
gioSetBit (gioPORTB、1、1);
}
}
}
}
/*用户代码结束*/