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 に接続すると、SLA+W の送信後に ACK 状態にも NACK 状態にも到達しません。バイト。この問題の原因は何ですか?