PCIE I2C read write 步驟

  • 330
  • 0

由於目前轉由I2C控制EEPROM

所以開始研究I2C如何控

 

PCIE

R_SERIAL_IO_CFG_PME_CTRL_STS

0x84

 

R_SERIAL_IO_MEM_PPR_RESETS

0x204

 

R_I2C_MEM_GENERAL

0x208

 

MMIO

R_I2C_MEM_ENABLE

0x6C

 

R_I2C_MEM_ENABLE_STATUS

0x9C

 

R_I2C_MEM_TAR

0x04

 

R_I2C_MEM_CON

0x00

 

R_I2C_MEM_DATA_CMD

0x10

 

R_I2C_MEM_TXFLR

0x74

 

R_I2C_MEM_RXFLR

0x78

 

R_I2C_MEM_STATUS

0x70

 

需要參數

PciCfgBase = PCIEX_BASE + B<<20 +D<<15 + F<<12)

BaseAddres =PCIEX_BASE + PciCfgBase + 0x10

  1. //Pcie I2C Enable

Set BaseAddres+ 0x84

B_SERIAL_IO_CFG_PME_CTRL_STS_PWR_ST

 [0:1]   

Read BaseAddres + 0x84

Set BaseAddres + 0x204 

ResetI2C

[0:1] 

ResetDma

[2]

1

Read BaseAddres + 0x208

SdaRdPostDr

26

0

SclRdPostDr

24

0

  1. //I2c Initialize Write Read
    1. //I2c Disable Controller

Set BaseAddres + 0x6C

Enable

 [0] 

  1. //Wait until I2C is disabled

Read BaseAddres + 0x9C

IcEn

[0]

  1. //I2c Set Frequency
  2. //I2c Set Slave Address

Set BaseAddres + 0x04

IcTar

[0:9]

Slave Address

Ic10bMaster

[12]

1: 10bit 0:7bit

  1. //I2c Start Operation

Set BaseAddres + 0x00

MasterMode

[0]

1

Speed

[1:2}

01: standard mode (0 to 100 kbit/s)

10: fast mode (400 kbit/s)

11: high speed mode (3.4 Mbit/s)

IcRestartEn

[5]

1

IcSlaveDis

[6]

1

  1. //I2c Enable Controller

Set BaseAddres + 0x6C

Enable

 [0] 

1

  1. Write
    1. //I2c Private Write

Read BaseAddres + 0x74

TXFLR

 [0:8]   

>=63 return

Read BaseAddres + 0x10

Write BaseAddres + 0x10

Data

 [0:7]   

WriteBuffer

Cmd

[8]

0:Write

Stop

[9]

WriteLength == 1  set 1 else 0

Restart

[10]

Restart == 1  set 1 else 0

 *WriteBuffer += 1;

  *WriteLength -= 1;

  1. Read
    1. //I2c Private Read

Read BaseAddres + 0x74

RXFLR

 [0:8]   

>=63 return

Read BaseAddres + 0x70

RFF

 [4] 

1 return

TFNF

[1]

1 return

Write BaseAddres + 0x10

Data

 [0:7]   

0

Cmd

[8]

1:Read

Stop

[9]

if ReadLength == 1 set 1 else 0

Restart

[10]

Restart == 1 set 1 else 0

Examle Byte Read Write

Write 0x1D = 0x02

Write BaseAddres + 0x10 = 0x41D

Write BaseAddres + 0x10 = 0x202

Read 0x1D

Write BaseAddres + 0x10 = 0x61D

Write BaseAddres + 0x10 = 0x700

Read BaseAddres + 0x10 --> 0x02

Examle Word Read

Read 0x1D

Write BaseAddres + 0x10 = 0x615

Write BaseAddres + 0x10 = 0x500

Read BaseAddres + 0x10 --> 0x0A

Write BaseAddres + 0x10 = 0x300

Read BaseAddres + 0x10 --> 0x08