As I stated in my earlier post, to READ data using the I2CREAD command, PBP will handle the low-level
I2C protocol actions to the target I2C device. (PBP acts as the I2C Master)
This information can be gleaned from the PBP manual as well, but maybe not as concise? ;-)
For example, if you want to read the data from register ($07) and the I2C device's 7bit slave address is ($1D).
Code:
''Read a single byte from device ($1D) (7bit addr) from register ($07).
myData var byte ' byte variable to hold the received data from Target device
myAddr var byte ' byte variable to hold Target device's 8bit slave address
myReg var byte ' byte variable to hold the Target device's Register address
DPIN1 var PORTB.4 'data pin
CPIN1 var PORTA.2 'clock
myAddr = $3A ' 7bit slave address left-shifted 1 bit to make an 8bit address and make bit0 (R/W) "0". ($1D << 1 = $3A)
myReg = $07 ' Address of Target device's Register to Read
I2CREAD DPIN1, CPIN1, myAddr, myReg, [myData]
Now this is what happens:
1. PBP transmits a start condition (ST) to the Target device, slave address ($1D), with the R/W bit set to "0" for a write.
2. PBP waits for an acknowledgement from the Target device.
3. PBP transmits the 8bit address of the register to read. ($07)
4. PBP waits for an acknowledgement from the Target device.
5. PBP transmits a repeated start (SR) condition to the Target device, slave address ($1D), with the R/W bit set to "1" for a read of the register in step 3.
6. PBP waits for an acknowledgement from the Target device.
7. PBP clocks in the byte of data sent from the Target device for the register asked for ($07) and stores it in the myData variable.
8. PBP issues a Stop Condition to the Target device once the 8 bits of data are clocked in and stored in the myData variable.
Writing data to an I2C device is similar in that PBP handles the low-level I2C protocol actions for you.
BTW
You should read the MMA7455L datasheet.
As with any device, you will need to make sure you configure the MMA7455L correctly for your application use.
Device default settings in general may not fit a person's application.
Also, it provides information on how to communicate with it and how connect the MCU to it.
All of the information is in there. :-).
Bookmarks