測試I2C及量測波形
更新記錄
item | note |
---|---|
20160422 | 第一版 |
目錄
以ADXL345測試
ADXL345
- Fixed 10bit resolution
- Digital Accelerometer (三軸加速度計)
- SPI(3 and 4 wire) and I2C digital interface
I2C /ADL345 I2C Address
- It supports standard (100 kHz) and fast (400 kHz) data transfer modes
- Single- or multiple-byte reads/writes are supported
7bit I2C address (0x1D) + bit8 R/W bit
0x3A for a write / 0x3B for a read目前硬体:ALT high
i2c address 7bit : 0x1D
Device Address | ALT |
---|---|
Write: 0x3A | High |
READ: 0x3B | High |
Write: 0x6A | Low |
READ: 0x6B | Low |
- Slave Addr(7bit) + W/R = 8bit
目前程式是採用SINGLE-BYTE-READ
device | t1 | t2 | t3 | t4 | t5 | t6 | t7 | t8 |
---|---|---|---|---|---|---|---|---|
Master | Start&SlaveAdr+W | - | RegAdr | Start&SlaveAdr+R | - | - | NACK | STOP |
Salve | - | ACK | - | - | ACK | DATA | - | - |
測試波形
程序如下:
seq. | type | description |
---|---|---|
1 | Start | start condigion |
2 | byteframe | master送出 7bit slave addr + 1bit W |
3 | ACK | slave ack(0) |
4 | byteframe | master送出 8bit register addr(0x0 即device ID) |
5 | ACK | slave ack(0) |
6 | byteframe | master送出 7bit slave addr + 1bit R |
7 | ACK | slave ack(0) |
8 | byteframe | slave send data |
9 | NACK | - |
10 | stop | stop condition |
1 | cx004 :[/test]# ./i2c_read 0x3A 0x0 |
程式程序
- gpio_i2c_read
1 | i2c_start_bit(); |
- i2c_start_bit
1 | DELAY(1); |
- i2c_stop_bit
1 | /* clock the ack */ |
i2c_send_byte(c)
- 離開時,CLK為low
1 | local_irq_disable(); |
i2c_receive_ack
- value: 0–Ack received; 1–Nack received
- 離開時,CLK為low
1 | DELAY(1); |