STM32F1 I2C

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

Previous topic - Next topic

tha

Bit 10 ACK: Acknowledge enable
บิตนี้ถูกเซ็ตและเคลียร์โดย software, และถูกเคลียร์โดย hardware เมื่อ PE=0.
     0: ไม่มี acknowledge ถูกส่งกลับคืน
     1: Acknowledge ถูกส่งกลับคืนหลังจาก a byte ถูกรับ (address หรือ data ที่ตรงกัน)

Bit 9 STOP: Stop generation
บิตนี้ถูกเซ็ตและเคลียร์โดย software, และถูกเคลียร์โดย hardware เมื่อ a Stop condition ถูกตรวจพบ, เซ็ตโดย hardware เมื่อ a timeout error ถูกตรวจพบ.
In Master Mode:
     0: No Stop generation.
     1: Stop generation หลังจาก the current byte transfer หรือหลังจาก the current Start condition ถูกส่ง.
In Slave mode:
     0: No Stop generation.
     1: ปลดปล่อย the SCL and SDA lines หลังจาก the current byte transfer

Bit 8 START: Start generation
บิตนี้ถูกเซ็ตและเคลียร์โดย software, และถูกเคลียร์โดย hardware เมื่อ start ถูกส่งหรือ PE=0.
In Master Mode:
     0: No Start generation
     1: ทำซ้ำ start generation
In Slave mode:
     0: No Start generation
     1: Start generation เมื่อ the bus เป็นอิสระ

Bit 7 NOSTRETCH: Clock stretching disable (Slave mode)
บิตนี้ถูกใช้เพื่อปิดการใช้งาน clock stretching ใน slave mode เมื่อ ADDR or BTF flag ถูก set, จนกระทั่งมันถูก reset โดย software.
     0: Clock stretching enabled
     1: Clock stretching disabled

Bit 6 ENGC: General call enable
     0: General call disabled. Address 00h ถูก NACKed.
     1: General call enabled. Address 00h ถูก ACKed.

Bit 5 ENPEC: PEC enable
     0: PEC calculation disabled
     1: PEC calculation enabled

Bit 4 ENARP: ARP enable
     0: ARP disable
     1: ARP enable
SMBus Device default address ถูกจำถ้า SMBTYPE=0
SMBus Host address ถูกจำถ้า SMBTYPE=1

Bit 3 SMBTYPE: SMBus type
     0: SMBus Device
     1: SMBus Host

Bit 2 Reserved, must be kept at reset value

Bit 1 SMBUS: SMBus mode
     0: I2C mode
     1: SMBus mode

Bit 0 PE: Peripheral enable
     0: Peripheral disable
     1: Peripheral enable
Note: ถ้าบิตนี้ถูก reset ขณะที่ a communication กำลังดำเนินการ, the peripheral ถูกปิดการใช้งานที่ the end of the current
           communication, เมื่อกลับสู่ IDLE state.
           ทุก bit resets เนื่องจาก PE=0 เกิดขึ้นที่ the end of the communication.
           In master mode, บิตนี้ต้องไม่ถูก reset ก่อน the end of the communication

Note: เมื่อ the STOP, START or PEC bit ถูก set, the software ต้องไม่ดำเนินการ any write access ไปยัง I2C_CR1 ก่อนบิตนี้
          จะถูกเคลียร์โดย hardware. มิฉะนั้นมีความเสี่ยงของการเซ็ต a second STOP, START or PEC request.

tha



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

Bit 12 LAST: DMA last transfer
     0: Next DMA EOT ไม่ใช่ the last transfer
     1: Next DMA EOT คือ the last transfer
Note: บิตนี้ถูกใช้ใน master receiver mode เพื่อยอมให้ the generation ของ a NACK บน the last received data.

Bit 11 DMAEN: DMA requests enable
     0: DMA requests disabled
     1: DMA request enabled when TxE=1 or RxNE =1

Bit 10 ITBUFEN: Buffer interrupt enable
     0: TxE = 1 or RxNE = 1 ไม่สร้าง any interrupt.
     1: TxE = 1 or RxNE = 1 สร้าง Event Interrupt (ไม่ว่า the state of DMAEN เป็นอะไรก็ตาม)

Bit 9 ITEVTEN: Event interrupt enable
     0: Event interrupt disabled
     1: Event interrupt enabled
