顯示具有 SCL 標籤的文章。 顯示所有文章
顯示具有 SCL 標籤的文章。 顯示所有文章

2015年12月12日 星期六

STM32F4xx Software I2C Slave Test Code

1. 既然有使用GPIO模擬的I2C Master, 當然也會有使用GPIO模擬的I2C Slave, 本範例是使用2塊
    STM32F401 Discovery Board模擬I2C Master/Slave來互相傳收資料, 由於預設的I2C GPIO是
    PB6和PB9, 因此我們必須將2塊Discovery Board的PB6/PB9互接.




2. Master Main Flow:

  • I2C GPIO Init.
  • write one byte(0xEF) to slave.
  • write six bytes(0x12,0x34,0x56,0x78,0xAB,0xCD) to slave.
  • read one byte(0x55) from slave.
  • read six bytes(0x11,0x22,0x33,0x44,0x55,0x66) from slave.     

3. Slave Main Flow:
  • 除了設定I2C GPIO外, 還需要利用Start Condition一個特性, SDA會由High to Low, 因此我們可以在SDA GPIO設定一個Falling edge Interrupt來偵測何時發生I2C傳輸.
  • slave discovery board address = 0x72.

  • 由於我們是使用SDA(PB9)來偵測Falling edge Interrupt, 所以我們必須使用STM32的EXTI9_5_IRQn來進行傳輸.

4. Test Flow:(Logic analyzer)
  • write one byte to slave:

  • write six bytes to slave:
  • read one byte from slave:
  • read six bytes from slave:

5. Test Code Download Link:

     Master

     Slave