I2C Xmc4700 Relax Kit

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

cross mob
Not applicable
Hello everyone,

I'm trying to use the example on i2c_master.h from line 805 to 827 to use I2C bus in the Xmc4700 Relax kit, I chose pin P0.13 and P3.15 on the DAVE CE (Manual Pins Allocator) and in Advanced Settings the Transmit and Receive mode are by Interrupt.

The only thing that are changed in this code are:

I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,mem_address,1,false);

and that I put the code in a While loop:


while(1)
{
mem_address[0] = 0x00;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,mem_address,1,false);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));

I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,tx_buffer,64,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
}


I;m checking if for signal with a scope and so far there is no signal with pull up resistor or with out pull up resistors.

Thanks in advance for the help

Best regards
0 Likes
13 Replies
User13817
Level 3
Level 3
Are you using DAVE 4? I'm also having difficulty using I2C protocol on DAVE4.
I discovered that if you force an init before transmitting and receiving it "works".

Try this:

while(1)
{
mem_address[0] = 0x00;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_Init(&I2C_MASTER_EEPROM);
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,true,SLAVE_ADDRESS,mem_address,1,false);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));

I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,tx_buffer,64,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
}

Please, give me a feedback.


PS: are you trying to read or you just want to send some data to a device?
I think if the IRQ is enabled on dave app you could use the function I2C_MASTER_Transmit() instead of I2C_MASTER_TransmitIRQ(). Like this:

while(1)
{
mem_address[0] = 0x00;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_Init(&I2C_MASTER_EEPROM);
I2C_MASTER_StartTransmit(&I2C_MASTER_EEPROM,true,SLAVE_ADDRESS,mem_address,1,false);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));

I2C_MASTER_StartTransmit(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,tx_buffer,64,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
}
0 Likes
Not applicable
I tried this solution, but it always get stuck in while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));. The idea right now is just send a message but the transmit mode and receive mode handling must be an Interrupt
0 Likes
Rodrigo_RT
Level 4
Level 4
50 sign-ins 10 likes given 25 replies posted
Hello people.

I'm also having the same problem, I'm using the XMC1402 T-038, the I2C only transmits, after an I2C_MASTER_Init ().

I2C_MASTER_Init (& I2C_MASTER_0);
I2C_MASTER_Transmit (& I2C_MASTER_0,1, SLAVE_ADDRESS, 0xf, 1,0);

And there is another problem the Call Back from tx and RX is not working.
I want to use an external EEprom but this is so difficult.
0 Likes
lock attach
Attachments are accessible only for community members.
User13817
Level 3
Level 3
alanblu wrote:
I tried this solution, but it always get stuck in while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));. The idea right now is just send a message but the transmit mode and receive mode handling must be an Interrupt


Are you using DAVE4? It seems that I2C is problematic on it.
Attached you can check my code that I've been using to transmit and receive data from a slave. Its kind of "working" reggarding the bug mentioned about the I2C Init.



The interrupts are configured like that:
2837.attach
0 Likes
User13817
Level 3
Level 3
Rodrigo wrote:
Hello people.

I'm also having the same problem, I'm using the XMC1402 T-038, the I2C only transmits, after an I2C_MASTER_Init ().

I2C_MASTER_Init (& I2C_MASTER_0);
I2C_MASTER_Transmit (& I2C_MASTER_0,1, SLAVE_ADDRESS, 0xf, 1,0);

And there is another problem the Call Back from tx and RX is not working.
I want to use an external EEprom but this is so difficult.


DAVE4? I used to have this problem also. The call back wasn't working.
I deleted the project, created again and it worked. I also changed the Manual Resource Assignment to this:
2825.attach
0 Likes
Not applicable
persike wrote:
Are you using DAVE4? It seems that I2C is problematic on it.
Attached you can check my code that I've been using to transmit and receive data from a slave. Its kind of "working" reggarding the bug mentioned about the I2C Init.



The interrupts are configured like that:
2834.attach


Thank you persike,

I tried this but I'm still getting stuck in the while:

while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);

If i erase line 89 and 94 the software runs one time and them it get stuck in line 84, if I let line 89 or 94, the software get stuck in the first while that it founds.

I changed the interrupt as you show me in the pictura

Ahh and I'm using DAvE 4.3.2

Regards
0 Likes
User13817
Level 3
Level 3
alanblu wrote:
Thank you persike,

I tried this but I'm still getting stuck in the while:

while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);

If i erase line 89 and 94 the software runs one time and them it get stuck in line 84, if I let line 89 or 94, the software get stuck in the first while that it founds.

I changed the interrupt as you show me in the pictura

Ahh and I'm using DAvE 4.3.2

Regards


