CMPS03:
Read routine. |
|
The CMPS03 module has 16 registers,
but we only need two of them (register 2 &3.) So, when reading from the CMPS03
(=Slave) and seen by the PIC's point of view (=Master), we have to:
1) Send a START, write the device address (0xc0) (last bit is 0 for write), wait for ACK. 2) Write the word address (sets the first register to read from, which is 0x02 here), wait for ACK. 3) Send a REPEATED START, write the device address again (0xc1) (last bit is 1 for read), wait for ACK. 4) Read the first byte, wait for ACK. 5) Read the last byte, no wait for ACK, send STOP.
We have to repeat this whole cycle each time we start reading the CMPS03 registers, otherwise they will be incremented automatically, and not set to zero.
|
Hi-Tech PICC: void read_compass(unsigned char *buffer) SEN = 1; //
1) send
start bit START RCEN = 1; //
5) start
receiving READ LAST & NO ACK buffer 1 |