26 Inter-integrated circuit (I2C) interface
Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx
microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.
Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx
microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes.
High-density devices are STM32F101xx and STM32F103xx microcontrollers where the
Flash memory density ranges between 256 and 512 Kbytes.
XL-density devices are STM32F101xx and STM32F103xx microcontrollers where the
Flash memory density ranges between 768 Kbytes and 1 Mbyte.
Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
ส่วนนี้ใช้กับตระกูล STM32F10xxx ทั้งหมดเว้นแต่จะระบุไว้เป็นอย่างอื่น
26.1 I2C introduction
I2C (inter-integrated circuit) bus Interface บริการเป็น an interface ระหว่าง the microcontroller และ the serial I2C bus. จัดให้มี multimaster capability, และควบคุม I2C bus-specific sequencing ทั้งหมด, protocol, arbitration และ timing. มันรับรอง the standard mode (Sm, สูงถึง 100 kHz) และ Fm mode (Fm, สูงถึง 400 kHz).
อาจถูกใช้เพื่อวัตถุประสงค์หลายประการรวมถึงการสร้างและการตรวจสอบ CRC, SMBus (system management bus) and PMBus (power management bus).
ขึ้นอยู่กับ specific device implementation DMA capability สามารถมีให้ใช้สำหรับลดการเกินพิกัดของ CPU .
26.2 I2C main features
• Parallel-bus/I2C protocol converter
• Multimaster capability: the same interface สามารถทำงานเป็น Master or Slave
• I2C Master features:
– Clock generation
– Start and Stop generation
• I2C Slave features:
– Programmable I2C Address detection
– Dual Addressing Capability เพื่อรู้จัก 2 slave addresses
– Stop bit detection
• Generation and detection of 7-bit/10-bit addressing and General Call
• Supports different communication speeds:
– Standard Speed (up to 100 kHz)
– Fast Speed (up to 400 kHz)
• Analog noise filter
• Status flags:
– Transmitter/Receiver mode flag
– End-of-Byte transmission flag
– I2C busy flag
• Error flags:
– Arbitration lost condition for master mode
– Acknowledgment failure after address/ data transmission
– Detection of misplaced start or stop condition
– Overrun/Underrun if clock stretching is disabled
• 2 Interrupt vectors:
– 1 Interrupt for successful address/ data communication
– 1 Interrupt for error condition
• Optional clock stretching
• 1-byte buffer with DMA capability
• Configurable PEC (packet error checking) generation or verification:
– PEC value สามารถถูกส่งเป็น last byte in Tx mode
– PEC error checking for last received byte
• SMBus 2.0 Compatibility:
– 25 ms clock low timeout delay
– 10 ms master cumulative clock low extend time
– 25 ms slave cumulative clock low extend time
– Hardware PEC generation/verification with ACK control
– Address Resolution
• PMBus Compatibility
Note: บางคุณลักษณะข้างบนนี้อาจไม่มีให้ใช้ในทุก mcu. ผู้ใช้ควรดูที่ the product data sheet, พื่อระบุคุณสมบัติเฉพาะที่รองรับโดย the
I2C interface implementation(การนำไปใช้งาน)
26.3 I2C functional description
นอกเหนือจาก receiving and transmitting data, interface แปลงมันจาก serial ไปสู่ parallel format และในทางกลับกัน. The interrupts ถูก enabled หรือ disabled โดย software. The interface ถูกต่อถึง the I2C bus โดย a data pin (SDA) และโดย a clock pin (SCL). มันสามารถถูกต่อด้วย a standard (สูงถึง 100 kHz) หรือ fast (สูงถึง 400 kHz) I2C bus.
26.3.1 Mode selection
The interface สามารถทำงานในหนึ่งของ the four following modes:
• Slave transmitter
• Slave receiver
• Master transmitter
• Master receiver
โดยค่าเริ่มต้น, มันทำงานใน slave mode. The interface สวิทช์โดยอัตโนมัติจาก slave ไปยัง master, หลังจากมันสร้าง a START condition และจาก master ไปยัง slave, ถ้า an arbitration loss หรือ a Stop generation เกิดขึ้น, จะยอมให้ multimaster capability.
Communication flow
ใน Master mode, the I2C interface เริ่มต้น a data transfer และสร้าง the clock signal. A serial data transfer เริ่มด้วย a start condition และสิ้นสุดด้วย a stop condition เสมอ. ทั้ง start and stop conditions ถูกสร้างขึ้นใน master mode โดย software.
ใน Slave mode, the interface มีสามารถของการจดจำ addresses ของตัวเอง (7 or 10-bit), และ the General Call address. The General Call address detection อาจถูก enabled หรือ disabled โดย software
Data and addresses ถูกส่งถ่ายเป็น 8-bit bytes, MSB first. The first byte(s) ที่ตาม the start condition บรรจุ the address (one in 7-bit mode, two in 10-bit mode). The address ถูกส่งใน Master mode เสมอ.
A 9th clock pulse ที่ตาม the 8 clock cycles ของ a byte transfer, ในระหว่างนี้ the receiver ต้องส่ง an acknowledge bit ไปยัง the transmitter. อ้างอิงถึง Figure 269.
(https://i.imgur.com/qftZzfh.png)
Acknowledge อาจถูก enabled หรือ disabled โดย software. The I2C interface addresses (dual addressing 7-bit/ 10-bit and/or general call address) สามารถถูกเลือกโดย software.
The block diagram of the I2C interface ถูกแสดงใน Figure 270.
(https://i.imgur.com/Wt4zUoI.png)
1. SMBA เป็น an optional signal ใน SMBus mode. สัญญานนี้ไม่ได้ใช้ถ้า SMBus ถูก disabled.
26.3.2 I2C slave mode
โดยค่าเริ่มต้น the I2C interface ทำงานใน Slave mode. เพื่อสวิทช์จาก default Slave mode ไปยัง Master mode a Start condition generation ถูกต้องการ.
The peripheral input clock ต้องถูกโปรแกรมใน the I2C_CR2 register เพื่อสร้าง correct timings. The peripheral input clock frequency ต้องเป็นอย่างน้อย:
• 2 MHz in Sm mode
• 4 MHz in Fm mode
ทันทีที่ a start condition ถูกตรวจพบ, the address ได้รับจาก the SDA line และส่งไปยัง the shift register. จากนั้นมันจะถูกเปรียบเทียบกับ the address ของ the interface (OAR1) และกับ OAR2 (if ENDUAL=1) หรือ the General Call address (if ENGC = 1).
Note: ใน 10-bit addressing mode, the comparison รวมเอา the header sequence (11110xx0), ที่ xx แสดงถึง the two
most significant bits of the address.
Header หรือ address ไม่ตรงกัน: the interface เพิกเฉยมันและคอยสำหรับ another Start condition.
Header ตรงกัน (10-bit mode only): the interface สร้าง an acknowledge pulse ถ้า the ACK bit ถูกเซ็ตและคอยสำหรับ the 8-bit slave address.
Address ตรงกัน: the interface สร้างในลำดับ:
• An acknowledge pulse ถ้า the ACK bit ถูก set
• The ADDR bit ถูก set โดย hardware แะ an interrupt ถูกสร้างขึ้นถ้า the ITEVFEN bit ถูก set.
• ถ้า ENDUAL=1, the software ต้องอ่าน the DUALF bit เพื่อเช็คว่า slave address ถูก acknowledged แล้ว.
ใน 10-bit mode, หลังจากการรับ the address sequence, the slave จะอยู่ใน Receiver mode เสมอ. มันจะเข้าสู่ Transmitter mode บนการรับ a repeated Start condition ที่ตามโดย the header sequence ด้วย matching address bits และ the least significant bit เซ็ต (11110xx1).
The TRA bit แสดงให้เห็นว่า the slave อยู่ใน Receiver หรือ Transmitter mode.
Slave transmitter
หลังจาก the address reception และหลังจากการเคลียร์ ADDR, the slave ส่ง bytes จาก the DR register ไปยัง the SDA line โดยทาง the internal shift register.
The slave จะขึง SCL low จนกระทั่ง ADDR ถูกเคลียร์และ DR ถูกเต็มด้วย the data ที่จะถูกส่ง (ดู Figure 271 Transfer sequencing EV1 EV3).
เมื่อ the acknowledge pulse ถูกรับ:
• The TxE bit ถูก set โดย hardware พร้อมด้วย an interrupt ถ้า the ITEVFEN และ the ITBUFEN bits ถูก set.
ถ้า TxE ถูก set และ some data ไม่ได้ถูกเขียนใน the I2C_DR register ก่อน the end ของ the next data transmission, the BTF bit ถูก set และ the interface คอยจนกระทั่ง BTF ถูกเคลียร์โดย การอ่านไปยัง I2C_SR1 ตามด้วยการเขียนไปยัง the I2C_DR register, ขึง SCL low.
(https://i.imgur.com/IadM4ev.png)
Slave receiver
หลังจาก the address reception และหลังจากเคลียร์ ADDR, the slave รับ bytes จาก the SDA line ลงใน the DR register โดยทาง the internal shift register. หลังจากแต่ละ byte, the interface สร้างในลำดับ:
• An acknowledge pulse ถ้า the ACK bit ถูก set
• The RxNE bit ถูก set โดย hardware และ an interrupt ถูกสร้างขึ้นถ้า the ITEVFEN และ ITBUFEN bit ถูก set.
ถ้า RxNE ถูก set และ data ใน the I2C_DR register ไม่ได้ถูกอ่านก่อน the end ของ the next data reception,, the BTF bit ถูก set และ the interface คอยจนกระทั่ง BTF ถูกเคลียร์โดยการอ่านจาก I2C_SR1 ตามด้วยการอ่านจาก the I2C_DR register, ขึง SCL low.
(https://i.imgur.com/hDKhw8j.png)
1. The EV1 event ขึง SCL low จนกระทั่ง the end of the corresponding software sequence.
2. The EV2 software sequence ต้องทำให้เสร็จสมบูรณ์ก่อน the end of the current byte transfer
3. หลังจากเช็ค the SR1 register content, the user ควรดำเนินการ the complete clearing sequence สำหรับแต่ละ flag ที่พบ
ว่า set.
ดังนั้น, สำหรับ ADDR and STOPF flags, ลำดับต่อไปนี้ถูกต้องการภายใน the I2C interrupt routine:
READ SR1
if (ADDR == 1) {READ SR1; READ SR2}
if (STOPF == 1) {READ SR1; WRITE CR1}
จุดประสงค์คือทำให้แน่ใจว่าทั้ง ADDR and STOPF flags ถูกเคลียร์ถ้าทั้งสองถูกพบว่า set.
Closing slave communication
หลังจาก the last data byte ถูกส่งถ่าย a Stop Condition ถูกสร้างขึ้นโดย the master. The interface ตรวจพบเงื่อนไขนี้และ sets:
• The STOPF bit และสร้าง an interrupt ถ้า the ITEVFEN bit ถูก set.
The STOPF bit ถูกเคลียร์โดยการอ่านของ the SR1 register ตามด้วยการเขียนไปยัง the CR1 register (ดู EV4 in Figure 272)
26.3.3 I2C master mode
ใน Master mode, the I2C interface เริ่มต้น a data transfer และสร้าง the clock signal. A serial data transfer เริ่มด้วย a Start condition และจบด้วย a Stop condition เสมอ.
Master mode ถูกเลือกทันทีที่ the Start condition ถูกสร้างขึ้นบน the bus ด้วย a START bit.
ต่อไปนี้คือลำดับที่ต้องการใน master mode.
• โปรแกรม the peripheral input clock ใน I2C_CR2 Register เพื่อสร้าง correct timings
• กำหนดค่า the clock control registers
• กำหนดค่า the rise time register
• โปรแกรม the I2C_CR1 register เพื่อเปิดการใช้งาน the peripheral
• เซ็ต the START bit ใน the I2C_CR1 register เพื่อสร้าง a Start condition
The peripheral input clock frequency ต้องเป็นอย่างน้อย:
• 2 MHz in Sm mode
• 4 MHz in Fm mode
SCL master clock generation
The CCR bits ถูกใช้เพื่อสร้าง the high and low level of the SCL clock, สตาร์ทจากการสร้างของ the rising and falling edge (ตามลำดับ). ดังที่ a slave อาจขึง the SCL line, the peripheral เช็ค the SCL input จาก the bus ที่ the end ของ the time ที่โปรแกรมใน TRISE bits หลังจาก rising edge generation
• ถ้า the SCL line เป็น low, มันหมายความว่า a slave กำลังขึง the bus, และ the high level counter จะหยุดจนกระทั่ง the SCL
line ถูกตรวจพบว่าเป็น high. นี้ยอมให้เพื่อรับประกัน the minimum HIGH period ของ the SCL clock parameter.
• ถ้า the SCL line เป็น high, the high level counter จะนับต่อไป.
โดยแท้จริงแล้ว, the feedback loop จาก the SCL rising edge generation โดย the peripheral ไปยัง the SCL rising edge detection โดย the peripheral ใช้เวลาถึงแม้ว่าไม่มี slave ขึง the clock. loopback duration นี้เชื่อมโยงถึง the SCL rising time (ส่งผลกระทบ SCL VIH input detection), บวก delay เนื่องจาก the noise filter ที่ปรากฎบน the SCL input path, บวก delay เนื่องจาก internal SCL input synchronization กับ APB clock. The maximum time ที่ใช้โดย the feedback loop ถูกโปรแกรมใน the TRISE bits, ดังนั้น the SCL frequency ยังคง stable ไม่ว่า the SCL rising time ก็ตาม.
Start condition
การเซ็ต the START bit เป็นเหตุให้ the interface สร้าง a Start condition และสวิทช์ไปเป็น Master mode (MSL bit set) เมื่อ the BUSY bit ถูก cleared.
Note: In master mode, การเซ็ต the START bit เป็นเหตุให้ the interface สร้าง a ReStart condition ที่ the end ของ the current byte transfer.
เมื่อ the Start condition ถูกส่ง:
• The SB bit ถูกเซ็ตโดย hardware และ an interrupt ถูกสร้างขึ้นถ้า the ITEVFEN bit ถูก set.
จากนั้น the master คอยสำหรับการอ่านของ the SR1 register ตามด้วยการเขียนใน the DR register ด้วย the Slave address (ดู Figure 273 and Figure 274 Transfer sequencing EV5).
Slave address transmission
จากนั้น the slave address ถูกส่งไปยัง the SDA line โดยทาง the internal shift register.
• ใน 10-bit addressing mode, การส่ง the header sequence เป็นเหตุให้เกิดเหตุการณ์ต่อไปนี้:
– The ADD10 bit ถูกเซ็ตโดย hardware และ an interrupt ถูกสร้างขึ้นถ้า the ITEVFEN bit ถูกเซ็ต.
จากนั้น the master จะคอยสำหรับการอ่านของ the SR1 register ตามด้วยการเขียนใน the DR register ด้วย the second
address byte (ดู Figure 273 and Figure 274 Transfer sequencing).
– The ADDR bit ถูกเซ็ตโดย hardware และ an interrupt ถูกสร้างขึ้นถ้า the ITEVFEN bit ถูกเซ็ต. จากนั้น the master
จะคอยสำหรับการอ่านของ the SR1 register ตามด้วยการอ่านของ the SR2 register (ดู Figure 273 and Figure 274
Transfer sequencing).
• In 7-bit addressing mode, one address byte ถูกส่ง.
ทันทีที่ the address byte ถูกส่ง,
– The ADDR bit ถูกเซ็ตโดย hardware และ an interrupt ถูกสร้างขึ้นถ้า the ITEVFEN bit ถูกเซ็ต.
จากนั้น the master จะคอยสำหรับการอ่านของ the SR1 register ตามด้วยการอ่านของ the SR2 register (ดู Figure 273 and
Figure 274 Transfer sequencing).
The master สามารถตัดสินใจเพื่อเข้าสู่ Transmitter or Receiver mode ขึ้นอยู่กับ the LSB of the slave address ที่ส่ง.
• In 7-bit addressing mode,
– เพื่อเข้าสู่ Transmitter mode, a master ส่ง the slave address พร้อมด้วย LSB reset.
– เพื่อเข้าสู่ Receiver mode, a master ส่ง the slave address พร้อมด้วย LSB set.
• In 10-bit addressing mode,
– เพื่อเข้าสู่ Transmitter mode, a master ส่ง the header (11110xx0) และจากนั้น the slave address, (ที่ xx หมายว่า
the two most significant bits of the address).
– เพื่อเข้าสู่ Receiver mode, a master ส่ง the header (11110xx0) และจากนั้น the slave address. จากนั้นมันควรส่ง a
repeated Start condition ตามด้วย the header (11110xx1), (ที่ xx หมายว่า the two most significant bits of the
address)
The TRA bit แสดงให้เห็นว่า the master อยู่ใน Receiver หรือ Transmitter mode
เป็นประโยชน์มากเลยครับพี่ ติดตามอ่านอยู่นะครับ
Master transmitter
หลังจาก the address transmission และหลังจากการเคลียร์ ADDR, the master ส่ง bytes จาก the DR register ไปยัง the SDA line โดยทาง the internal shift register.
The master คอยจนกระทั่ง the first data byte ถูกเขียนลงใน I2C_DR (ดู Figure 273 Transfer sequencing EV8_1).
เมื่อ the acknowledge pulse ถูกได้รับ, the TxE bit ถูกเซ็ตโดย hardware และ an interrupt ถูกสร้างขึ้นถ้า the ITEVFEN และ ITBUFEN bits ถูกเซ็ต.
ถ้า TxE ถูกเซ็ตและ a data byte ไม่ถูกเขียนใน the DR register ก่อน the end of the last data transmission, BTF ถูกเซ็ตและ the interface คอยจนกระทั่ง BTF ถูกเคลียร์โดยการอ่านจาก I2C_SR1 ตามด้วยการเขียนไปยัง I2C_DR, ขึง SCL low.
Closing the communication
หลังจาก the last byte ถูกเขียนไปยัง the DR register, the STOP bit ถูกเซ็ตโดย software เพื่อสร้าง a Stop condition (ดู Figure 273 Transfer sequencing EV8_2). The interface กลับไปยัง slave mode โดยอัตโนมัติ (MSL bit ถูกเคลียร์).
Note: Stop condition ควรถูกโปรแกรมในระหว่าง EV8_2 event, เมื่ออย่างใดอย่างหนึ่ง TxE หรือ BTF ถูก set.
(https://i.imgur.com/sZFA0RJ.png)
Notes: 1- The EV5, EV6, EV9, EV8_1 and EV8_2 events ขึง SCL low จนกระทั่ง the end of the corresponding
software sequence.
2- The EV8 software sequence ต้องเสร็จสมบูรณ์ the end of the current byte transfer. ในกรณี EV8 software
sequence ไม่สามารถถูกจัดการก่อน the current byte end of transfer, ขอแนะนำให้ใช้ BTF แทน TXE ที่มีข้อเสียของ
การช้าลง the communication.
Master receiver
หลังจาก the address transmission และหลังจากการเคลียร์ ADDR, the I2C interface เข้าสู่ Master Receiver mode. ในโหมดนี้ the interface รับ bytes จาก the SDA line ลงใน the DR register โดย the internal shift register. หลังจากแต่ละ byte the interface สร้างในลำดับ:
1. An acknowledge pulse ถ้า the ACK bit ถูก set
2. The RxNE bit ถูก set และ an interrupt ถูกสร้างขึ้นถ้า the ITEVFEN and ITBUFEN bits ถูก set (see Figure 274
Transfer sequencing EV7).
ถ้า RxNE ถูกเซ็ตและ a data byte ใน the DR register ไม่ถูกอ่านก่อน the end of the last data reception, BTF ถูกเซ็ตโดย hardware และ the interface คอยจนกระทั่ง BTF ถูกเคลียร์โดยการอ่านจาก I2C_SR1 register ตามด้วยการอ่านใน I2C_DR register, ขึง SCL low.
Closing the communication
Method 1: วิธีนี้สำหรับกรณีเมื่อ the I2C ถูกใช้พร้อมด้วย interrupts ที่มี the highest priority ใน the application
The master ส่ง a NACK สำหรับ the last byte ที่รับจาก the slave. หลังจากการรับ NACK นี้, the slave ปลดปล่อย the control of the SCL and SDA lines. จากนั้น the master สามารถส่ง a Stop/Restart condition
1. เพื่อสร้าง the nonacknowledge pulse หลังจาก the last received data byte, the ACK bit ต้องถูกเคลียร์เพียงแค่หลังจาก
การอ่าน the second last data byte (หลังจากที่สองก่อนสุดท้าย RxNE
event).
2. เพื่อสร้าง the Stop/Restart condition, software ต้องเซ็ต the STOP/START bit เพียงแค่หลังจากการอ่าน the second last
data byte (after the second last RxNE event).
3. ในกรณี a single byte ต้องถูกรับ, the Acknowledge ปิดการใช้งานและ the Stop condition generation ถูกทำเพียงแค่หลัง
จาก EV6 (ใน EV6_1, เพียงแค่หลังจาก ADDR ถูก cleared).
หลังจาก the Stop condition generation, the interface กลับไปยัง slave mode โดยอัตโนมัติ (MSL bit cleared).
(https://i.imgur.com/elctHXC.png)
1. ถ้า a single byte ถูกรับ, มันคือ NA.
2. The EV5, EV6 and EV9 events ขึง SCL low จนกระทั่ง the end of the corresponding software sequence.
3. The EV7 software sequence ต้องเสร็จสมบูรณ์ก่อน the end of the current byte transfer. ในกรณี EV7 software
sequence ไม่สามารถถูกจัดการก่อน the current byte end of transfer, ขอแนะนำให้ใช้ BTF แทน RXNE ที่มีข้อเสียของการช้า
ลง the communication.
4. The EV6_1 or EV7_1 software sequence ต้องเสร็จสมบูรณ์ก่อน the ACK pulse of the current byte transfer.
Method 2: วิธีนี้สำหรับกรณีเมื่อ the I2C ถูกใช้พร้อมด้วย interrupts ที่ไม่มี the highest priority ใน the application หรือเมื่อ the I2C ถูกใช้ด้วยวิธี polling.
ด้วยวิธีนี้, DataN_2 ไม่ถูกอ่าน, ดังนั้นหลังจาก DataN_1, the communication ถูกขึง (ทั้ง RxNE and BTF ถูก set). จากนั้น, เคลียร์ the ACK bit ก่อนการอ่าน DataN-2 ใน DR เพื่อให้แน่ใจว่ามันถูกเคลียร์ก่อน the DataN Acknowledge pulse. หลังจากนั้น, เพียงแค่หลังจากการอ่าน DataN_2, เซ็ต the STOP/ START bit และอ่าน DataN_1. หลังจาก RxNE ถูก set, อ่าน DataN. นี้ถูกแสดงข้างล่างนี้
(https://i.imgur.com/Ctua3xP.png)
เมื่อ 3 bytes ยังเหลืออยู่ให้ถูกอ่าน:
• RxNE = 1 => ไม่มีอะไร (DataN-2 ไม่ถูกอ่าน).
• DataN-1 ถูกรับ
• BTF = 1 เพราะทั้ง shift and data registers เต็ม: DataN-2 ใน DR และ DataN-1 ใน the shift register => SCL ถูกดึง
low: ไม่มี data อื่นที่จะถูกรับบน the bus.
• เคลียร์ ACK bit
• อ่าน DataN-2 in DR => นี้จะเริ่ม the DataN reception ใน the shift register
• DataN ถูกรับ (พร้อมด้วย a NACK)
• โปรแกรม START/STOP
• อ่าน DataN-1
• RxNE = 1
• อ่าน DataN
ขั้นตอนที่อธิบายข้างบนใช้ได้สำหรับ N>2. กรณีที่ a single byte หรือ two bytes ถูกรับควรถูกรับมือต่างออกไป, ดังอธิบายข้างล่าง:
• กรณีของ a single byte ถูกรับ:
– ใน the ADDR event, เคลียร์ the ACK bit.
– เคลียร์ ADDR
– โปรแกรม the STOP/START bit.
– อ่าน the data หลังจาก the RxNE flag ถูก set.
• กรณีของ two bytes ถูกรับ:
– เซ็ต POS และ ACK
– คอยสำหรับ the ADDR flag ถูกเซ็ต
– เคลียร์ ADDR
– เคลียร์ ACK
– คอยสำหรับ BTF ถูกเซ็ต
– โปรแกรม STOP
– อ่าน DR สองครั้ง
(https://i.imgur.com/hPq31Ee.png)
(https://i.imgur.com/V8qAWzh.png)
26.3.4 Error conditions
ต่อไปนี้เป็น the error conditions ซึ่งอาจเป็นเหตุให้ communication ล้มเหลว.
Bus error (BERR)
error นี้เกิดขึ้นเมื่อ the I2C interface ตรวจพบ an external Stop or Start condition ในระหว่าง an address or a data transfer. ในกรณีนี้:
• the BERR bit ถูก set และ an interrupt ถูกสร้างขึ้นถ้า the ITERREN bit ถูก set
• ใน Slave mode: data ถูกละทิ้งและ the lines ถูกปลดปล่อยโดย hardware:
– ในกรณีของ a misplaced Start, the slave พิจารณาว่ามันคือ a restart และคอยสำหรับ an address, หรือ a Stop
condition
– ในกรณีของ a misplaced Stop, the slave จะกระทำเหมือน a Stop condition และ the lines ถูกปลดปล่อยโดย
hardware
• ใน Master mode: the lines ไม่ถูกปลดปล่อยและสถานะของ the current transmission ไม่ถูกกระทบ. มันขึ้นอยู่กับ the
software ที่จะทำแท้ง the current transmission หรือไม่
Acknowledge failure (AF)
error นี้เกิดขึ้นเมื่อ the interface ตรวจพบ a nonacknowledge bit. ในกรณีนี้:
• the AF bit ถูก set และ an interrupt ถูกสร้างขึ้นถ้า the ITERREN bit ถูก set
• a transmitter ซึ่งรับ a NACK ต้องรีเซ็ต the communication:
– ถ้า Slave: lines ถูกปลดปล่อยโดย hardware
– ถ้า Master: a Stop or repeated Start condition ต้องถูกสร้างขึ้นโดย software
Arbitration lost (ARLO)
error นี้เกิดขึ้นเมื่อ the I2C interface ตรวจพบ an arbitration lost condition. ในกรณีนี้:
• the ARLO bit ถูก set โดย hardware (และ an interrupt ถูกสร้างขึ้นถ้า the ITERREN bit ถูก set)
• the I2C Interface กลับไปสู่ slave mode โดยอัตโนมัติ (the MSL bit ถูกเคลียร์). เมื่อ the I2C สูญเสีย the arbitration, มันไม่
สามารถ acknowledge slave address ของมันใน the same transfer, แต่มันสามารถ acknowledge มันหลังจาก a repeated
Start จาก the winning master
• lines ถูกปลดปล่อยโดย hardware
Overrun/underrun error (OVR)
An overrun error สามารถเกิดขึ้นใน slave mode เมื่อ clock stretching ถูกปิดการใช้งานและ the I2C interface กำลังรับ data. The interface รับ a byte แล้ว (RxNE=1) และ the data ใน DR ยังไม่ถูกอ่าน, ก่อน the next byte ถูกรับโดย the interface. ในกรณีนี้,
• The last received byte จะสูญหาย.
• ในกรณีของ Overrun error, software ควรเคลียร์ the RxNE bit และ the transmitter ควรส่งซ้ำ the last received byte.
Underrun error สามารถเกิดขึ้นใน slave mode เมื่อ clock stretching ถูกปิดการใช้งานและ the I2C interface กำลังส่ง data. The interface ไม่อัปเดต the DR ด้วย the next byte (TxE=1), ก่อน the clock มาสำหรับ the next byte. ในกรณีนี้,
• The same byte ใน the DR register จะถูกส่งอีกครั้ง
• The user ควรทำให้แน่ใจว่า data ที่รับบน the receiver side ในระหว่าง an underrun error ถูกละทิ้งและ the next bytes ถูก
เขียนภายใน the clock low time ที่ระบุใน the I2C bus standard.
สำหรับ the first byte ที่ถูกส่ง, the DR ต้องถูกเขียนหลังจาก ADDR ถูกเคลียร์และก่อน the first SCL rising edge. ถ้าเป็นไปไม่ได้, the receiver ต้องละทิ้ง the first data.
26.3.5 SDA/SCL line control
• ถ้า clock stretching ถูก enabled:
– Transmitter mode: ถ้า TxE=1 and BTF=1: the interface ยึด the clock line low ก่อน transmission เพื่อคอย
สำหรับ the microcontroller อ่าน SR1 และจากนั้นเขียน the byte ใน the Data Register (ทั้ง buffer and shift
register ว่างเปล่า).
– Receiver mode: ถ้า RxNE=1 and BTF=1: the interface ยึด the clock line low หลังจาก reception เพื่อคอยสำหรับ
the microcontroller อ่าน SR1 และจากนั้นอ่าน the byte ใน the Data Register (ทั้ง buffer and shift register เต็ม).
• ถ้า clock stretching ถูก disabled in Slave mode:
– Overrun Error ในกรณีของ RxNE=1 และไม่มีการอ่านของ DR ถูกทำก่อน the next byte ถูกรับ. The last received byte
จะสูญหาย.
– Underrun Error ในกรณี TxE=1 และไม่มีการเขียนลงใน DR ถูกทำก่อน the next byte ต้องถูกส่ง. The same byte จะถูก
ส่งอีกครั้ง.
– Write Collision ไม่ถูกจัดการ.
26.3.6 SMBus
Introduction
The System Management Bus (SMBus) คือ a two-wire interface ซึ่งมีหลากหลาย devices สามารถสื่อสารซึ่งกันและกันและกับส่วนที่เหลือของระบบ. มันอยู่บนฐานของ I2C principles of operation. SMBus จัดให้มี a control bus สำหรับ system and power management งานที่เกี่ยวข้อง. A system อาจใช้ SMBus ส่งผ่าน messages ถึงและจาก devices แทนการสลับ control lines แต่ละราย.
The System Management Bus Specification อ้างอิงถึงสามชนิดของ devices. A slave คือ a device ที่กำลังรับหรือกำลังตอบสนองต่อ a command. A master คือ a device ที่ปล่อยออก commands, สร้าง the clocks, และยุติ the transfer. A host คือ a specialized master ที่จัดให้มี the main อินเตอร์เฟสไปยัง the system's CPU. A host ต้องเป็น a master-slave และต้องรองรับ
the SMBus host notify protocol. มีเพียง one host เท่านั้นที่ยอมให้ใน a system.
ความคล้ายคลึงกันระหว่าง SMBus and I2C
• 2-wire bus protocol (1 Clk, 1 Data) + SMBus Alert line ให้เลือกได้
• Master-slave communication, Master จัดให้มี clock
• Multi master capability
• SMBus data format คล้ายกันกับ I2C 7-bit addressing format (Figure 269).
ความแตกต่างระหว่าง SMBus and I2C
ตารางต่อไปนี้อธิบายความแตกต่างระหว่าง SMBus and I2C.
(https://i.imgur.com/K9ZPwOm.png)
SMBus application usage
ด้วย System Management Bus, a device สามารถจัดให้มี manufacturer information, บอก the system ว่า model/part number ของมันคือ, บันทึกสถานะของมันสำหรับ a suspend event, รายงานชนิดต่างๆของ errors, ยอมรับ control parameters, และคืนกลับ status ของมัน. SMBus จัดให้มี a control bus สำหรับ system and power management งานที่เกี่ยวข้อง.
Device identification
device ใดๆที่มีอยู่บน the System Management Bus ที่เป็น a slave จะมี address เฉพาะที่เรียกว่า the Slave Address. สำหรับรายการของ slave addresses ที่สงวนไว้, อ้างอิงถึง the SMBus specification version. 2.0 (http://smbus.org/).
Bus protocols
The SMBus specification รองรับได้มากถึง nine bus protocols. สำหรับรายละเอียดที่มากขึ้นของ protocols เหล่านี้และ SMBus address types, อ้างอิงถึง SMBus specification version. 2.0. protocols เหล่านี้ควรถูกทำให้เป็นผลโดย the user software
Address resolution protocol (ARP)
SMBus slave address conflicts สามารถถูกแก้ไขโดยการกำหนดแบบไดนามิค a new unique address ไปยังแต่ละ slave device. The Address Resolution Protocol (ARP) มีคุณลักษณะต่อไปนี้:
• Address assignment ใช้ the standard SMBus physical layer arbitration mechanism
• Assigned addresses ยังคงคงที่ในขณะที่ device power ถูกประยุกต์ใช้; address retention ผ่านทาง device power loss ถูก
ยอมให้ได้อีกด้วย
• ไม่มี additional SMBus packet overhead เกิดขึ้นหลังจาก address assignment. (กล่าวคือการเข้าถึงที่ตามมาไปยัง assigned
slave addresses มี the same overhead เหมือนการเข้าถึงไปยัง fixed address devices.)
• Any SMBus master สามารถแจกแจง the bus
Unique device identifier (UDID)
เพื่อจัดให้มี a mechanism เพื่อแยกแต่ละ device สำหรับความมุ่งหมายของ address assignment, แต่ละ device ต้องใช้ a unique device identifier (UDID).
สำหรับรายละเอียดบน 128-bit UDID และข้อมูลที่มากขึ้นบน ARP, อ้างอิงถึง SMBus specification version 2.0.
SMBus alert mode
SMBus Alert คือ an optional signal พร้อมด้วย an interrupt line สำหรับ devices ที่ต้องการแลกเปลี่ยนความสามารถของมันไปยัง master สำหรับ a pin. SMBA เป็น a wired-AND signal เช่นเดียวกันกับ the SCL and SDA signals เป็น. SMBA ถูกใช้ร่วมกันกับ the SMBus General Call Address. Messages ที่เรียกด้วยด้วย the SMBus มีความยาว two bytes.
A slave-only device สามารถส่งสัญญาน the host ผ่านทาง SMBA ที่มันต้องการจะคุยโดยการเซ็ต ALERT bit ใน I2C_CR1 register. The host ประมวลผล the interrupt และเข้าถึงพร้อมกันทุก SMBA devices ผ่านทาง the Alert Response Address (รู้ในนาม ARA ที่มีค่า 0001100X). Only the device(s) ซึ่งดึง SMBA low จะ acknowledge the Alert Response Address. status นี้ถูกระบุโดยใช้ SMBALERT Status flag ใน I2C_SR1 register. The host ดำเนินการ a modified Receive Byte operation. The 7 bit device address ถูกจัดให้มีโดย the slave transmit device ถูกวางใน the 7 most significant bits of the byte. The eighth bit สามารถเป็นศูนย์หรือหนึ่ง.
ถ้ามากกว่าหนึ่ง device ดึง SMBA low, the highest priority (lowest address) device จะชนะ communication rights โดยทาง standard arbitration ในระหว่าง the slave address transfer. หลังจาก acknowledging the slave address the device ต้องปลด SMBA pull-down ของมัน. ถ้า the host ยังคงดู SMBA low เมื่อ the message transfer เสร็จสมบูรณ์, มันรู้ที่จะอ่าน the ARA อีกครั้ง
A host ซึ่งไม่ได้ใช้ the SMBA signal อาจเข้าถึง the ARA เป็นระยะ.
สำหรับรายละเอียดที่มากขึ้นบน SMBus Alert mode, อ้างอิงถึง SMBus specification version 2.0.
Timeout error
มีความแตกต่างกันใน the timing specifications ระหว่าง I2C and SMBus. SMBus กำหนด a clock low timeout, TIMEOUT of 35 ms. ยัง SMBus ระบุ TLOW: SEXT เป็นดัง the cumulative clock low ยืดเวลาสำหรับ a slave device. SMBus ระบุ TLOW: MEXT เป็นดัง the cumulative clock low ยืดเวลาสำหรับ a master device. สำหรับรายละเอียดที่มากขึ้นบน timeouts เหล่านี้, อ้าง
อิงถึง SMBus specification version 2.0.
The status flag Timeout หรือ Tlow Error ใน I2C_SR1 แสดงสถานะของคุณลักษณะนี้
How to use the interface in SMBus mode
เพื่อสวิทช์จาก I2C mode ไปเป็น SMBus mode, ลำดับต่อไปนี้ควรถูกกระทำ.
• Set the SMBus bit in the I2C_CR1 register
• กำหนดค่า the SMBTYPE and ENARP bits in the I2C_CR1 register ตามต้องการสำหรับ the application
ถ้าคุณต้องการกำหนดค่า the device เป็น a master, ทำตาม the Start condition generation ขั้นตอนใน Section 26.3.3. มิฉะนั้น, ทำตามลำดับใน Section 26.3.2.
The application ต้องควบคุม the various SMBus protocols โดย software.
• SMB Device Default Address รับทราบ if ENARP=1 and SMBTYPE=0
• SMB Host Header acknowledged if ENARP=1 and SMBTYPE=1
• SMB Alert Response Address acknowledged if SMBALERT=1
26.3.7 DMA requests
DMA requests (เมื่อเปิดการใช้งาน) ถูกสร้างขึ้นเฉพาะสำหรับ data transfer. DMA requests ถูกสร้างขึ้นโดย Data Register กลายมาเป็นว่างเปล่าใน transmission and Data Register กลายมาเป็นเต็มใน reception. The DMA ต้องถูกเริ่มต้นและเปิดการใช้งานก่อน the I2C data transfer. The DMAEN bit ต้องถูกเซ็ตใน the I2C_CR2 register ก่อน the ADDR event. ใน master mode หรือใน slave mode เมื่อ clock stretching ถูกเปิดการใช้งาน, the DMAEN bit สามารถถูกเซ็ตอีกดวยในระหว่าง the ADDR event, ก่อนการเคลียร์ the ADDR flag. The DMA request ต้องถูกบริการก่อน the end ของ the current byte transfer. เมื่อจำนวนของ data transfers ซึ่งถูกโปรแกรมแล้วสำหรับ the corresponding DMA stream ถูกถึง, the DMA controller ส่ง an End of Transfer EOT signal ไปยัง the I2C interface และสร้าง a Transfer Complete interrupt ถ้าถูกเปิดการใช้งาน:
• Master transmitter: ใน the interrupt routine หลังจาก the EOT interrupt, ปิดการใช้งาน DMA requests จากนั้นคอย
สำหรับ a BTF event ก่อนการโปรแกรม the Stop condition.
• Master receiver: เมื่อจำนวนของ bytes ที่ถูกรับเท่ากับหรือมากกว่า 2 , the DMA controller ส่ง a hardware signal,
EOT_1, ที่ตรงกันกับลำดับสุดท้ายแต่ one data byte (จำนวนของ bytes – 1). ถ้า, ใน the I2C_CR2 register, the LAST bit
ถูกเซ็ต, I2C จะส่ง a NACK โดยอัตโนมัติหลังจาก the next byte ตามด้วย EOT_1. The user สามารถสร้าง a Stop condition
ใน the DMA Transfer Complete interrupt routine ถ้าถูกเปิดการใช้งาน.
Transmission using DMA
DMA mode สามารถถูกเปิดการใช้งานสำหรับ transmission โดยการเซ็ต the DMAEN bit ใน the I2C_CR2 register. Data จะถูกโหลดจาก a Memory area ที่กำหนดค่าโดยใช้ the DMA peripheral (อ้างอิงถึง the DMA specification) ไปยัง the I2C_DR register เมื่อ the TxE bit ถูกเซ็ต. เพื่อแม็ป a DMA stream x สำหรับ I2C transmission (ที่ x คือ the stream number), ทำตามลำดับต่อไปนี้:
1. เซ็ต the I2C_DR register address ใน the DMA_SxPAR register. The data จะถูกย้ายไปยัง address นี้จาก the
memory หลังจากแต่ละ TxE event.
2. เซ็ต the memory address ใน the DMA_SxMA0R register (และใน DMA_SxMA1R register ในกรณีของ a bouble
buffer mode). The data จะถูกโหลดลงใน I2C_DR จาก memory นี้หลังจากแต่ละ TxE event.
3. กำหนดค่าจำนวนทั้งหมดของ bytes ที่ถูกส่งถ่ายใน the DMA_SxNDTR register. หลังจากแต่ละ TxE event, ค่านี้จะถูกลดลง.
4. กำหนดค่า the DMA stream priority โดยใช้ the PL[0:1] bits ใน the DMA_SxCR register
5. เซ็ต the DIR bit ใน the DMA_SxCR register และกำหนดค่า interrupts หลังจาก half transfer หรือ full transfer ขึ้นอยู่กับ
application requirements.
6. ทำให้ the stream ทำงานโดยการเซ็ต the EN bit ใน the DMA_SxCR register.
เมื่อจำนวนของ data transfers ซึ่งถูกโปรแกรมไว้แล้วใน the DMA Controller registers ถูกถึง, the DMA controller ส่ง an End of Transfer EOT/ EOT_1 signal ไปยัง the I2C interface และ the DMA สร้าง an interrupt, ถ้าถูกเปิดการใช้งาน, บน the DMA stream interrupt vector.
Note: ห้ามเปิดการใช้งาน the ITBUFEN bit ใน the I2C_CR2 register ถ้า DMA ถูกใช้สำหรับ transmission
Reception using DMA
DMA mode สามารถถูกเปิดการใช้งานสำหรับ reception โดยการเซ็ต the DMAEN bit ใน the I2C_CR2 register. Data จะถูกโหลดจาก the I2C_DR register ไปยัง a Memory area ที่กำหนดค่าโดยใช้ the DMA peripheral (refer to the DMA specification) เมื่อไรก็ตามที่ a data byte ถูกรับ. เพื่อแม็ป a DMA stream x สำหรับ I2C reception (ที่ x คือ the stream number), ทำตามลำดับต่อไปนี้:
1. เซ็ต the I2C_DR register address ใน DMA_SxPAR register. The data จะถูกย้ายจาก address นี้ไปยัง the memory
หลังจากแต่ละ RxNE event.
2. เซ็ต the memory address ใน the DMA_SxMA0R register (และใน DMA_SxMA1R register ในกรณีของ a bouble
buffer mode). The data จะถูกโหลดจาก the I2C_DR register ไปยัง memory area นี้หลังจากแต่ละ RxNE event.
3. กำหนดค่าจำนวนทั้งหมดของ bytes ที่ถูกส่งถ่ายใน the DMA_SxNDTR register. หลังจากแต่ละ RxNE event, ค่านี้จะถูกลดลง.
4. กำหนดค่า the DMA stream priority โดยใช้ the PL[0:1] bits ใน the DMA_SxCR register
5. รีเซ็ต the DIR bit และกำหนดค่า interrupts ใน the DMA_SxCR register หลังจาก half transfer หรือ full transfer ขึ้นอยู่
กับ application requirements.
6. ทำให้ the stream ทำงานโดยการเซ็ต the EN bit ใน the DMA_SxCR register.
เมื่อจำนวนของ data transfers ซึ่งถูกโปรแกรมไว้แล้วใน the DMA Controller registers ถูกถึง, the DMA controller ส่ง an End of Transfer EOT/ EOT_1 signal ไปยัง the I2C interface และ the DMA สร้าง an interrupt, ถ้าถูกเปิดการใช้งาน, บน the DMA stream interrupt vector.
Note: ห้ามเปิดการใช้งาน the ITBUFEN bit ใน the I2C_CR2 register ถ้า DMA ถูกใช้สำหรับ transmission
26.3.8 Packet error checking
A PEC calculator ถูกนำมาใช้เพื่อปรับปรุงความน่าเชื่อถือของการสื่อสาร. The PEC ถูกคำนวณโดยใช้ the C(x) = x8 + x2 + x + 1 CRC-8 polynomial อนุกรมบนแต่ละบิต.
• PEC calculation ถูกเปิดการใช้งานโดยการเซ็ต the ENPEC bit ใน the I2C_CR1 register. PEC คือ a CRC-8 ที่คำนวณบนทุก
message bytes รวมทั้ง addresses and R/W bits.
– ใน transmission: เซ็ต the PEC transfer bit ใน the I2C_CR1 register หลังจาก the TxE event ที่ตรงกันกับ the last
byte. The PEC จะถูกส่งถ่ายหลังจาก the last transmitted byte
– ใน reception: เซ็ต the PEC bit ใน the I2C_CR1 register หลังจาก the RxNE event ที่ตรงกันกับ the last byte ดังนั้น
the receiver ส่ง a NACK ถ้า the next received byte ไม่เท่ากันกับ the internally calculated PEC. ในกรณีของ
Master-Receiver, a NACK ต้องตาม the PEC ไม่ว่าผลการตรวจสอบเป็นอย่างไร.The PEC ต้องถูกเซ็ตก่อน the ACK pulse
of the current byte reception.
• A PECERR error flag/interrupt มีให้ใช้อีกด้วยใน the I2C_SR1 register.
• ถ้า DMA and PEC calculation ทั้งคู่ถูกเปิดการใช้งาน:
– ใน transmission: เมื่อ the I2C interface ได้รับ an EOT signal จาก the DMA controller, มันจะส่ง a PEC โดยอัตโนมัติ
หลังจาก the last byte.-
– ใน reception: เมื่อ the I2C interface ได้รับ an EOT_1 signal จาก the DMA controller, มันจะพิจารณา the next
byte โดยอัตโนมัติว่าเป็น a PEC และจะตรวจสอบมัน. A DMA request ถูกสร้างขึ้นหลังจาก PEC reception.
• เพื่อยอมให้ intermediate PEC transfers, a control bit มีให้ใช้ใน the I2C_CR2 register (LAST bit) เพื่อตัดสินว่าถ้ามันเป็น
the last DMA transfer จริงๆหรือไม่. ถ้ามันเป็น the last DMA request สำหรับ a master receiver, a NACK จะถูกส่งโดย
อัตโนมัติหลังจาก the last received byte.
• PEC calculation ถูกทำให้เสียหายโดย an arbitration loss.
26.4 I2C interrupts
ตารางข้างล่างนี้ให้รายการของ I2C interrupt requests.
(https://i.imgur.com/4OH1eDq.png)
(https://i.imgur.com/Pq0c704.png)
Note: SB, ADDR, ADD10, STOPF, BTF, RxNE and TxE ถูกลอจิก OR บน the same interrupt channel.
BERR, ARLO, AF, OVR, PECERR, TIMEOUT and SMBALERT ถูกลอจิก OR บน the same interrupt channel.
(https://i.imgur.com/pOAKnnV.png)
26.5 I2C debug mode
เมื่อ the microcontroller เข้าสู่ the debug mode (Cortex®-M3 core ถูกหยุด), the SMBUS timeout อย่างใดอย่างหนึ่งทำงานต่อไปตามปกติหรือหยุด, ขึ้นอยู่กับ the DBG_I2Cx_SMBUS_TIMEOUT configuration bits ใน the DBG module. สำหรับรายละเอียดที่มากขึ้นอ้างอิงถึง Section 31.16.2: Debug support for timers, watchdog, bxCAN and I2C.
26.6 I2C registers
อ้างอิงถึงสำหรับรายการตัวย่อที่ใช้ใน register descriptions.
The peripheral registers ต้องถูกเข้าถึงโดย half-words (16 bits) or words (32 bits).
(https://i.imgur.com/OjeHXId.png)
Bit 15 SWRST: Software reset
เมื่อ set, the I2C อยู่ภายใต้ reset state. ก่อนการรีเซ็ตบิตนี้, ทำให้แน่ใจว่า the I2C lines ถูกปลดปล่อยและ the bus เป็นอิสระ.
0: I2C Peripheral ไม่อยู่ภายใต้ reset
1: I2C Peripheral อยู่ภายใต้ reset state
Note: บิตนี้สามารถถูกใช้เพื่อเริ่มต้นใหม่ the peripheral หลังจาก an error หรือ a locked state. ตัวอย่างเช่น, ถ้า the BUSY bit ถูก
เซ็ตและยังคงถูกล็อคเนืองจากความผิดพลาดบน the bus, the SWRST bit สามารถถูกใช้เพื่อออกจากสภาวะนี้.
Bit 14 Reserved, must be kept at reset value
Bit 13 ALERT: SMBus alert
บิตนี้ถูกเซ็ตและเคลียร์โดย software, และถูกเคลียร์โดย hardware เมื่อ PE=0.
0: ปลดปล่อย SMBA pin high. Alert Response Address Header ตามด้วย NACK.
1: ขับ SMBA pin low. Alert Response Address Header ตามด้วย ACK.
Bit 12 PEC: Packet error checking
บิตนี้ถูกเซ็ตและเคลียร์โดย software, และถูกเคลียร์โดย hardware เมื่อ PEC ถูกส่งถ่ายหรือโดย a START หรือ Stop condition หรือเมื่อ PE=0.
0: ไม่มี PEC transfer
1: PEC transfer (in Tx or Rx mode)
Note: PEC calculation ถูกทำให้เสียหายโดย an arbitration loss.
Bit 11 POS: Acknowledge/PEC Position (for data reception)
บิตนี้ถูกเซ็ตและเคลียร์โดย software, และถูกเคลียร์โดย hardware เมื่อ PE=0.
0: ACK bit ควบคุม the (N)ACK ของ the current byte ที่กำลังถูกรับใน the shift register. The PEC bit แสดงให้เห็นว่า
current byte ใน shift register คือ a PEC.
1: ACK bit ควบคุม the (N)ACK ของ the next byte ซึ่งจะถูกรับใน the shift register. The PEC bit แสดงให้เห็นว่า the next
byte ใน the shift register คือ a PEC
Note: The POS bit ถูกใช้เมื่อขั้นตอนสำหรับ reception ของ 2 bytes (see Method 2: transfer sequence diagram for
master receiver when N=2) ถูกทำตาม. มันต้องถูกกำหนดค่าก่อน data reception starts. ในกรณีนี้, เพื่อ NACK the
2nd byte, the ACK bit ต้องถูกเคลียร์เพียงแค่หลังจาก ADDR ถูกเคลียร์. เพื่อตรวจสอบ the 2nd byte เป็น PEC, the PEC
bit ต้องถูกเซ็ตในระหว่าง the ADDR stretch event หลังจากการกำหนดค่า the POS bit.
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.
(https://i.imgur.com/EEbYSl3.png)
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: ไม่ยอมให้
(https://i.imgur.com/ma6jO9H.png)
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
(https://i.imgur.com/1haxe7Z.png)
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
(https://i.imgur.com/pUb7BsZ.png)
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 และดังนั้นไม่สามารถถูกอ่าน.
(https://i.imgur.com/m3Fkhj0.png)
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.
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 ยังคงเต็ม.
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)
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.
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 ถูกเคลียร์.
(https://i.imgur.com/4Pt1zsZ.png)
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.
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 ถูกเคลียร์.
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).
(https://i.imgur.com/eowM183.png)
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).
(https://i.imgur.com/iE5zzsP.png)
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).
(https://i.imgur.com/jXmi537.png)