STM32F1 I2C

Started by tha, December 28, 2020, 03:06:11 PM

Previous topic - Next topic

tha

Bit 1 ADDR: Address sent (master mode)/matched (slave mode)
บิตนี้ถูกเคลียร์โดย software โดยการอ่าน the SR1 register ตามด้วยการอ่าน SR2, หรือโดย hardware เมื่อ PE=0.

Address ตรงกัน (Slave)
     0: Address ไม่ตรงกันหรือไม่ได้ถูกรับ.
     1: Received address ตรงกัน.
  – เซ็ตโดย hardware ทันทีที่ the received slave address ตรงกันกับ the OAR registers content หรือ a general call หรือ a
     SMBus Device Default Address หรือ SMBus Host หรือ SMBus Alert ถูกจำได้. (เมื่อ enabled ขึ้นอยู่กับ configuration).
  Note: In slave mode, ขอแนะนำให้ดำเนินการ the complete clearing sequence (READ SR1 จากนั้น READ SR2) หลังจาก
             ADDR ถูกเซ็ต. อ้างอิงถึง Figure 272.

Address ถูกส่ง (Master)
     0: No end of address transmission
     1: End of address transmission
  – สำหรับ 10-bit addressing, the bit ถูกเซ็ตหลังจาก the ACK ของ the 2nd byte.
  – สำหรับ 7-bit addressing, the bit ถูกเซ็ตหลังจาก the ACK ของ the byte.
  Note: ADDR ไม่ถูกเซ็ตหลังจาก a NACK reception

Bit 0 SB: Start bit (Master mode)
     0: No Start condition
     1: Start condition ถูกสร้างขึ้น.
  – เซ็ตเมื่อ a Start condition ถูกสร้างขึ้น.
  – ถูกเคลียร์โดย software โดยการอ่าน the SR1 register ตามด้วยการเขียน the DR register,  หรือโดย hardware เมื่อ PE=0.

tha

26.6.7 I2C Status register 2 (I2C_SR2)

Address offset: 0x18
Reset value: 0x0000

Note: การอ่าน I2C_SR2 หลังจากการอ่าน I2C_SR1 เคลียร์ the ADDR flag, ถึงแม้ว่า the ADDR flag ถูกเซ็ตแล้วหลังจากการอ่าน
           I2C_SR1. ด้วยเหตุนี้, I2C_SR2 ต้องถูกอ่านเฉพาะเมื่อ ADDR ถูกพบว่าเซ็ตใน I2C_SR1 หรือเมื่อ the STOPF bit ถูกเคลียร์.



Bits 15:8 PEC[7:0] Packet error checking register
register นี้บรรจุ the internal PEC เมื่อ ENPEC=1.

Bit 7 DUALF: Dual flag (Slave mode)
     0: Received address ตรงกันกับ OAR1
     1: Received address ตรงกันกับ OAR2
  – ถูกเคลียร์โดย hardware หลังจาก a Stop condition หรือทำซ้ำ Start condition, หรือเมื่อ PE=0.

Bit 6 SMBHOST: SMBus host header (Slave mode)
     0: No SMBus Host address
     1: SMBus Host address ถูกรับเมื่อ SMBTYPE=1 and ENARP=1.
  – ถูกเคลียร์โดย hardware หลังจาก a Stop condition หรือทำซ้ำ Start condition, หรือเมื่อ PE=0.

Bit 5 SMBDEFAULT: SMBus device default address (Slave mode)
     0: No SMBus Device Default address
     1: SMBus Device Default address ถูกรับเมื่อ ENARP=1
  – ถูกเคลียร์โดย hardware หลังจาก a Stop condition หรือทำซ้ำ Start condition, หรือเมื่อ PE=0.

Bit 4 GENCALL: General call address (Slave mode)
     0: No General Call
     1: General Call Address ถูกรับเมื่อ ENGC=1
  – ถูกเคลียร์โดย hardware หลังจาก a Stop condition หรือทำซ้ำ Start condition, หรือเมื่อ PE=0.

tha

Bit 3 Reserved, must be kept at reset value

Bit 2 TRA: Transmitter/receiver
     0: Data bytes ถูกรับ
     1: Data bytes ถูกส่ง
     บิตนี้ถูกเซ็ตขึ้นอยู่กับ the R/W bit ของ the address byte, ที่ the end of total address phase.
     มันถูกเคลียร์โดย hardware อีกด้วยหลังจากการตรวจพบของ Stop condition (STOPF=1), ทำซ้ำ Start condition, การสูญเสีย
     ของ bus arbitration (ARLO=1), หรือเมื่อ PE=0.

Bit 1 BUSY: Bus busy
     0: ไม่มี communication บน the bus
     1: Communication กำลังดำเนินอยู่บน the bus
  – เซ็ตโดย hardware บนการตรวจพบของ SDA or SCL low
  – ถูกเคลียร์โดย hardware บนการตรวจพบของ a Stop condition.
     มันแสดงให้เห็นว่า a communication กำลังดำเนินการอยู่บน the bus. information นี้ยังคงถูกอัปเดตเมื่อ the interface ถูก
     ปิดการใช้งาน (PE=0).

