我试图将LPC2378 I2C0与HMC5883L连接。我写了以下代码:
main () {
lcd_init();
lcd_clear();
PINSEL1 |= 0x01400000;
I20CONCLR =0x6c; //Clear all flags
I20CONSET=0X40; //Enable the interface.
I20SCLH=I20SCLL=60; //100 KHz
VICIntEnable |= 0x0000200;
VICVectPriority9 = 1;
VICVectAddr9 = (unsigned long)ISR_I2C;
I20CONSET=0X60; //to send Start bit
while(1)
{
// Idle state. Waiting for interrupts.
}
}
__irq void ISR_I2C(void) {
int status;
status=I20STAT;
if(status==0X08)
{
I20DAT=0x3C; // Slave address + R/W bit
lcd_print("Hello");
I20CONCLR=0x28; //start, interrupt clear
}
if(status==0X18)
{
I20DAT=0x02; //Slave ACK, Send data byte
lcd_print("ACK");
I20CONCLR=0x08; // interrupt clear
}
if(status==0X20)
{
lcd_print("NACK");
I20CONCLR=0x08; // interrupt clear
}
VICVectAddr = 0;
}
当我在模拟中运行时(在Keil中),我得到了NACK条件(由于没有从器件确认,这是预期的),但是当我连接到HMC5883L时,我在传输后没有达到ACK或NACK状态SLA + W字节。造成这个问题的原因是什么?