Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - tha

#3545
ARM Processors / Re: STM32F1 I2C
January 10, 2021, 10:23:44 AM
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.

#3546
ARM Processors / Re: STM32F1 I2C
January 10, 2021, 05:32:57 AM
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 ไม่ถูกจัดการ.
#3547
ARM Processors / Re: STM32F1 I2C
January 10, 2021, 04:50:09 AM
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.
#3548
ARM Processors / Re: STM32F1 I2C
January 09, 2021, 10:47:58 AM
ขั้นตอนที่อธิบายข้างบนใช้ได้สำหรับ 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 สองครั้ง



#3549
ARM Processors / Re: STM32F1 I2C
January 09, 2021, 09:46:17 AM
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. นี้ถูกแสดงข้างล่างนี้



เมื่อ 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
#3550
ARM Processors / Re: STM32F1 I2C
January 09, 2021, 07:19:14 AM
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).


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.
#3551
ARM Processors / Re: STM32F1 I2C
January 09, 2021, 06:40:21 AM
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.
#3552
ARM Processors / Re: STM32F1 I2C
January 08, 2021, 02:52:42 PM
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.



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.