close
參考文章 :
http://www.takobear.tw/201702608526356260322804024687/bear-i2c1
The first thing that will happen is that the master will send out a start sequence.
This will alert all the slave devices on the bus that a transaction is starting and they should listen in incase it is for them.
Next the master will send out the device address.
The slave that matches this address will continue with the transaction, any others will ignore the rest of this transaction and wait for the next.
Having addressed the slave device the master must now send out the internal location or register number inside the slave that it wishes to write to or read from.
This number is obviously dependant on what the slave actually is and how many internal registers it has.
Some very simple devices do not have any, but most do, including all of our modules.
Our CMPS03 has 16 locations numbered 0-15. The SRF08 has 36.
Having sent the I2C address and the internal register address the master can now send the data byte (or bytes, it doesn't have to be just one).
The master can continue to send data bytes to the slave and these will normally be placed in the following registers because the slave will automatically increment the internal register address after each byte.
hen the master has finished writing all data to the slave, it sends a stop sequence which completes the transaction.
write to a slave device:
1. Send a start sequence
2. Send the I2C address of the slave with the R/W bit low (even address)
3. Send the internal register number you want to write to
4. Send the data byte
5. [Optionally, send any further data bytes]
6. Send the stop sequence.
This is a little more complicated - but not too much more.
Before reading data from the slave device, you must tell it which of its internal addresses you want to read.
So a read of the slave actually starts off by writing to it.
This is the same as when you want to write to it:
You send the start sequence, the I2C address of the slave with the R/W bit low (even address) and the internal register number you want to write to.
Now you send another start sequence (sometimes called a restart) and the I2C address again - this time with the read bit set.
You then read as many data bytes as you wish and terminate the transaction with a stop sequence.
read the compass bearing as a byte from the CMPS03 module:
1. Send a start sequence
2. Send 0xC0 ( I2C address of the CMPS03 with the R/W bit low (even address)
3. Send 0x01 (Internal address of the bearing register)
4. Send a start sequence again (repeated start)
5. Send 0xC1 ( I2C address of the CMPS03 with the R/W bit high (odd address)
6. Read data byte from CMPS03
7. Send the stop sequence.
http://www.takobear.tw/201702608526356260322804024687/bear-i2c1
The first thing that will happen is that the master will send out a start sequence.
This will alert all the slave devices on the bus that a transaction is starting and they should listen in incase it is for them.
Next the master will send out the device address.
The slave that matches this address will continue with the transaction, any others will ignore the rest of this transaction and wait for the next.
Having addressed the slave device the master must now send out the internal location or register number inside the slave that it wishes to write to or read from.
This number is obviously dependant on what the slave actually is and how many internal registers it has.
Some very simple devices do not have any, but most do, including all of our modules.
Our CMPS03 has 16 locations numbered 0-15. The SRF08 has 36.
Having sent the I2C address and the internal register address the master can now send the data byte (or bytes, it doesn't have to be just one).
The master can continue to send data bytes to the slave and these will normally be placed in the following registers because the slave will automatically increment the internal register address after each byte.
hen the master has finished writing all data to the slave, it sends a stop sequence which completes the transaction.
write to a slave device:
1. Send a start sequence
2. Send the I2C address of the slave with the R/W bit low (even address)
3. Send the internal register number you want to write to
4. Send the data byte
5. [Optionally, send any further data bytes]
6. Send the stop sequence.
This is a little more complicated - but not too much more.
Before reading data from the slave device, you must tell it which of its internal addresses you want to read.
So a read of the slave actually starts off by writing to it.
This is the same as when you want to write to it:
You send the start sequence, the I2C address of the slave with the R/W bit low (even address) and the internal register number you want to write to.
Now you send another start sequence (sometimes called a restart) and the I2C address again - this time with the read bit set.
You then read as many data bytes as you wish and terminate the transaction with a stop sequence.
read the compass bearing as a byte from the CMPS03 module:
1. Send a start sequence
2. Send 0xC0 ( I2C address of the CMPS03 with the R/W bit low (even address)
3. Send 0x01 (Internal address of the bearing register)
4. Send a start sequence again (repeated start)
5. Send 0xC1 ( I2C address of the CMPS03 with the R/W bit high (odd address)
6. Read data byte from CMPS03
7. Send the stop sequence.
全站熱搜
留言列表