I forgot to mention that I'm debugging with breakpoints between them. If I just let it run it stucks on that while also.
Add some delay between the I2C_Transmit() and I2C_Receive() or use breakpoints like me (it must be a big delay).
Like this:

// Sending a data to X_LEVEL_UPPER register
i2c_data = X_LEVEL_UPPER;
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work
DELAY;
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SENSOR_WRITE_ADDRESS,&i2c_data,1,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();

i2c_data = 0x50; // any value, just to test if the I2C is working as expected
I2C_MASTER_Transmit(&I2C_MASTER_0,false,SENSOR_WRITE_ADDRESS,&i2c_data,1,true);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();

// Reading
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work
DELAY;
I2C_MASTER_Receive(&I2C_MASTER_0,true,SENSOR_READ_ADDRESS,&vector[0],6,true,true);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();

It should work.

2854.attach
0 Likes
Not applicable
I'm still getting stuck in the same place

#define DELAY (500000)


// Sending a data to X_LEVEL_UPPER register
i2c_data = X_LEVEL_UPPER;
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SENSOR_WRITE_ADDRESS,&i2c_data,1,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();

i2c_data = 0x50; // any value, just to test if the I2C is working as expected
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,false,SENSOR_WRITE_ADDRESS,&i2c_data,1,true);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();


// Reading
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work
delay(DELAY);
I2C_MASTER_Receive(&I2C_MASTER_0,true,SENSOR_READ_ADDRESS,&vector[0],6,true,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
0 Likes
User13817
Level 3
Level 3
alanblu wrote:
I'm still getting stuck in the same place

#define DELAY (500000)


// Sending a data to X_LEVEL_UPPER register
i2c_data = X_LEVEL_UPPER;
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SENSOR_WRITE_ADDRESS,&i2c_data,1,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();

i2c_data = 0x50; // any value, just to test if the I2C is working as expected
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time <- this one doesn't need because it's not a new transmission.
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,false,SENSOR_WRITE_ADDRESS,&i2c_data,1,true);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();


// Reading
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work
delay(DELAY);
I2C_MASTER_Receive(&I2C_MASTER_0,true,SENSOR_READ_ADDRESS,&vector[0],6,true,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();


That code send 0x50 to the register X_LEVEL_UPPER of slave address SENSOR_WRITE_ADDRESS. So it's not necessary to add the second I2C_MASTER_INIT() because it is the same transmission. That's why the stop bit parameter is false in the same Transmission and True at the second one.
If you just wanna to transmit one byte you can try this:

i2c_data = X_LEVEL_UPPER;
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SENSOR_WRITE_ADDRESS,&i2c_data,1,true);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();

// Reading
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work
delay(DELAY);
I2C_MASTER_Receive(&I2C_MASTER_0,true,SENSOR_READ_ADDRESS,&vector[0],6,true,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
0 Likes
Not applicable
I went back to the following configuration:

mem_address[0] = IO_STATE;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_Init(&I2C_MASTER_0);
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SLAVE_ADDRESS,mem_address,1,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_0));

I2C_MASTER_Init(&I2C_MASTER_0);
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SLAVE_ADDRESS,tx_buffer,5,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_0));

and I tried all the possible configuration of true and false on the I2C_MASTER_Transmit function I noticed that the while get stuck when I have a true statement in the second argument of any of the call of the transmit function,but when I transmit without the true statement I only get a bit change in BOTH channels (SDA and SCL) does this mean something?
0 Likes
User13817
Level 3
Level 3
alanblu wrote:
I went back to the following configuration:

mem_address[0] = IO_STATE;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_Init(&I2C_MASTER_0);
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SLAVE_ADDRESS,mem_address,1,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_0));

I2C_MASTER_Init(&I2C_MASTER_0);
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SLAVE_ADDRESS,tx_buffer,5,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_0));

and I tried all the possible configuration of true and false on the I2C_MASTER_Transmit function I noticed that the while get stuck when I have a true statement in the second argument of any of the call of the transmit function,but when I transmit without the true statement I only get a bit change in BOTH channels (SDA and SCL) does this mean something?


Without the true the comunication shouldn't work, because the uc will not send start and stop bit conditions.
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)

Apparently you have a different problem than my one, sorry for not solving it.
Good luck! Hope someone that uses the same kit that you have been using helps you.
0 Likes
Not applicable
persike wrote:
Without the true the comunication shouldn't work, because the uc will not send start and stop bit conditions.
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)

Apparently you have a different problem than my one, sorry for not solving it.
Good luck! Hope someone that uses the same kit that you have been using helps you.


Ok, Thanks for the Help!
0 Likes
Not applicable
Hi everyone!
The problem I had was due to the wrong address. I could solve it thanks to the support team.
"Address(address) should reserve an additional bit at the LSB for read/write indication. For example, address 0x05 should be provided as 0x0a"

Best regards
Alan
0 Likes