Kinetis K70 as I2C-Slave

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Kinetis K70 as I2C-Slave

ソリューションへジャンプ
2,376件の閲覧回数
andy87
Contributor II

Hallo,

I have a problem to configure the Kinetis K70 as a I2C-Slave.

My Master send the Slave-address but I get always a NACK from my K70.

I have a short example to check the Slave-address.

Here my configuration:

SIM_SCGC4 |= 0x40; //Turn on clock to I2C0 module  

PORTE_PCR19 = PORT_PCR_MUX(4); // SCL

PORTE_PCR18 = PORT_PCR_MUX(4); //SDA

I2C0_A1 = 0x6;                  // Slave-address
I2C0_C1 |= I2C_C1_IICEN_MASK;   /* enable IIC */
I2C0_C1 |= I2C_C1_IICIE_MASK;   // interrupt enable

I2C0_C1 &= ~0x10;

I2C0_C1 &= ~I2C_C1_MST_MASK;

At the moment i have only an ISR, which toggels LED's  if the Slave address is correct.

void i2c0_isr (void)

{

     GPIOA_PDOR &= ~GPIO_PDOR_PDO(GPIO_PIN(11));

     GPIOA_PDOR &= ~GPIO_PDOR_PDO(GPIO_PIN(10));

     I2C0_S |= 0x2;

}

I dont know where my mistake is. Have anyone an idea??

Could it be a timing problem?

1 解決策
1,240件の閲覧回数
andy87
Contributor II

Problem is solved:).

My mistake was that I turned on all port clocks after the I2C-Init.

I make it now before the Init and the problem is away.

Best Regards,

Andy

元の投稿で解決策を見る

4 返答(返信)
1,241件の閲覧回数
andy87
Contributor II

Problem is solved:).

My mistake was that I turned on all port clocks after the I2C-Init.

I make it now before the Init and the problem is away.

Best Regards,

Andy

1,240件の閲覧回数
DavidS
NXP Employee
NXP Employee

Hi Andy,

Thanks for sharing the solution.

Congratulations!

Regards,

David

1,240件の閲覧回数
andy87
Contributor II

Hi David,

Thank u for your answer.

I enabled the interrupts as u discribed. I just set no priority, because this is my only interrupt in my testing-program right now.

But I saw that the program run into the isr_default-Interrupt if i wanna set the slave address and the Port-Control-Register to change the GPIO to SDA-functionalty.

It returns then back to the main, but I have no idea why the program jump into the ísr_default.

So I think the program set not really my SDA-Port and my Slave-Address.

Regards,

Andy

0 件の賞賛
返信
1,240件の閲覧回数
DavidS
NXP Employee
NXP Employee

Hi Andreas,

Please make sure you are enabling the interrupt at all levels:

- module (as you've done in your application)

- NVIC (ex:    enable_irq(30); don't forget to set the priority too:  set_irq_priority (int irq, int prio); )

- core (#define EnableInterrupts asm(" CPSIE i"); )

Regards,

David