interrupt นี้ถูกสร้างเมื่อ:
       –    SB = 1 (Master)
       –    ADDR = 1 (Master/Slave)
       –    ADD10= 1 (Master)
       –    STOPF = 1 (Slave)
       –    BTF = 1 พร้อมด้วยไม่มี TxE or RxNE event
       –    TxE event เป็น 1 ถ้า ITBUFEN = 1
       –    RxNE event เป็น 1ถ้า ITBUFEN = 1

Bit 8 ITERREN: Error interrupt enable
     0: Error interrupt disabled
     1: Error interrupt enabled
interrupt นี้ถูกสร้างเมื่อ:
       –    BERR = 1
       –    ARLO = 1
       –    AF = 1
       –    OVR = 1
       –    PECERR = 1
       –    TIMEOUT = 1
       –    SMBALERT = 1

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

Bits 5:0 FREQ[5:0]: Peripheral clock frequency
The FREQ bits ต้องถูกกำหนดค่าด้วย the APB clock frequency value (I2C peripheral ถูกต่อถึง APB). The FREQ field ถูกใช้โดย the peripheral เพื่อสร้าง data setup และ hold times ที่สอดคล้องกับ the I2C specifications. The minimum allowed frequency คือ 2 MHz, the maximum frequency ถูกจำกัดโดย the maximum APB frequency และไม่สามารถเกิน 50 MHz (peripheral intrinsic maximum limit).
     0b000000: ไม่ยอมให้
     0b000001: ไม่ยอมให้
     0b000010: 2 MHz
     ...
     0b110010: 50 MHz
     สูงกว่า 0b100100: ไม่ยอมให้

tha



Bit 15 ADDMODE Addressing mode (slave mode)
     0: 7-bit slave address (10-bit address ไม่ acknowledged)
     1: 10-bit slave address (7-bit address ไม่ acknowledged)

Bit 14 ควรให้อยู่ที่ 1 เสมอโดย software.

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

Bits 9:8 ADD[9:8]: Interface address
     7-bit addressing mode: ไม่ต้องสนใจ
     10-bit addressing mode: bits9:8 ของ address

Bits 7:1 ADD[7:1]: Interface address
     bits 7:1 ของ address

Bit 0 ADD0: Interface address
     7-bit addressing mode: ไม่ต้องสนใจ
     10-bit addressing mode: bit 0 ของ address


tha



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

Bits 7:1 ADD2[7:1]: Interface address
     bits 7:1 ของ address ใน dual addressing mode

Bit 0 ENDUAL: Dual addressing mode enable
     0: เฉพาะ OAR1 ที่ถูกจำใน 7-bit addressing mode
     1: ทั้ง OAR1 and OAR2 ที่ถูกจำใน 7-bit addressing mode

tha



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

Bits 7:0 DR[7:0] 8-bit data register
Byte ถูกรับหรือถูกส่งไปยัง the bus.
     –    Transmitter mode: Byte transmission สตาร์ทโดยอัตโนมัติเมื่อ a byte ถูกเขียนใน the DR register. A continuous
           transmit stream สามารถถูกรักษาไว้ถ้า the next data ที่จะถูกส่งถูกใส่ใน DR ทันทีที่ the transmission ถูกสตาร์ท
           (TxE=1)
     –    Receiver mode: Received byte ถูกคัดลอกลงใน DR (RxNE=1). A continuous transmit stream สามารถถูกรักษาไว้
           ถ้า DR ถูกอ่านก่อน the next data byte ถูกรับ (RxNE=1).
Note: In slave mode, the address ไม่ถูกคัดลอกลงใน DR.
           Write collision ไม่ถูกจัดการ (DR สามารถถูกเขียนถ้า TxE=0).
           ถ้า an ARLO event เกิดขึ้นบน ACK pulse, the received byte ไม่ถูกคัดลอกลงใน DR และดังนั้นไม่สามารถถูกอ่าน.

tha



Bit 15 SMBALERT: SMBus alert
     In SMBus host mode:
     0: no SMBALERT
     1: SMBALERT event เกิดขึ้นบน pin
     In SMBus slave mode:
     0: no SMBALERT response address header
     1: SMBALERT response address header ไปยัง SMBALERT LOW ถูกรับ
  – ถูกเคลียร์โดย software โดยเขียน 0, หรือโดย hardware เมื่อ PE=0.