Bit 0 MSL: Master/slave
     0: Slave Mode
     1: Master Mode
  – เซ็ตโดย hardware ทันทีที่ the interface อยู่ใน Master mode (SB=1).
  – ถูกเคลียร์โดย hardware หลังการการตรวจพบ a Stop condition บน the bus หรือ a loss of arbitration (ARLO=1), หรือโดย
     hardware เมื่อ PE=0.

Note: การอ่าน I2C_SR2 หลังจากการอ่าน I2C_SR1 เคลียร์ the ADDR flag, ถึงแม้ว่า the ADDR flag ถูกเซ็ตแล้วหลังจากการอ่าน
           I2C_SR1. ด้วยเหตุนี้, I2C_SR2 ต้องถูกอ่านเฉพาะเมื่อ ADDR ถูกพบว่าเซ็ตใน I2C_SR1 หรือเมื่อ the STOPF bit ถูกเคลียร์.


tha

26.6.8 I2C Clock control register (I2C_CCR)

Address offset: 0x1C
Reset value: 0x0000

Note: fPCLK1 ต้องเป็นอย่างน้อย 2 MHz เพื่อบรรลุ Sm mode I2C frequencies. มันต้องเป็นอย่างน้อย 4 MHz เพื่อบรรลุ Fm mode I2C frequencies. มันต้องเป็นผลคุณของ 10MHz เพื่อถึง the 400 kHz maximum I2C Fm mode clock.
The CCR register ต้องถูกกำหนดค่าเฉพาะเมื่อ the I2C ถูกปิดการใช้งาน (PE = 0).



Bit 15 F/S: I2C master mode selection
     0: Sm mode I2C
     1: Fm mode I2C

Bit 14 DUTY: Fm mode duty cycle
     0: Fm mode tlow/thigh = 2
     1: Fm mode tlow/thigh = 16/9 (ดู CCR)

Bits 13:12 Reserved, must be kept at reset value

Bits 11:0 CCR[11:0]: Clock control register in Fm/Sm mode (Master mode)
     ควบคุม the SCL clock ใน master mode.
     Sm mode หรือ SMBus:
     Thigh = CCR * TPCLK1
     Tlow = CCR * TPCLK1

     Fm mode:
     ถ้า DUTY = 0:
     Thigh = CCR * TPCLK1
     Tlow = 2 * CCR * TPCLK1
     ถ้า DUTY = 1: (เพื่อถึง 400 kHz)
     Thigh = 9 * CCR * TPCLK1
     Tlow = 16 * CCR * TPCLK1

     ตัวอย่างเช่น: ใน Sm mode, เพื่อสร้าง a 100 kHz SCL frequency:
     ถ้า FREQR = 08, TPCLK1 = 125 ns ดังนั้น CCR ต้องถูกโปรแกรมด้วย 0x28 (0x28 <=> 40d x 125 ns = 5000 ns.)

  Note: The minimum allowed value คือ 0x04, ยกเว้นใน FAST DUTY mode ที่ the minimum allowed value คือ 0x01
             thigh = tr(SCL) + tw(SCLH). ดู device datasheet สำหรับ the definitions of parameters.
             tlow = tf(SCL) + tw(SCLL). ดู device datasheet สำหรับ the definitions of parameters.
             I2C communication speed, fSCL ~ 1/(thigh + tlow). The real frequency อาจแตกต่างกันไปเนื่องจาก the analog
             noise filter input delay.
             The CCR register ต้องถูกกำหนดค่าเฉพาะเมื่อ the I2C ถูกปิดการใช้งาน (PE = 0).

tha



Bits 15:6 Reserved, must be kept at reset value

Bits 5:0 TRISE[5:0]: Maximum rise time in Fm/Sm mode (Master mode)
     บิตเหล่านี้ควรจัดให้มี the maximum duration ของ the SCL feedback loop ใน master mode.
     จุดประสงค์คือเพื่อรักษา a stable SCL frequency ไม่ว่า the SCL rising edge duration เป็นอย่างไรก็ตาม.
     บิตเหล่านี้ต้องถูกโปรแกรมด้วย the maximum SCL rise time ที่ให้ไว้ใน the I2C bus specification, เพิ่มขึ้น 1.
     ตัวอย่างเช่น: ใน Sm mode, the maximum allowed SCL rise time คือ 1000 ns.
     ถ้า, ใน the I2C_CR2 register, ค่าของ FREQ[5:0] bits เท่ากับ 0x08 และ TPCLK1 = 125 ns ดังนั้น the TRISE[5:0]
     bits ต้องถูกโปรแกรมด้วย 09h.
     (1000 ns / 125 ns = 8 + 1)
     The filter value สามารถถูกบวกเข้าไปใน TRISE[5:0] ได้อีกด้วย.
     ถ้า the result ไม่ใช่จำนวนเต็ม, TRISE[5:0] ต้องถูกโปรแกรมด้วยส่วนที่เป็นจำนวนเต็ม, เพื่อเคารพต่อ the tHIGH parameter.
  Note: TRISE[5:0] ต้องถูกกำหนดค่าเฉพาะเมื่อ the I2C ถูกปิดการใช้งาน (PE = 0).

tha