Hello, I am using a MK64FN1M0VLL12 chip and I've been trying to integrate adc measurements and i2c. I've been using the dac_adc_demo as an example but I ran into some hardware initialization issues. For i2c I need to initialize the E ports:
CLOCK_SYS_EnablePortClock(PORTE_IDX);
But when I add that to the dac_adc_demo in hardware_init.c, the i2c line stops working. I know ADC0_SE17 shares a port with the i2c line but I'm not using that adc pin (I'm using channel 3). I'm confused as to what's causing issues with enabling the clock for port e.
Solved! Go to Solution.
Hello
Turns out the issue was that some of the logic in the .slaveCallback function I was using in the i2c slave config. I wasn't properly handling the i2cEvent and setting the rxBuff/txBuff. My hardware was fine and the hardware_init was correct also. It was just strange because I didn't think a logic issue on the slave could disable my bluetooth lol. Your suggestion of commenting out the dac_adc code eventually led me to discover my issue. Thanks!
Hi inderjitjutla,
You just enable the PORTE clock, you should also choose the I2C pin as the I2C function, please refer to the I2C sample code configuration:
/* Ungate the port clock */ | |
CLOCK_EnableClock(kCLOCK_PortE); | |
/* I2C0 pull up resistor setting */ | |
PORT_SetPinConfig(PORTE, 24U, &pinConfig); | |
PORT_SetPinConfig(PORTE, 25U, &pinConfig); | |
/* I2C0 PIN_MUX Configuration */ | |
PORT_SetPinMux(PORTE, 24U, kPORT_MuxAlt5); | |
PORT_SetPinMux(PORTE, 25U, kPORT_MuxAlt5); |
/* Ungate the port clock */ | |
CLOCK_EnableClock(kCLOCK_PortC); | |
/* I2C1 pull up resistor setting */ | |
PORT_SetPinConfig(PORTC, 10U, &pinConfig); | |
PORT_SetPinConfig(PORTC, 11U, &pinConfig); | |
/* I2C1 PIN_MUX Configuration */ | |
PORT_SetPinMux(PORTC, 10U, kPORT_MuxAlt2); | |
PORT_SetPinMux(PORTC, 11U, kPORT_MuxAlt2); |
Wish it helps you!
If you still have question, please let me know!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello,
Thanks for the reply! I believe I'm already doing that. This is my full hardware_init.c:
/* Enable clock for PORTs */
CLOCK_SYS_EnablePortClock(PORTA_IDX);
CLOCK_SYS_EnablePortClock(PORTB_IDX);
CLOCK_SYS_EnablePortClock(PORTE_IDX);
/* Enable I2C pins */
configure_i2c_pins(0);
/* Init board clock */
BOARD_ClockInit();
dbg_uart_init();
Where the configure_i2c_pins(0) is:
void configure_i2c_pins(uint32_t instance)
{
switch(instance) {
case I2C0_IDX: /* I2C0 */
/* Affects PORTE_PCR24 register */
PORT_HAL_SetMuxMode(PORTE,24u,kPortMuxAlt5);
PORT_HAL_SetOpenDrainCmd(PORTE,24u,true);
/* Affects PORTE_PCR25 register */
PORT_HAL_SetMuxMode(PORTE,25u,kPortMuxAlt5);
PORT_HAL_SetOpenDrainCmd(PORTE,25u,true);
break;
case I2C1_IDX: /* I2C1 */
/* Affects PORTC_PCR10 register */
PORT_HAL_SetMuxMode(PORTC,10u,kPortMuxAlt2);
PORT_HAL_SetOpenDrainCmd(PORTC,10u,true);
/* Affects PORTC_PCR11 register */
PORT_HAL_SetMuxMode(PORTC,11u,kPortMuxAlt2);
PORT_HAL_SetOpenDrainCmd(PORTC,11u,true);
break;
default:
break;
}
}
I've tested both the dac/adc operation and i2c operation separately and they seem to work. When I try to integrate both something seems to be wrong with the i2c line. The i2c line is connected to a bluetooth module and the bluetooth module stops working when I try setting up both i2c and adc at the same time. The mcu is acting a slave for i2c. Could it be something with how I initialize the i2c slave and intialize the adc hardware?
I tried calling 'I2C_DRV_SlaveInit(BOARD_I2C_INSTANCE, &userConfig, &slave);' before and after I configure the adc/dac channel
Hi inderjitjutla,
Did you use the I2C0 module? Did you add the external pullup in PTE24 and PTE25?
If you comment the dac_adc code just leave the dac_adc initialization in the main.c function, whether your I2C can work ok?
Best Regards,
Jingjing
Hello
Turns out the issue was that some of the logic in the .slaveCallback function I was using in the i2c slave config. I wasn't properly handling the i2cEvent and setting the rxBuff/txBuff. My hardware was fine and the hardware_init was correct also. It was just strange because I didn't think a logic issue on the slave could disable my bluetooth lol. Your suggestion of commenting out the dac_adc code eventually led me to discover my issue. Thanks!