Bit 14 TIMEOUT: Timeout or Tlow error
     0: No timeout error
     1: SCL ยังคง LOW เป็นเวลา 25 ms (Timeout)
     หรือ
     Master cumulative clock low ยืดเวลาไปมากก่วา 10 ms (Tlow:mext)
     หรือ
     Slave cumulative clock low ยืดเวลาไปมากก่วา 25 ms (Tlow:sext)
  – เมื่อเซ็ตใน slave mode: slave รีเซ็ต the communication และ lines ถูกปลดปล่อยโดย hardware
  – เมื่อเซ็ตใน master mode: Stop condition ถูกส่งโดย hardware
  – ถูกเคลียร์โดย software โดยเขียน 0, หรือโดย hardware เมื่อ PE=0.
  Note: functionality นี้มีให้ใช้เฉพาะใน SMBus mode

Bit 13 Reserved, must be kept at reset value

Bit 12 PECERR: PEC Error in reception
     0: no PEC error: receiver ส่งคืนกลับ ACK หลังจาก PEC reception (ถ้า ACK=1)
     1: PEC error: receiver ส่งคืนกลับ NACK หลังจาก PEC reception (ไม่ว่า ACK เป็นอะไรก็ตาม)
  Note: ถูกเคลียร์โดย software โดยเขียน 0, หรือโดย hardware เมื่อ PE=0.

Bit 11 OVR: Overrun/Underrun
     0: No overrun/underrun
     1: Overrun or underrun
  – เซ็ตโดย hardware ใน slave mode เมื่อ NOSTRETCH=1 และ:
  – ใน reception เมื่อ a new byte ถูกรับ (รวมทั้ง ACK pulse) และ the DR register ยังไม่ได้ถูกอ่าน. New received byte จะ
     สูญหาย.
  – ใน transmission เมื่อ a new byte ควรถูกส่งและ the DR register ยังไม่ได้ถูกเขียน. The same byte ถูกส่งเป็นครั้งที่สอง.
  – ถูกเคลียร์โดย software โดยเขียน 0, หรือโดย hardware เมื่อ PE=0.
  Note: ถ้า the DR write เกิดขึ้นใกล้มากๆกับ SCL rising edge, the sent data ถูกระบุไม่ได้และ a hold timing error เกิดขึ้น

Bit 10 AF: Acknowledge failure
     0: No acknowledge failure
     1: Acknowledge failure
  – เซ็ตโดย hardware เมื่อไม่มี acknowledge ถูกส่งคืนกลับ.
  – ถูกเคลียร์โดย software โดยเขียน 0, หรือโดย hardware เมื่อ PE=0.

Bit 9 ARLO: Arbitration lost (master mode)
     0: ไม่มี Arbitration Lost ถูกตรวจพบ
     1: Arbitration Lost ถูกตรวจพบ
     เซ็ตโดย hardware เมื่อ the interface สูญเสีย the arbitration ของ the bus ไปยัง master อื่น
  – ถูกเคลียร์โดย software โดยเขียน 0, หรือโดย hardware เมื่อ PE=0.
     หลังจาก an ARLO event the interface สวิทช์กลับโดยอัตโนมัติไปเป็น Slave mode (MSL=0).
  Note: ใน SMBUS, the arbitration บน the data ใน slave mode เกิดขึ้นเฉพาะในระหว่าง the data phase, หรือ the
             acknowledge transmission (ไม่ใช่บน the address acknowledge).

Bit 8 BERR: Bus error
     0: ไม่มี Start ผิดที่หรือ Stop condition
     1: Start ผิดที่หรือ Stop condition
  – เซ็ตโดย hardware เมื่อ the interface ตรวจพบ an SDA rising หรือ falling edge ขณะที่ SCL เป็น high, เกิดขึ้นในตำแหน่งที่ใช้
     ไม่ได้ในระหว่าง a byte transfer.
  – ถูกเคลียร์โดย software โดยเขียน 0, หรือโดย hardware เมื่อ PE=0.

tha

