TI中文支持网
TI专业的中文技术问题搜集分享网站

DM6467 about i2c driver

Hello specialist:

       I now have used dm6467 platform.i want to  acheve i2c as slave driver,while i know  it 's as master in the most of time for linux os. I want to use it as slave device,can be used  External devices as master. how to do it?

regards

                       Leo

 

VampireDaVinci:

1. sure , plz. check www.ti.com/…/spruer0d.pdf

leo wang:

回复 VampireDaVinci:

我中文说吧,我现在的方案中 DM6467作为从机要和外部的主机通信,通过I2C,我看了6467的I2C linux驱动似乎只支持dm6467作为主机,然后我现在绕过驱动,直接操作寄存器初始化为从机,初始化部分有什么问题麻烦看一下:

然后

void i2c_init(int speed, int slaveadd)

{

u_int32_t div, psc;

/*

step 1

ICMDR-IRS  

clear IRS=0;

*/

REG(I2C_CON) = 0;

usleep(80000);

printf("I2c—>Reset: [0x%lx] \n",REG(I2C_CON));

/*

step2

ICMDR-XA

set xa for 7bit adress

*/

REG(I2C_OA) = slaveadd;

REG(I2C_SA) =slaveadd;

printf("I2c—>Slave: [0x%lx] \n",REG(I2C_OA));

REG(I2C_CNT) =0;

/*

step3

ICIMR AAS=1 ICRRDY=1 ICXRDY=1 SCD=1

set interrupt bit

*/

/* Interrupts must be enabled or I2C module won't work */

REG(I2C_IE) = I2C_IE_SCD_IE | I2C_IE_XRDY_IE |

     I2C_IE_RRDY_IE |I2C_IE_AAS_IE ;

printf("I2c—>IE: [0x%lx] \n",REG(I2C_IE));

/*

step4

                    CONFIG_SYS_HZ_CLOCK  =990M;

                    speed=400Hz (主要是主机是模拟的)

*/

psc = 8;

div = (CONFIG_SYS_HZ_CLOCK / ((psc + 1) * speed)) – 10;

printf("div: %d \n",div);

REG(I2C_PSC) = psc;

REG(I2C_SCLL) = (div * 50) / 100;

REG(I2C_SCLH) = div – REG(I2C_SCLL);

/*

step5

ICMDR MST=0 FDF=0 BC=0 DLB=0 STB=0 RM=1 STP=0 STT=1

set mod register

*/

/* Now enable I2C controller (get it out of reset) */

REG(I2C_CON) = I2C_CON_RM | I2C_CON_STT ;

REG(I2C_CON) = I2C_CON_EN | REG(I2C_CON);

printf("I2c—>MDR: [0x%lx] \n",REG(I2C_CON));

}

leo wang:

回复 VampireDaVinci:

我中文说吧,我现在的方案中 DM6467作为从机要和外部的主机通信,通过I2C,我看了6467的I2C linux驱动似乎只支持dm6467作为主机,然后我现在绕过驱动,直接操作寄存器初始化为从机,初始化部分有什么问题麻烦看一下:

然后

void i2c_init(int speed, int slaveadd)

{

u_int32_t div, psc;

/*

step 1

ICMDR-IRS  

clear IRS=0;

*/

REG(I2C_CON) = 0;

usleep(80000);

printf("I2c—>Reset: [0x%lx] \n",REG(I2C_CON));

/*

step2

ICMDR-XA

set xa for 7bit adress

*/

REG(I2C_OA) = slaveadd;

REG(I2C_SA) =slaveadd;

printf("I2c—>Slave: [0x%lx] \n",REG(I2C_OA));

REG(I2C_CNT) =0;

/*

step3

ICIMR AAS=1 ICRRDY=1 ICXRDY=1 SCD=1

set interrupt bit

*/

/* Interrupts must be enabled or I2C module won't work */

REG(I2C_IE) = I2C_IE_SCD_IE | I2C_IE_XRDY_IE |

     I2C_IE_RRDY_IE |I2C_IE_AAS_IE ;

printf("I2c—>IE: [0x%lx] \n",REG(I2C_IE));

/*

step4

                    CONFIG_SYS_HZ_CLOCK  =990M;

                    speed=400Hz (主要是主机是模拟的)

*/

psc = 8;

div = (CONFIG_SYS_HZ_CLOCK / ((psc + 1) * speed)) – 10;

printf("div: %d \n",div);

REG(I2C_PSC) = psc;

REG(I2C_SCLL) = (div * 50) / 100;

REG(I2C_SCLH) = div – REG(I2C_SCLL);

/*

step5

ICMDR MST=0 FDF=0 BC=0 DLB=0 STB=0 RM=1 STP=0 STT=1

set mod register

*/

/* Now enable I2C controller (get it out of reset) */

REG(I2C_CON) = I2C_CON_RM | I2C_CON_STT ;

REG(I2C_CON) = I2C_CON_EN | REG(I2C_CON);

printf("I2c—>MDR: [0x%lx] \n",REG(I2C_CON));

}

赞(0)
未经允许不得转载:TI中文支持网 » DM6467 about i2c driver
分享到: 更多 (0)