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

XMC™ Forum Discussions

senx0011
Level 1
Level 1
5 sign-ins First reply posted First question asked

Hello,

 

At run time, I want to deinit I2C which was initialized as Master and reinitialize as I2C Slave. I was hoping this could be achieved by resetting the peripheral clock for the I2C. I have not run into any peripheral-clock-reset routine in the clock driver generated by Dave.

I did not run into any deinit routine in the I2C driver generated by Dave either.

Can this be done at run time? and if so how? What driver calls would you call to achieve this?

Btw, I cannot afford resetting the XMC MCU.

thank you in adavance,

0 Likes
5 Replies
LinglingG_46
Moderator
Moderator
Moderator
10 questions asked 5 questions asked 250 sign-ins

1: Could you tell us why you have this requirement?

2: What is the product you make?

 

 

 

0 Likes
senx0011
Level 1
Level 1
5 sign-ins First reply posted First question asked

Hi,

1: Could you tell us why you have this requirement?

Long story to explain, but basically I need to switch to I2C-Slave mode after I2C-Master mode.

2: What is the product you make?

It is an EtherCat slave device.

below is my attempt of "deinit" based on the the init, init is pasted below as well.

I have not tested yet.

Any feedback or help would be great. Have you guys run such scneario before?

thank you

=======

void I2C_MASTER_0_DeInit(void)
{
const uint32_t tx_fifo_events = (uint32_t)(0);
const uint32_t rx_fifo_events = (uint32_t)(XMC_USIC_CH_RXFIFO_EVENT_CONF_ALTERNATE | XMC_USIC_CH_RXFIFO_EVENT_CONF_STANDARD);

NVIC_DisableIRQ((IRQn_Type)87);/* Rx interrupt priority settings */
NVIC_DisableIRQ((IRQn_Type)89);
XMC_I2C_CH_Stop(XMC_I2C0_CH1);
XMC_USIC_CH_RXFIFO_DisableEvent(XMC_I2C0_CH1, rx_fifo_events);
XMC_USIC_CH_TXFIFO_DisableEvent(XMC_I2C0_CH1, tx_fifo_events);
XMC_USIC_CH_Disable(XMC_I2C0_CH1);
}

======

void I2C_MASTER_0_init(void)
{

const uint32_t tx_fifo_events = (uint32_t)(0);
const uint32_t rx_fifo_events = (uint32_t)(XMC_USIC_CH_RXFIFO_EVENT_CONF_ALTERNATE | XMC_USIC_CH_RXFIFO_EVENT_CONF_STANDARD);
XMC_I2C_CH_Init(XMC_I2C0_CH1, &I2C_MASTER_0_channel_config);

XMC_USIC_CH_SetInputSource(XMC_I2C0_CH1, XMC_USIC_CH_INPUT_DX0, 1);
XMC_USIC_CH_SetInputSource(XMC_I2C0_CH1, XMC_USIC_CH_INPUT_DX1, 0);

/* configure i2c tx fifo */
XMC_USIC_CH_TXFIFO_Configure(XMC_I2C0_CH1,
16,
XMC_USIC_CH_FIFO_SIZE_16WORDS,
(uint32_t)1);
XMC_USIC_CH_TXFIFO_SetInterruptNodePointer(XMC_I2C0_CH1,
XMC_USIC_CH_TXFIFO_INTERRUPT_NODE_POINTER_STANDARD,
((uint32_t)3));
XMC_USIC_CH_TXFIFO_EnableEvent(XMC_I2C0_CH1, tx_fifo_events);
/* configure i2c rx fifo */
XMC_USIC_CH_RXFIFO_Configure(XMC_I2C0_CH1,
0,
XMC_USIC_CH_FIFO_SIZE_16WORDS,
(uint32_t)(15));
XMC_USIC_CH_RXFIFO_SetInterruptNodePointer(XMC_I2C0_CH1,
XMC_USIC_CH_RXFIFO_INTERRUPT_NODE_POINTER_STANDARD,
((uint32_t)0x5));
XMC_USIC_CH_RXFIFO_SetInterruptNodePointer(XMC_I2C0_CH1,
XMC_USIC_CH_RXFIFO_INTERRUPT_NODE_POINTER_ALTERNATE,
((uint32_t)0x5));
XMC_USIC_CH_RXFIFO_EnableEvent(XMC_I2C0_CH1, rx_fifo_events);
XMC_USIC_CH_SetInterruptNodePointer(XMC_I2C0_CH1,
XMC_USIC_CH_INTERRUPT_NODE_POINTER_PROTOCOL,
((uint32_t)0));
XMC_I2C_CH_Start(XMC_I2C0_CH1);

XMC_GPIO_Init((XMC_GPIO_PORT_t *)PORT2_BASE, (uint8_t)5, &I2C_MASTER_0_sda_pin_config);
XMC_GPIO_Init((XMC_GPIO_PORT_t *)PORT2_BASE, (uint8_t)4, &I2C_MASTER_0_scl_pin_config);
/* Tx interrupt priority settings */
NVIC_SetPriority((IRQn_Type)87, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),63,0));
NVIC_EnableIRQ((IRQn_Type)87);/* Rx interrupt priority settings */
NVIC_SetPriority((IRQn_Type)89, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),63,0));
NVIC_EnableIRQ((IRQn_Type)89);}

=========

0 Likes

Now, we don't have code example which can deinit and reinit I2C at running time.

 

0 Likes
senx0011
Level 1
Level 1
5 sign-ins First reply posted First question asked

Why? does this mean that XMC4800 does not support "deinit and reinit of I2c" at run-time?

How about changing slave address at run time? how to achive this? any code snippet?

Please advise. thank you.

thank you,

0 Likes

I mean you need to config it by yourselves. After stop the I2C, then you can config it from master to salve, or slave to master.

When you call "I2C_MASTER_STATUS_t I2C_MASTER_Transmit(I2C_MASTER_t *handle, bool send_start, const uint32_t address,uint8_t *data, const uint32_t size, bool send_stop);", you can change the I2C address.

0 Likes