Bit 7 TxE: Data register empty (transmitters)
     0: Data register ไม่ว่างเปล่า
     1: Data register ว่างเปล่า
  – เซ็ตเมื่อ DR ว่างเปล่าใน transmission. TxE ไม่ถูกเซ็ตในระหว่าง address phase.
  – ถูกเคลียร์โดย software โดยการเขียนไปยัง the DR register หรือโดย hardware หลังจาก a start or a stop condition or
     when PE=0.
     TxE ไม่ถูกเซ็ตถ้าอย่างใดอย่างหนึ่ง a NACK ถูกได้รับ, หรือถ้า next byte ที่จะถูกส่งเป็น PEC (PEC=1)
  Note: TxE ไม่ถูกเคลียร์โดยการเขียน the first data ที่กำลังถูกส่ง, หรือโดยการเขียน data เมื่อ BTF ถูกเซ็ต, ดังที่ทั้งสองกรณี the
             data register ยังคงว่างเปล่า.

Bit 6 RxNE: Data register not empty (receivers)
     0: Data register  ว่างเปล่า
     1: Data register ไม่ว่างเปล่า
  – เซ็ตเมื่อ data register ไม่ว่างเปล่าใน receiver mode. RxNE ไม่ถูกเซ็ตในระหว่าง address phase.
  – ถูกเคลียร์โดย software โดยการการอ่านหรือการเขียน the DR register หรือโดย hardware เมื่อ PE=0.
     RxNE ไม่ถูกเซ็ตในกรณีของ ARLO event.
  Note: RxNE ไม่ถูกเคลียร์โดยการอ่าน data เมื่อ BTF ถูกเซ็ต, ดังที่ the data register ยังคงเต็ม.

tha

Bit 5 Reserved, must be kept at reset value

Bit 4 STOPF: Stop detection (slave mode)
     0: ไม่มี Stop condition ถูกตรวพบ
     1: Stop condition ถูกตรวพบ
  – เซ็ตโดย hardware เมื่อ a Stop condition ถูกตรวจพบบน the bus โดย the slave หลังจาก an acknowledge (if ACK=1).
  – ถูกเคลียร์โดย software โดยการอ่าน the SR1 register ตามด้วยการเขียนใน the CR1 register, หรือโดย hardware เมื่อ PE=0
  Note: The STOPF bit ไม่ถูกเซ็ตหลังจาก a NACK reception.
             ขอแนะนำให้ดำเนินการ the complete clearing sequence (READ SR1 จากนั้น WRITE CR1) หลังจาก the STOPF ถูก
             เซ็ต. อ้างอิงถึง Figure 272.

Bit 3 ADD10: 10-bit header sent (Master mode)
     0: ไม่มี ADD10 event เกิดขึ้น
     1: Master ได้ส่ง first address byte (header) แล้ว.
  – เซ็ตโดย hardware เมื่อ the master ได้ส่ง the first byte แล้วใน 10-bit address mode.
  – ถูกเคลียร์โดย software โดยการอ่าน the SR1 register ตามด้วยการเขียนใน the DR register ของ the second address byte,
     หรือโดย hardware เมื่อ PE=0.
  Note: ADD10 bit ไม่ถูกเซ็ตหลังจาก a NACK reception

Bit 2 BTF: Byte transfer finished
     0: Data byte transfer ไม่ถูกทำ
     1: Data byte transfer ที่ประสบความสำเร็จ
  – เซ็ตโดย hardware เมื่อ NOSTRETCH=0 และ:
  – ใน reception เมื่อ a new byte ถูกรับ (รวมทั้ง ACK pulse) และ DR ยังไม่ได้ถูกอ่าน (RxNE=1).
  – ใน transmission เมื่อ a new byte ควรถูกส่งและ DR ยังไม่ได้ถูกเขียน (TxE=1).
  – ถูกเคลียร์โดย software โดยการอ่าน the SR1 register ตามด้วยอย่างใดอย่างหนึ่งอ่านหรือเขียนใน the DR register หรือโดย
     hardware หลังจาก a start หรือ a stop condition ใน transmission หรือเมื่อ PE=0.
  Note: The BTF bit ไม่ถูกเซ็ตหลังจาก a NACK reception
             The BTF bit ไม่ถูกเซ็ตถ้า next byte ที่จะถูกส่งเป็น the PEC (TRA=1 in I2C_SR2 register and PEC=1 in I2C_CR1
             register)