Announcements

Help us improve the Power & Sensing Selection Guide. Share feedback

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Bond_007
Level 3
Level 3
10 questions asked 25 sign-ins 10 replies posted

Hi Team, 
We are working on I2C driver to interface EEPROM (M24C04) for XMC1300 kit (XMC1302 MCU). I'm using PINs USIC0_C1_DX1_P1_4(SCL)as DX1_SCLK and USIC0_C0_DX0_P1_5 (SDA) as DX0_SDA from the USIC0 Connector of XMC1300. 

Trying to send and read data of EEPROM but SDA and SCL pins are Remains High though added Internal pull up(in Software) and External pull up is 10K.
I tried this EEPROM read and write with another MCU it is working fine. But I'm facing issue only in XMC1302

I'm suspecting on P1.4 and P1.5 pins. where they belonged to different channels(C1, C0) and I2C is Channel1. Is driver works for above pins ?
Also suspecting clock configuration. please help me soon to solve this issue.

 

void Init_I2C(void) {
/* Configure Clock */
clock_config.pclk_src=XMC_SCU_CLOCK_PCLKSRC_MCLK; /*PCLK = MCLK*/
clock_config.fdiv = 0; /**< Fractional divider */
clock_config.idiv = 1; /**MCLK = 32MHz */

XMC_SCU_CLOCK_Init(&clock_config);
XMC_I2C_CH_EnableMasterClock(i2c);

/* Configure LED1 */
led1_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
XMC_GPIO_Init(XMC_GPIO_PORT0, 4, &led1_config);

/* Configure LED1 */
WCPin_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
XMC_GPIO_Init(XMC_GPIO_PORT0, 10, &WCPin_config);

/* I2C configuration */
i2c_cfg.baudrate = 100000U;


XMC_I2C_CH_Init(i2c, &i2c_cfg);
/* I2C initialization sequence*/
XMC_I2C_CH_SetInputSource(i2c, XMC_USIC_CH_INPUT_DX0 , USIC0_C0_DX0_P1_5); //DX0 -> DOUT0 P1_5_AF_U0C0_DOUT0 XMC_I2C_CH_INPUT_SDA USIC0_C1_DX0_P0_7
XMC_I2C_CH_SetInputSource(i2c, XMC_USIC_CH_INPUT_DX1 , USIC0_C1_DX1_P1_4); //DX1 -> SCLKOUT P1_4_AF_U0C1_SCLKOUT XMC_I2C_CH_INPUT_SCL USIC0_C1_DX1_P0_8

XMC_USIC_CH_TXFIFO_Configure(XMC_UART0_CH1, 0, XMC_USIC_CH_FIFO_SIZE_8WORDS, 1); // 8 entries for TxFIFO from point 0, LIMIT=1
XMC_USIC_CH_RXFIFO_Configure(XMC_UART0_CH1, 8, XMC_USIC_CH_FIFO_SIZE_8WORDS, 7); // 8 entries for RxFIFO from point 16, LIMIT=7 (SRBI is set if all 8*data has been received)

/* I2C port pin configuration*/
sda_pin_config.mode = XMC_GPIO_MODE_INPUT_PULL_UP; //XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT2;
sda_pin_config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;

scl_pin_config.mode = XMC_GPIO_MODE_INPUT_PULL_UP; //XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT2;
scl_pin_config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;

XMC_I2C_CH_Start(i2c);

XMC_GPIO_Init(SDA_PIN, &sda_pin_config);
XMC_GPIO_Init(SCL_PIN, &scl_pin_config);

}

void EEPROM_SendByte(uint8_t MemoryAddress, uint8_t DataToSend) {

XMC_I2C_CH_SetSlaveAddress(i2c, EEPROM_I2C_ADR_W);

XMC_I2C_CH_MasterStart(i2c, EEPROM_I2C_ADR_W, XMC_I2C_CH_CMD_WRITE); // I2C send repeated start command (with slave address) to write Data to PCA9502

while ((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED)
== 0U) {
} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED); // clear ACK flag in register PSR

XMC_I2C_CH_MasterTransmit(i2c, 0x50); // I2C send
while ((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED)
== 0U) {
} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED);
#if 0
XMC_I2C_CH_MasterTransmit(i2c, DataToSend); // I2C send TxData=IO_STATE
//for (volatile uint16_t gu8Index = 0; gu8Index < 500; gu8Index++);
while ((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED)
== 0U) {
} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED);
#endif
XMC_I2C_CH_MasterStop(i2c);

}

uint8_t EEPROM_ReadByte(uint8_t MemoryAddress) {
uint8_t data = 0;

XMC_I2C_CH_SetSlaveAddress(i2c, EEPROM_I2C_ADR_R);
XMC_I2C_CH_MasterStart(i2c, EEPROM_I2C_ADR_R, XMC_I2C_CH_CMD_READ); // I2C send repeated start command (with slave address) to write Data to slave
XMC_I2C_CH_MasterReceiveAck(i2c);

while ((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 0U) {} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED); // clear ACK flag in register PSR

XMC_I2C_CH_MasterReceiveNack(i2c);
while((XMC_I2C_CH_GetStatusFlag(i2c) &
(XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION |
XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION)) == 0U){}
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION |
XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);

data = XMC_I2C_CH_GetReceivedData(i2c); // get RxData from RBUF

XMC_I2C_CH_MasterStop(i2c);

return data;
}

int main(void) {
//static uint32_t gu32RxData[256];
//static volatile uint16_t gu16AddressCnt;
SystemInit();
//SystemCoreClockSetup();
Init_I2C();

while (1U) {

#if 1
ReceivedData = 0;
EEPROM_SendByte(0x00, 0x01);
for (volatile uint16_t gu16Index = 0; gu16Index < 5500; gu16Index++);
ReceivedData = EEPROM_ReadByte(0x00);
for (volatile uint16_t gu16Index = 0; gu16Index < 5500; gu16Index++);

if (ReceivedData != 0) {
XMC_GPIO_ToggleOutput(XMC_GPIO_PORT0, 4);
}
#endif
}
}

 

Please refer the below my I2C Driver code. Any help would be very thankful.

0 Likes
2 Replies
Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

Hi @Bond_007 ,

You should the pins of the same Channel because of which you might be facing issues.

Please select both the pins from either Channel0 or Channel1.

Regards,

Alakananda
0 Likes
Bond_007
Level 3
Level 3
10 questions asked 25 sign-ins 10 replies posted

Hi @Alakananda_BG ,

Thanks for the reply,

I Tested with the above suggestion where both pins belonged to same channel but the SDA and SCL remains high at 5V level. Start condition is not generating.

Used pins are  below. what else might be the issue ? any help would be very thankful.

USIC0_C1_DX0_P0_7
 USIC0_C1_DX1_P0_8

 

0 Likes