Hello everyone,
I am trying to get an IIM-42652 to run with an PIC 18F4690. But I have bad luck with all tries. Still the SPI communication does not work. I get only 0x00 for every register read. The SPI setup seems to meet the IIM-default: 4-wire, cpol=0, cpha=sample@rising_edge; For test I choose a low SPI frequency: ~650 kHz
Is there a special initialization sequence necessary for this device? I couldn't find anything about this in the data sheet.
Any trick to get it run??
Here is some code:
// SPI Config PIC
SSPCON1bits.SSPM3 = 0; // SSPM3:0 = 0001 --> SPI Master Mode, clock = Fosc/64 = 625 kHz @40MHz
SSPCON1bits.SSPM2 = 0;
SSPCON1bits.SSPM1 = 1;
SSPCON1bits.SSPM0 = 0;
SSPCON1bits.CKP = 0; // CPOL idle = 0
LD0 = 1; // CS_SPI idle = 1
SSPCON1bits.SSPEN = 1; // Enable serial port
// I start IMU initialization with a soft reset followed by 100 ms delay
// DEVICE_CONFIG
/*
SPIwrite(0x11); // ADR 11h
NOP();
SPIwrite(0x01); // --> SOFT_RESET !!
NOP();
for (c = 1; c <= 10; c++) // delay 100 ms
wait10ms();
// Then I read Adress 75h (WHO_AM_I) and write it back to the bus where I expect the Reset value: 0x6F
// but I just receive 0x00. No output on the MISO-line at all!
while (1)
{
// SPI READ
LD0 = 0; // CS_SPI setzen (low-aktiv)
NOP();
SSPBUF = 0xF5; // WRITE ADR 75h --> Read F5h
while (PIR1bits.SSPIF == 0); // Auf SSPIF warten
dummy = SSPBUF; // Dummy-Read um BF rückzusetzen
PIR1bits.SSPIF = 0; // SSPIF rücksetzen
for (c = 1; c <= 10; c++) // 10 ergibt ca. 16µs
NOP();
SSPBUF = spibyte; // WRITE DATA
while (PIR1bits.SSPIF == 0); // Auf SSPIF warten
spibyte = SSPBUF; // READ spidata
PIR1bits.SSPIF = 0; // SSPIF rücksetzen
for (c = 1; c <= 10; c++) // 10 ergibt ca. 16µs
NOP();
LD0 = 1; // CS_SPI rücksetzen (low-aktiv)
// Ende SPI READ
}
return;