Switching to I2C0 module for FRDM-KL26Z

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Switching to I2C0 module for FRDM-KL26Z

Jump to solution
1,637 Views
danyonchu
Contributor I

I am using the driver example for I2C blocking, communicating using 2 FRDM-KL26Z boards (1 master, 1 slave). Currently the examples work, but on the board I am developing, I need I2C communication to happen over PTB2 and PTB3. When the hardware is initialized in the file 'hardware_init.c', you can call the function 'configure_i2c_pins' where you select I2C0 or I2C1 module. Looking into that function, if the arguments you pass in can either be 0U or 1U, where 1U corresponds to setting Port C pin1 and Port C pin 2 as your I2C pins. Sending in 0U should then set Port B pin2 and Port B pin 3 as your I2C pins. I also enabled the port clocks using the command 'CLOCK_SYS_EnablePortClock (PORTB_IDX);' .When changing the file on both the master and slave side to configure_i2c_pins(0U), I am not getting any communication through those pins. Am I misunderstanding the code?  Or is there additional places that I have to change the code to set those pins as I2C? If anyone could provide any insight on this, it would be much appreciated.

For reference, my hardware_init.c file now looks like this:

#include "board.h"

#include "pin_mux.h"

#include "fsl_clock_manager.h"

#include "fsl_debug_console.h"

void hardware_init(void) {

/* enable clock for PORTs */

CLOCK_SYS_EnablePortClock(PORTA_IDX);

CLOCK_SYS_EnablePortClock(PORTB_IDX);

CLOCK_SYS_EnablePortClock(PORTE_IDX);

configure_i2c_pins(0U);

/* Init board clock */

BOARD_ClockInit();

dbg_uart_init();

}

Tags (1)
0 Kudos
1 Solution
1,392 Views
visakhanc
Contributor III

I guess you are using SDK v1.x. I have found the example you mentioned. Here they are using I2C1 for master and slave. To change this to I2C0, you need to modify the file: examples\frdmkl46z\board.h. Make  the following modification:

/* The i2c instance used for i2c connection by default */
#define BOARD_I2C_INSTANCE    0

This will make the driver to use I2C0 for communication. The modifications you have done already are correct. 

View solution in original post

0 Kudos
9 Replies
1,392 Views
visakhanc
Contributor III

I could not find the example in i2c/i2c_blocking. The SDK V2.2 for FRDM-KL26Z don't have that example. Which version of SDK is used?

0 Kudos
1,392 Views
danyonchu
Contributor I

The example I was referring to was the i2c blocking example (located at boards\frdmkl26z\driver_examples\i2c\i2c_blocking). 

0 Kudos
1,393 Views
visakhanc
Contributor III

I guess you are using SDK v1.x. I have found the example you mentioned. Here they are using I2C1 for master and slave. To change this to I2C0, you need to modify the file: examples\frdmkl46z\board.h. Make  the following modification:

/* The i2c instance used for i2c connection by default */
#define BOARD_I2C_INSTANCE    0

This will make the driver to use I2C0 for communication. The modifications you have done already are correct. 

0 Kudos
1,392 Views
danyonchu
Contributor I

I have found the part in the code that you have mentioned. Unfortunately I still do not have any communication between PTB2(board1)-->PTB2(board2) and PTB3(board1)-->PTB3(board2) on both boards. These are the follwoing changes I have made thus far:

 In board.h

/* The i2c instance used for i2c DAC demo */

#define BOARD_DAC_I2C_INSTANCE 1

/* The i2c instance used for i2c connection by default */

#define BOARD_I2C_INSTANCE 0 //<-- changed here

/* The spi instance used for spi example */

#define BOARD_SPI_INSTANCE 0

In hardware_init.h

/* enable clock for PORTs */

CLOCK_SYS_EnablePortClock(PORTA_IDX);

CLOCK_SYS_EnablePortClock(PORTB_IDX); //<-- added this

CLOCK_SYS_EnablePortClock(PORTC_IDX);

CLOCK_SYS_EnablePortClock(PORTD_IDX);

CLOCK_SYS_EnablePortClock(PORTE_IDX);

configure_i2c_pins(0U);//<-- changed from 1U to 0U

0 Kudos
1,392 Views
danyonchu
Contributor I

I figured out that I was overwriting my I2C pins later by accident and the suggestion you made earlier was correct. Thank you!

0 Kudos
1,392 Views
visakhanc
Contributor III

Nice to know it is working for you!

0 Kudos
1,392 Views
danyonchu
Contributor I

visakhanc‌ what file(s) are this declaration needed? I have not done this yet, but I am not sure of where this needs to go since I don't see a use of that variable in the example code. The only modifications I have made were to hardware_init.c on both the master side and the slave side.

0 Kudos
1,392 Views
visakhanc
Contributor III

I am referring to FRDM-KL26Z SDK driver example code for I2C polling transfer: i2c_polling_transfer.c (located at boards\frdmkl26z\driver_examples\i2c\polling_transfer). I thought this was the example you were referring to. But I didn't see hardware_init.c in the example. Which example are you working with?

In the example, I have mentioned above, they are using I2C1 as slave & I2C0 as master. Since you want to use I2C0 as slave & master, modifying the definition is necessary.

0 Kudos
1,392 Views
visakhanc
Contributor III

The modifications to change I2C pins to from I2C1 (PortE 0&1) to I2C0 (PortB 2&3) seems correct.

But as per your need, both master and slave should use I2C0 to communicate. So, you also need to initialize the I2C driver to use I2C0 as slave (Master already uses I2C0 in the example).

The following modification can be done:

#define EXAMPLE_I2C_SLAVE_BASEADDR    I2C0

Have you done this already?

0 Kudos